See previous post for how to setup java libraries. If you are mad like me, and have updated sunflow to use the latest janino compiler you should require the commons-compiler.jar as well.
# sunflow_test.rb NB: run this script directly with jruby
require 'library/sunflow_api/library/sunflow_api.jar'
require 'library/sunflow/library/sunflow.jar'
require 'library/sunflow/library/janino.jar'
class SunflowTest
API = Java::Com::briansteen::SunflowAPIAPI
SMath = Java::Org::sunflow::math
attr_reader :sunflow
def initialize width = 500, height = 500
@sunflow = API.new
sunflow.set_width(width)
sunflow.set_height(height)
sunflow.set_camera_position(0, 2.5, -5)
sunflow.set_camera_target(0, 0, 0)
sunflow.set_thinlens_camera("thinLensCamera", 50, width/height)
end
def create_scene
sunflow.draw_plane("ground", SMath::Point3.new(0,-3.5,0), SMath::Vector3.new(0, 1, 0))
sunflow.draw_sphere_flake("mySphereFlake", 20, SMath::Vector3.new(0, 1, 0), 1)
end
def render_scene filename = nil
sunflow.setPathTracingGIEngine 6
# render
sunflow.render unless filename
if filename
begin # test for dodgy filename/path
file = File.new(filename, "w")
file.close
sunflow.render(filename) # save as png image
rescue
puts "Warning #{filename} is not writable"
end
end
end
end
test = SunflowTest.new
test.create_scene
test.render_scene
Experiments with ruby-processing (processing-2.2.1) and JRubyArt for processing-3.0
Friday, 1 October 2010
Subscribe to:
Post Comments (Atom)
Followers
About Me
- monkstone
- I have developed JRubyArt and propane new versions of ruby-processing for JRuby-9.1.5.0 and processing-3.2.2
No comments:
Post a Comment