Skip to content

Commit 3617070

Browse files
committed
simplify sketches
1 parent 90f5c26 commit 3617070

File tree

4 files changed

+11
-27
lines changed

4 files changed

+11
-27
lines changed

demo/elegant_ball.rb

+1-8
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ def draw
2121
background(0)
2222
# Move the origin so that the scene is centered on the screen.
2323
translate(width / 2, height / 2, 0.0)
24-
# Set up the lighting.
25-
setup_lights
24+
lights # Simple lighting for PiCrate.
2625
# Rotate the local coordinate system.
2726
smooth_rotation(5.0, 6.7, 7.3)
2827
# Draw the inner object.
@@ -41,12 +40,6 @@ def renderer
4140
@renderer ||= AppRender.new(self)
4241
end
4342

44-
def setup_lights
45-
ambient_light(0.025, 0.025, 0.025)
46-
directional_light(0.2, 0.2, 0.2, -1, -1, -1)
47-
spot_light(1.0, 1.0, 1.0, -200, 0, 300, 1, 0, -1, Math::PI / 4, 20)
48-
end
49-
5043
# Generate a vector whose components change smoothly over time in the range
5144
# (0..1). Each component uses a Math.sin function to map the current time in
5245
# milliseconds in the range (0..1).A 'speed' factor is specified for each

demo/flight_patterns.rb

+5-13
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,14 @@ class FlightPatterns < Processing::App
1313
attr_reader :flee, :radius
1414

1515
def settings
16-
size 1024, 750, P3D
16+
size 1024, 750, P2D
1717
end
1818

1919
def setup
20-
sketch_title 'Flight Patterns'
20+
sketch_title 'Flight Patterns'
2121
sphere_detail 8
2222
color_mode RGB, 1.0
2323
no_stroke
24-
shininess 1.0
25-
specular 0.3, 0.1, 0.1
26-
emissive 0.03, 0.03, 0.1
2724
@radius = 0.02 * height
2825
@click = false
2926
@flee = false
@@ -41,24 +38,19 @@ def key_pressed
4138

4239
def draw
4340
background 0.05
44-
ambient_light 0.01, 0.01, 0.01
45-
light_specular 0.4, 0.2, 0.2
46-
point_light 1.0, 1.0, 1.0, mouse_x, mouse_y, 190
4741
@flocks.each_with_index do |flock, i|
48-
flock.goal(target: Vec3D.new(mouse_x, mouse_y, 0), flee: @flee)
42+
flock.goal(target: Vec2D.new(mouse_x, mouse_y), flee: @flee)
4943
flock.update(goal: 185, limit: 13.5)
5044
flock.each do |boid|
51-
r = (0.15 * boid.pos.z) + radius
5245
case i
5346
when 0 then fill 0.85, 0.65, 0.65
5447
when 1 then fill 0.65, 0.85, 0.65
5548
when 2 then fill 0.65, 0.65, 0.85
5649
end
5750
push_matrix
58-
point_array = (boid.pos.to_a).map { |p| p - (r / 2.0) }
51+
point_array = (boid.pos.to_a).map { |p| p - (radius / 2.0) }
5952
translate(*point_array)
60-
@click ? sphere(r / 2) : ellipse(0, 0, r, r)
61-
@click ? hint(ENABLE_DEPTH_TEST) : hint(DISABLE_DEPTH_TEST)
53+
ellipse(0, 0, radius, radius)
6254
pop_matrix
6355
end
6456
end

external_library/java/hype/h_orbiter.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def settings
2121

2222
def setup
2323
sketch_title('HOrbiter Example')
24-
group = ColorGroup.from_web_array(PALETTE.to_java(:string)
24+
group = ColorGroup.from_web_array(PALETTE.to_java(:string))
2525
H.init(self)
2626
H.background(color('#242424'))
2727
H.use3D(true)

external_library/java/hype/hype_swarm.rb

+4-5
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ def setup
4141
.add(HRect.new(10).rounding(5))
4242
.on_create do |obj|
4343
obj.stroke_weight(2)
44-
.stroke(colors2[1])
45-
.fill(colors2[2])
44+
.stroke(colors2[2])
45+
.fill(colors2[1])
4646
.loc(rand(100..540), rand(100..540))
4747
.anchor_at(H::CENTER)
4848
.rotation(45)
@@ -79,11 +79,10 @@ def draw
7979
end
8080
H.draw_stage
8181
it = swarm.goals.iterator
82-
while it.has_next
82+
while it.has_next?
8383
it.remove
84-
it.next
84+
# it.next
8585
end
86-
8786
pool.each do |d|
8887
swarm.add_goal(d.x, d.y)
8988
end

0 commit comments

Comments
 (0)