> But, I'm having a little trouble handling the coloring of the > drawings was painted in the picture. The basic shapes such as > circle, oval... after they are drawn down in the form of contour, but > then somebody want to fill up, how to refer to them by script? Please > give me some suggestions to solve this problem. Thanks.
To do the actual fill you'll probably want to create a clipping path. https://developer.mozilla.org/en/Canvas_tutorial/Compositing To know where to create the clipping path, I'd probably save information about each drawn circle or rectangle into an array. Then when the user clicks on the canvas with the fill tool, you can examine each object in the array to see which one the click happened within. One way to do this for rectangles is to determine if a line drawn from the point of the click to the canvas origin (0,0) would intersect one and only one of the rectangle's sides. If it intersects 0 or more than one, the point is outside of the rectangle. If it intersects one and only one, the point is inside that object. I have some code to do that if you need it. I'm sure there's another way to do that for circles; if you looked for only one intersection with the diameter of the circle you'd get a false positive on tangents, I'd think. It's been awhile since I've done any geometry :) Also, I don't know how this helps you where two or more objects are partially or wholly overlapping. Another thing I've done in my canvas game design is to copy shapes to a hidden canvas where the fill color is set so that it refers back to an object in an array (or two-dimensional array). So for item # 35, as an example, the fill color would be 'rgba(35,0,0,1)'. You can then get the image data from the hidden canvas and see what the color of the pixel is that corresponds to the one clicked on in the drawing canvas and that will tell you which object was clicked on. Maybe not so useful in your case, but maybe that will spark an idea. Also you might check out Pixastic http://www.pixastic.com/ He's done a lot of neat things with image editing through canvas. --Tom Wilson -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/[email protected]/ To search via a non-Google archive, visit here: http://www.mail-archive.com/[email protected]/ To unsubscribe from this group, send email to [email protected]
