Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I draw a Polygon? #11

Closed
earthling4211573 opened this issue Dec 9, 2010 · 1 comment
Closed

How do I draw a Polygon? #11

earthling4211573 opened this issue Dec 9, 2010 · 1 comment

Comments

@earthling4211573
Copy link

I've been trying draw Polygons but am getting the error: "array[i] is undefined fabric.js/all.js Line 1647".

Example of tries:
canvas.add(new fabric.Polygon({
points: [obj1, obj2, obj3, obj4] //obj has .x and .y
}));

canvas.add(new fabric.Polygon({ 
    points: [[thisPathRect[0][0],thisPathRect[0][1]], [thisPathRect[1][0],thisPathRect[1][1]], [thisPathRect[2][0],thisPathRect[2][1]], [thisPathRect[3][0],thisPathRect[3][1]]]
}));

Any ideas? (There don't seam to be any example on how to create a Polygon in fabric.js, I guess my best bet apart from asking here is understanding http://kangax.github.com/fabric.js/docs/symbols/src/src_polygon.class.js.html ).

@earthling4211573
Copy link
Author

Just noticed that when initializing the points are not an "option" but come before the options: "..initialize(points, options)..", so something like this will work:

    poly = new fabric.Polygon([{ x: thisPathRect[0][0]+translate[0], y: thisPathRect[0][1]+translate[1] },
                                     { x: thisPathRect[1][0]+translate[0], y: thisPathRect[1][1]+translate[1] }, 
                                     { x: thisPathRect[2][0]+translate[0], y: thisPathRect[2][1]+translate[1] }, 
                                     { x: thisPathRect[3][0]+translate[0], y: thisPathRect[3][1]+translate[1] }], { 
        stroke: "#000000", 
        strokeWidth: 5,
        fill: tolColors[0], 
        opacity: 1.0
    });
    canvas.add(poly);

kangax pushed a commit that referenced this issue Feb 1, 2016
birdage pushed a commit to birdage/fabric.js that referenced this issue Jun 19, 2018
Added a Pan Tool (by wmaillard)
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant