Skip to content

Instantly share code, notes, and snippets.

@hhzl
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hhzl/a0685140950332726ed3 to your computer and use it in GitHub Desktop.
Save hhzl/a0685140950332726ed3 to your computer and use it in GitHub Desktop.
| svg circle |
svg := document createElementNS: 'http://www.w3.org/2000/svg' tag: 'svg'.
svg setAttribute: 'style' value: 'border: 1px solid black'.
svg setAttribute: 'width' value: '80'.
svg setAttribute: 'height' value: '200'.
svg setAttributeNS: 'http://www.w3.org/2000/xmlns/'
arg2: 'xmlns:xlink' arg3: 'http://www.w3.org/1999/xlink'.
circle := document createElementNS: 'http://www.w3.org/2000/svg' tag: 'circle'.
circle setAttribute: 'cx' value: '40'.
circle setAttribute: 'cy' value: '40'.
circle setAttribute: 'r' value: '24'.
circle setAttribute: 'style' value: 'stroke:#006600; fill:#00cc00'.
svg appendChild: circle.
circle := document createElementNS: 'http://www.w3.org/2000/svg' tag: 'circle'.
circle setAttribute: 'cx' value: '40'.
circle setAttribute: 'cy' value: '100'.
circle setAttribute: 'r' value: '24'.
circle setAttribute: 'style' value: 'stroke:#006600; fill: yellow'.
svg appendChild: circle.
circle := document createElementNS: 'http://www.w3.org/2000/svg' tag: 'circle'.
circle setAttribute: 'cx' value: '40'.
circle setAttribute: 'cy' value: '160'.
circle setAttribute: 'r' value: '24'.
circle setAttribute: 'style' value: 'stroke:#006600; fill:#cc0000'.
svg appendChild: circle.
document body appendChild: svg.
"Translated and adapted from: http://stackoverflow.com/questions/8215021/create-svg-tag-with-javascript"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment