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.
animated
clock in svg
Comments
90% of your CPU to run a clock?
All I can say is that it obviously doesn't work if running two clocks will totally kill a modern 21st century CPU. You didn't mention mention memory usage, but I assume that is similarly very high.
Running the analog clock applet in Plasma, updating every second, takes less that 1% of my CPU, and the same clock running in Ruby takes about 1% (according to top). I'm sure we could update the SVG theme to look like a stopwatch the same as the JavaFX one, and they wouldn't run any slower. All Plasma applets run in the same process and so there will only be one Ruby interpreter running for two or more clocks. I wonder if each JavaFX clock runs in its own JVM, or do they use the same JVM?
By Richard Dale at Thu, 08/21/2008 - 09:48