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

SunflowAPIAPI test example using jruby

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

0 comments:

Post a Comment

Followers

Blog Archive

About Me

My Photo
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.