Hype Library 3D Orbiter
Here is an example sketch by Joshua Davis, from the hype framework that has been changed to make use of ruby syntax. The declared aim of the hype library is to provide:- A collection of classes that performs the heavy lifting so that you can create sketches with the minimum amount of code. When using the hype library to create JRubyArt sketches it is suggested that you not simply ape the hype framework examples, but tailor your sketches to take advantage of the ruby language to create even more elegant code (Code as Art), not that it is relevant here.
Unzip the library in the processing libraries folder, rename the folder hype
, rename distribution
folder to library
, rename the HYPE.jar
to hype.jar
. Check that you can see the library from the processing-3.2.1 ide. Note that we can use snake case in place of camel case, for constants use ::
and not .
to call. The important thing to learn from this sketch is how to implement the HCallback interface. This can be implemented as a closure (block), note we do not/should not try and use the vanilla processing method.
In this case we use the web_to_color_array
convenience method (available since JRubyArt-1.0.7) to convert the web string array to color int in the HColorPool
constructor.
orbiter_example.rb
# encoding: utf-8
load_library :hype
include_package 'hype'
# namespace for imported classes
module Hype
java_import 'hype.extended.behavior.HOrbiter3D'
java_import 'hype.extended.colorist.HColorPool'
end
attr_reader :colors, :pool
PALETTE = %w(#333333 #494949 #5F5F5F #707070 #7D7D7D #888888 #949494 #A2A2A2 #B1B1B1 #C3C3C3 #D6D6D6 #EBEBEB #FFFFFF).freeze
def settings
size(640, 640, P3D)
end
def setup
sketch_title('HOrbiter Example')
H.init(self)
H.background(color('#242424'))
H.use3D(true)
H.add(HSphere.new)
.size(200)
.stroke_weight(0)
.no_stroke
.fill(color('#666666'))
.anchor_at(H::CENTER)
.loc(width / 2, height / 2)
@pool = HDrawablePool.new(100)
pool.autoAddToStage
.add(HSphere.new)
.colorist(Hype::HColorPool.new(web_to_color_array(PALETTE)).fill_only)
.on_create do |obj|
ran_size = 10 + (rand(0..3) * 7)
obj.size(ran_size).stroke_weight(0).no_stroke.anchor_at(H::CENTER)
orb = Hype::HOrbiter3D.new(width / 2, height / 2, 0)
.target(obj)
.z_speed(rand(-1.5..1.5))
.y_speed(rand(-0.5..0.5))
.radius(195)
.z_angle(rand(0..360))
.y_angle(rand(0..360))
obj.extras(HBundle.new.obj('o', orb))
end
.request_all
end
def draw
point_light(100, 0, 0, width / 2, height, 200) # under red light
point_light(51, 153, 153, width / 2, -50, 150) # over teal light
# mid light gray light
point_light(204, 204, 204, width / 2, (height / 2) - 50, 500)
pool.each do |d|
obj1 = d.extras
o = obj1.obj('o')
o.radius(rand(190..220))
end
sphere_detail(20)
H.draw_stage
end