Demand:
- Drawing polygons
- can fill color
- Text can be set
- Removable, can be deleted
- When the mouse is pressed, the segment should follow the current position of the mouse before lifting
- Data can be easily interacted with the background, saved to the background, or the data from the background to the foreground to display the corresponding graphics
Thinking:
- The first thought is to find ready-made change, find to find, I think Fabricjs can still, but studied, found that examples are too few, it is difficult to get started in a short time
- Think of recently have been want to study did not have time to see HTML5, just before also bought a book about the development of canvas game, want to try, did not expect to get started soon
Results: Completed in one and a half days, the results are as follows:
Attention:
- Do not use style or CSS to set the width and height of the canvas, otherwise it will cause the coordinates to be magnified.
- Use jquery to get a canvas using "$ (' #canvas '). Get (0)", otherwise the corresponding object is not taken
- The palette uses "Spectrum.js"
- The value assignment is in JSON mode, using "Jquery.json-2.4.js"
- When using JSON assignment, because I have a JS wrapper class for the graphics, and with a custom method, so when the assignment is not recognized by the custom method of the problem, because when parsing json, the object will be parsed to object instead of my definition of objects, so it is necessary to deal with the human
- All code +html A total of 600 lines, which in the past was completely unthinkable to me, HTML5 will bring us what kind of future? Worth looking forward to.
PS: Use HTML5 's canvas to make a simple graphical drawing device. Ideas to organize, browse broken thousand or comment over hundred, that is, on the source sharing.