JavaFX vs Plasma
Today I came across an article explaining how to run JavaFX on Linux. I managed to install the sdk by downloading the Mac version. Next, I started the stopwatch example:
cd /tmp
unzip javafx_sdk-1_0-pre1-macosx-universal.zip
export JAVAFX_HOME=/tmp/javafx-sdk1.0pre1
export PATH=/tmp/javafx-sdk1.0pre1/bin/:$PATH
cd /tmp/javafx-sdk1.0pre1/samples/StopWatch
unzip StopWatch.zip
cd StopWatch
ant run
This stopwatch uses 90% of my CPU when running. It is implemented using one png file for the background and six fx files. These FX files are a mix of code and graphics. Here are two excerpts that show this:
frontContent = Group {
id: "Front"
content: [
// MAIN DIAL
Group {
translateX: 40 translateY: 60
cache: true
content: [
Circle {
centerX: 140
centerY: 140
radius: 140
fill:LinearGradient { startX:0 startY:0 endX:1 endY:1
stops: [
Stop { offset:0 color: Color.web("#3c3c3c") },
Stop { offset:1 color: Color.web("#010101") }
]
}
},
// Tick Marks
for (i in [1..numOfMarks]) {
Rectangle{x: 0-2 y: 108 width: 4 height: 13
fill: Color.web("#9fff81")
rotate: (360/numOfMarks)*i
translateX: 140
translateY: 140}
},
public class StopwatchWidget extends CustomNode {
private attribute model:StopwatchModel = StopwatchModel{};
private attribute theme:Theme = LightTheme{model:model};
public function create():Node {
return Group {
content: frontContent
}
}
}
The first fragment looks like a mix of Java, JavaScript, JSON and SVG. The second one like a mix of a Java and Javascript.
To me it seems that using SVG and Javascript would be much simpler and show a cleaner separation of code and graphics. So here is my challenge to you: reimplement this stopwatch with SVG and some programming language in either a webpage or as a plasma widget. The result should not use more than 20% of my CPU with an active stopwatch.
Update: here is an example of an animated clock in pure SVG. It's not a stopwatch yet, but it is very close.