The key to combining the two is page 249 of Visualizing Data, which describes how to use Java instead of Processing's own Java like language. It was fairly trivial to convert the Java to Scala -
import processing.core._
class Test extends PApplet {
val bg = 0xFFEECC00
override def setup = {
size(400,400)
}
override def draw = {
background(bg)
line(mouseX, mouseY, width/2.0f, height/2.0f)
}
}
When you compile the code with scalac, you'll need to include Processing's core.jar on the classpath.
As you can probably tell from the processing base class, you end up with a good old fashioned Java applet. As it's been over 10 years since the last time I played with applets, it took a few minutes to get it to work. To cut a long story short, I did the following:
1) jar Test.class
2) copy core.jar from Processing into the current directory
3) copy scala-library.jar from Scala into the current directory
4) create a HTML file with the following:
<APPLET CODE=Test.class WIDTH=500 HEIGHT=500 ARCHIVE="Test.jar, core.jar, scala-library.jar">
</APPLET>
5) finally, start appletviewer:
appletviewer test.htmlI'm certain there's a better way to package it all up, but like I said, it's been years since I played with applets.
1 comments:
You might try to obfuscate your code to significantly reduce jar sized.
for example, ProGuard cleans out all unused classes and methods.
I think, there will be few classes left from scala.jar after clean-up
Post a Comment