Experiments with ruby-processing (processing-2.2.1) and JRubyArt for processing-3.0

Saturday 27 April 2013

Using latest hemesh library with latest ruby-processing

Here is an example of using another java processing library with ruby-processing:-
load_library :hemesh

include_package 'wblut.math'
include_package 'wblut.processing'
include_package 'wblut.core'
include_package 'wblut.hemesh'
include_package 'wblut.geom'

 RES=20

attr_reader :mesh, :inv_mesh, :render

def setup
  size(800, 800, P3D)
  smooth(8)
  values = []
  (0 .. RES).each do |i|
    valu = []
    (0 .. RES).each do |j|
      val = []
      (0 .. RES).each do |k|
        val << 2.1*noise(0.35*i, 0.35*j, 0.35*k)
      end
      valu << val
    end
    values << valu
  end

  creator=HEC_IsoSurface.new
  creator.set_resolution(RES,RES, RES)# number of cells in x,y,z direction
  creator.set_size(400.0/RES, 400.0/RES, 400.0/RES) # cell size
  creator.set_values(values.to_java(Java::float[][]))# values corresponding to the grid points
  # values can also be double[][][]
  creator.set_isolevel(1)# isolevel to mesh
  creator.set_invert(false)# invert mesh
  creator.set_boundary(100)# value of isoFunction outside grid
  # use creator.clearBoundary to rest boundary values to "no value".
  # A boundary value of "no value" results in an open mesh

  @mesh=HE_Mesh.new(creator)
  # mesh.modify(HEM_Smooth.new.set_iterations(10).setAutoRescale(true))
  creator.set_invert(true)

  @inv_mesh=HE_Mesh.new(creator)
  inv_mesh.modify(HEM_Smooth.new.set_iterations(10).set_auto_rescale(true))
  @render=WB_Render.new(self)
end

def draw
  background(120)
  lights
  translate(400, 400, 0)
  rotate_y(mouse_x.to_f/width*TWO_PI)  # use TWO_PI until processing-2.0b9
  rotate_x(mouse_y.to_f/height*TWO_PI) # then we can use TAU
  no_stroke
  fill(255,0,0)
  render.draw_faces(inv_mesh)
  stroke(0)
  render.draw_edges(mesh)
  stroke(255,0,0,80)
  render.draw_edges(inv_mesh)
end

No comments:

Post a Comment

Followers

Blog Archive

About Me

My photo
I have developed JRubyArt and propane new versions of ruby-processing for JRuby-9.1.5.0 and processing-3.2.2