Sha256: 18bbb9ff393b6caf81360e91aee5a037c0d85af83f1065b9e2f4ab07de68fea3

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

require 'toxiclibs'

#######
# After Paul Bourke see http://paulbourke.net/geometry/sphericalh/
# radius =
# sin(m0*phi)**m1 + cos(m2*phi)**m3 + sin(m4*theta)**m5 + cos(m6*theta)**m7
# where phi = (0..PI) and theta = (0..TWO_PI)
# As implemented by Karsten Schmidt aka toxi/postspectacular
#######

attr_reader :gfx, :mesh, :spherical, :param

def setup
  sketch_title 'Spherical Harmonics Mesh Builder'
  ArcBall.init(self)
  @param = [8, 4, 1, 5, 1, 4, 0, 0] # default function parameters (m0..m7)
  @mesh = spherical_mesh(param)
  @gfx = Gfx::MeshToVBO.new(self) # Mesh to vertex buffer object converter
  no_stroke
  @spherical = gfx.mesh_to_shape(mesh, true) # white
end

def draw
  background(0)
  lights
  shininess(16)
  directional_light(255, 255, 255, 0, -1, 1)
  specular(255)
  shape(spherical)
end

def key_pressed
  return unless (key == 'r')
  @mesh = spherical_mesh(random_parameters)
  no_stroke
  @spherical = gfx.mesh_to_colored_shape(mesh, true) # harmonic colors
end

def random_parameters
  (0..8).map { rand(0..8) }
end

def spherical_mesh(param)
  b = SurfaceMeshBuilder.new(SphericalHarmonics.new(param.to_java(:float)))
  b.create_mesh(nil, 80, 60)
end

def settings
  size(1024, 576, P3D)
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
toxiclibs-0.5.1-java examples/spherical_harmonics_mesh.rb