0

i have a collection of pattern in SVG format online. grid.kevinbock.de

now i thought it´ll be cool to paint them online and at least fill the areas with some "onclick=fill" stuff with SVG...

i couldnt find a tutorial for exactly this and wondering if u could help me how to set up the code for this...

heres an example of a grid in SVG format:

<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 15.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Ebene_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="50%"
 viewBox="0 0 800 600" preserveAspectRatio="xMidYMid slice" width="100%" height="100%" enable-background="new 0 0 800 600" xml:space="preserve">

<polygon fill="none" stroke="#000000" stroke-width="0.25" stroke-miterlimit="10" points="653.458,599.182 653.458,585.273 
665.501,592.229 677.546,599.182 665.501,606.135 653.458,613.09 "/>
<polygon fill="none" stroke="#000000" stroke-width="0.25" stroke-miterlimit="10" points="653.458,571.367 653.458,557.461 
665.501,564.414 677.546,571.367 665.501,578.32 653.458,585.273 "/>
<polygon fill="none" stroke="#000000" stroke-width="0.25" stroke-miterlimit="10" points="653.458,543.553 653.458,529.646 
665.501,536.602 677.546,543.553 665.501,550.508 653.458,557.461 "/>

... and so on...
</svg>

further questions are: is there any possibility to get something like snapping when drawing lines in the grid? near the vector points? and is there a way to insert a "back/Undo"-Button and Save the file?

Solano
  • 11
  • 2
  • You should reduce the number of lines of code in your example. It's way too much without any additional meaning. – stefan May 26 '13 at 12:50

1 Answers1

1

For showing you can just use the <svg> tag in your html code. To manipulate the svg you can use javascript. You can manipulate the SVG drawing like a regular DOM document. Example:

<html>
  <script>
    function colorChange()
    {
      var el = document.getElementById("mycircle");
      el.style.fill = "blue";
    }
  </script>
  <svg>
    <circle onClick="colorChange();" id="mycircle" cx="100" cy="50" r="40" stroke="black"
  stroke-width="2" fill="red"/>
  </svg>
</html>

See this jsfiddle to see it in action.

Robe Elckers
  • 967
  • 1
  • 6
  • 19
  • thank you very much! now i understand the mechanic! is there a way to toggle the colors? and what about many little objects in a svg, do i have to call any of them what to do onclick? – Solano May 26 '13 at 20:43
  • Sorry, I don't understand what you mean. Can you provide some more details? – Robe Elckers May 27 '13 at 09:30