I want to draw a grid as shown in image but I totally don't have idea that where should I begin. Should I use SVG or should I use Canvas with HTML5 and how to draw it.
Please guide on this. I want this grid to draw rectangle, circle or other diagrams on it and I will calculate area of that diagram like area of square.
相关问题
- Does using percentages instead of pixels change an
- Convert svg to geojson fails with ogr2ogr
- Method for drawing circles in a pyramid pattern
- How to get coordinates of an svg?
- Changing color of SVG which was embedded using <
相关文章
- HTML5 control
- Make marker-end same color as path?
- How to display unicode in SVG?
- Converting svg to png with inkscape command line f
- How to create an SVG Matrix without an SVG element
- rect collision detection d3js
- Drawing a filled circle in a canvas on mouseclick
- My background image get cut off at the bottom
I am posting my code using
canvas
here on SO but I am also creating a working sample on JSFiddle here.Using the
canvas
approach you can make the grid size dynamic by changing theseparation
parameter.However, if your grid size is going to be static I feel that maybe you don't need to draw the grid. Just for the sake of displaying a grid to the user you could use CSS to repeat a background image as demonstrated in the fiddle here. That will also be good on page performance.
SVG can do this nicely using patterns:
I set
width
andheight
to100%
, so you can define the actual width and height on use, either for inline SVG:or an
<img>
element:results in:
results in
Note that for this particular grid you have to use widths and heights of the form
n x 80 + 1
(withn
being any integer) if you want the grid to start and end with a thick stroke.In the interest of coverage, how about a CSS based approach?
it's very easy to do using canvas, that's what I recommend. I'm responding quickly on mobile here, but you should get the idea even if the psuedocode below isn't EXACTLY right:
you'll have a loop something like: