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
Here is my blog in which I will describe my experiments with ruby-processing, find out more about ruby-processing at:- http://wiki.github.com/jashkenas/ruby-processing and http://github.com/jashkenas/context_free for the cfdg DSL (context-free-art)
Friday, 1 October 2010
Subscribe to:
Post Comments (Atom)
Blog Archive
-
▼
2010
(73)
-
►
September
(15)
- Basic Hair Example SunflowAPIAPI just using jruby
- Basic Hair Example SunflowAPIAPI in ruby processin...
- SunflowAPIAPI in ruby processing
- A Staffordshire Knot Using Ruby Processing and A C...
- An Infinity Loop? With My 3D Context Free Library
- Revised 3D Context Free DSL Sketch, with Mouse Whe...
- A Mouse Wheel Listener in Ruby Processing
- 3D Context Free DSL Screen Saver?
- Translating the default.es to ruby processing DSL
- Testing the cube primitive in my context free DSL
- Experimental 3D Context Free DSL in ruby-processin...
- Using the control panel and Toxi Processing Libra...
- Tone map example of Gray-Scott diffusion using tox...
- Another Example of Using Toxi Processing Libraries...
- Using the Toxi Processing Libraries in ruby proces...
-
►
June
(6)
- Cesàro fractal using ruby processing context free ...
- Exploring Dynamic Randomness in ruby-processing co...
- Towards an Escher Bird Tiling (Ruby processing con...
- Weird Flower Ruby Processing Context Free DSL
- Alhambra Tiling Ruby Processing Context Free DSL
- Red Dwarf (Ruby Processing Context Free DSL)
-
►
September
(15)
About Me
- monkstone
- Consolidating my online identity as monkstone. I am a 64 bit linux user and advocate of open source software, you can sometimes find me on the processing forum.
0 comments:
Post a Comment