Virtual Mechanics: Community Forums and FAQs
Virtual Mechanics: Community Forums and FAQs
Animation / Mobile
SVG newbie Question: Variables?|
Go
![]() |
New
![]() |
Find
![]() |
Notify
![]() |
Tools
![]() |
Reply
![]() |
|
|
Junior Mechanic |
I'm new to SVG and XML.
Having read several tutorials, I started coding some SVGs. Now here is what I wanna do in some pseudo-code: (doesn't work like this, of course ... var x=5; var y=2.5; <rect x="{$x}" y="{$x*2}" width="{$y}" height="68" /> <circle cx="{$x+5}" cy="0" r="10" /> ... Hope this is understandable. I found out that something like this can be done with java-script. But: Is there any chance of using variables without java-script? Thx. |
||
|
Guru 'Power' Mechanic![]() |
I'm not an SVG user, so you'd have to be guided by what your SVG tutorials say. You know much more than me
If you can do something similar to what you want in SiteSpinner or Web Engine, you may find it useful to look at the SVG code they generate. |
|||
|
|
Junior Mechanic |
Well, the problem ist:
When you create SVGs with WYSIWYG programs like SiteSpinner, the size of an object is always seen as a constant number, so the code looks like this: ... <rect x="5" y="10" width="2.5" height="68" /> <circle cx="10" cy="0" r="10" /> ... After modification of the rectangle and the circle, the constants would be changed: ... <rect x="7" y="14" width="4" height="68" /> <circle cx="12" cy="0" r="10" /> ... This is rather inconvenient because I want to make an SVG where the positions and sizes of about 20 objects can be easily changed in order to create several versions of the same drawing. At the moment, the only technique seems to be: * re-calculate the values manually, then * modify every single object I thought there might be a way of using variables in XML like in my above post? (Actually, it has nothing to do with SVG in particular.) |
|||
|
Guru 'Power' Mechanic![]() |
The general procedure would be to put your drawing code (circle and rectangles) into javascript functions. Then in javascript you would say something like:
<script> DrawRectangle(5,10,2.5,68) //passing the variables to function DrawRectangle() DrawRectangle(7,14,4,68) . .etc for as many rectangles as you want . </script> The tricky bit for me would be the function DrawRectangle(), because that would have to be coded to use SVG (XML?). Sorry my knowledge in this area is nil |
|||
|
| Powered by Eve Community |
| Please Wait. Your request is being processed... |
|
Virtual Mechanics: Community Forums and FAQs
Virtual Mechanics: Community Forums and FAQs
Animation / Mobile
SVG newbie Question: Variables?
