Skip to content

Instantly share code, notes, and snippets.

@ksky
Created June 15, 2012 09:48
Show Gist options
  • Save ksky/2935665 to your computer and use it in GitHub Desktop.
Save ksky/2935665 to your computer and use it in GitHub Desktop.
SVG Animation Sample playing with GroovyFX
@Grab('org.codehaus.groovyfx:groovyfx:0.2')
import static groovyx.javafx.GroovyFX.start
svg = '''<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="400px" height="250px" viewBox="0 0 400 250" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1">
<rect id="rect" x="50" y="50" width="100" height="75" fill="red" opacity="0.0">
<animate attributeName="opacity" begin="0s" dur="0.5s" from="0.0" to="1.0" fill="freeze" repeatCount="1"/>
<animate attributeName="x" begin="1s" dur="5s" fill="freeze" calcMode="linear" repeatCount="1" keyTimes="0;0.2;0.4;0.6;0.8;1" values="50;250;50;250;50;250"/>
<animate attributeName="fill" begin="1.5s" dur="2.4s" fill="freeze" calcMode="linear" repeatCount="1" keyTimes="0;0.25;0.5;0.75;1" values="red;green;red;green;red"/>
</rect>
<circle id="circle" cx="150" cy="150" r="50" fill="cyan" opacity="0.0">
<animate attributeName="opacity" begin="2s" dur="0.5s" from="0.0" to="1.0" fill="freeze" repeatCount="1"/>
<animate attributeName="opacity" begin="5s" dur="0.5s" from="1.0" to="0.0" fill="freeze" repeatCount="1"/>
<animateTransform attributeName="transform" type="scale" additive="sum" begin="2.5s" dur="2s" fill="freeze" keyTimes="0;0.5;1" values="1,1;2.0,0.75;1,1" repeatCount="1"/>
</circle>
</svg>
'''
start {
stage = stage {
scene {
view = webView()
view.engine.loadContent(svg)
}
}
stage.show()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment