See previous post for how to setup java libraries.
# basic_hair.rb run with 'rp5 run script.rb'
class BasicHair < Processing::App
load_libraries :sunflow_api, :sunflow
include_package 'com.briansteen'
include_package 'org.sunflow.math'
include_package 'java.awt'
API = Java::Com::briansteen::SunflowAPIAPI
SMath = Java::Org::sunflow::math
JColor = java.awt.Color
WIDTH = 640
HEIGHT = 480
P_AMOUNT = 20
def setup
# create a new API instance
@sunflow = API.new
# set width and height
@sunflow.set_width(WIDTH)
@sunflow.set_height(HEIGHT)
# set background color
@sunflow.set_background(1, 1, 1)
# set camera
@sunflow.set_camera_position(0, 7, 5)
@sunflow.set_camera_target(2, 0.5, 0)
@sunflow.set_thinlens_camera("thinLensCamera", 50, WIDTH/HEIGHT)
# set basic light
@sunflow.set_point_light("myPointLight", SMath::Point3.new(0, 5, 5),
JColor.new(255, 255, 255))
@sunflow.set_directional_light("myDirectionalLight", SMath::Point3.new(-2, 3, 0),
SMath::Vector3.new(0, 0, 0), 3, JColor.new(1, 1, 1))
# @sunflow.setSphereLight("mySphereLight", SMath::Point3.new(0, 30, -5),
# JColor.new(0, 0, 255), 32, 10)
# draw a ground plane
@sunflow.draw_plane("ground", SMath::Point3.new(0, 0, 0), SMath::Vector3.new(0, 1, 0))
# coordinates array
hair_widths = [0.025]
@sunflow.draw_box("boxname", 0, 0, 0, 1)
# create particle coordinates
350.times do |j|
# particle start position
particle_x = Math.cos(j*0.5)*j*0.0015
particle_y = 0
particle_z = Math.sin(j*0.5)*j*0.0015
hair_coordinates = Array.new(P_AMOUNT*3)
array_index = -1
P_AMOUNT.times do |i|
particle_x += 0.1 + Math.cos(i * 0.15 + j*0.05) * 0.13
particle_y -= Math.sin(particle_z*0.01 + j*0.05)*0.125 +
Math.cos(i*0.5 + particle_y)*0.125
particle_z += Math.sin(i)*0.25 + particle_y*0.01
hair_coordinates[array_index += 1] = particle_x
hair_coordinates[array_index += 1] = particle_y
hair_coordinates[array_index += 1] = particle_z
end
# set ambient occlusion shader
@sunflow.setAmbientOcclusionShader("myAmbientOcclusionShader#{j}", JColor.new(55,55,55),
JColor.new(0,0,0), 16, 1)
# set glass shader
# @sunflow.setGlassShader("myGlassShader", JColor.new(1,1,1), 2.5, 3, JColor.new(1,1,1))
# set shiny-diffuse shader
# @sunflow.setShinyDiffuseShader("myShinyShader", JColor.new(55,55,55), 0.8)
# draw object
@sunflow.drawHair("hair#{j}", P_AMOUNT - 2, hair_coordinates.to_java(:float),
hair_widths.to_java(:float))
end
@sunflow.setIrradianceCacheGIEngine(32, 0.4, 1, 15, nil)
# render
@sunflow.render() # display in sunflow window
# @sunflow.render("BasicHair.png") # save as png image
end
def draw
exit
end
end
Experiments with ruby-processing (processing-2.2.1) and JRubyArt for processing-3.0
Thursday, 30 September 2010
Subscribe to:
Post Comments (Atom)
Followers
Blog Archive
-
▼
2010
(73)
-
▼
September
(15)
- Basic Hair Example SunflowAPIAPI just using jruby
- Basic Hair Example SunflowAPIAPI in ruby processing
- 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...
-
▼
September
(15)
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