Skip to content

Commit 4056dcb

Browse files
author
monkstone
committed
revert Sketch title
1 parent 5c130e8 commit 4056dcb

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

samples/contributed/jwishy.rb

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# from a Python example for Nodebox, and then, now
44
# to Ruby-Processing.
55

6-
# For fun, try running it via jirb, and
6+
# For fun, try running it using live mode, and
77
# playing with the attr_accessors, as
88
# well as the background.
99

@@ -18,13 +18,15 @@
1818

1919
def setup
2020
size 600, 600
21+
frame.set_title 'Wishy Worm'
2122
control_panel do |c|
23+
c.title = 'Control Panel'
2224
c.look_feel 'Nimbus'
2325
c.slider :bluish, 0.0..1.0, 0.5
2426
c.slider :alpha, 0.0..1.0, 0.5
2527
c.checkbox :go_big
2628
c.button :reset
27-
c.menu :shape, %w(oval square)
29+
c.menu :shape, %w(oval square triangle)
2830
@panel = c
2931
end
3032
@hide = false
@@ -61,7 +63,7 @@ def draw
6163
horiz, vert, mag = x_wiggle, y_wiggle, magnitude
6264

6365
if @go_big
64-
mag *= 2
66+
mag *= 2
6567
vert /= 2
6668
end
6769

@@ -74,8 +76,8 @@ def draw
7476
y += log10(vert) * mag + sin(vert) * 2
7577
fill(sin(y_wiggle + c), rand * 0.2, rand * blu, 0.5)
7678
s = 42 + cos(vert) * 17
77-
args = [x - s / 2, y - s / 2, s, s]
78-
@shape == 'oval' ? oval(*args) : rect(*args)
79+
args = [@shape, x - s / 2, y - s / 2, s, s]
80+
draw_shape(args)
7981
vert += rand * 0.25
8082
horiz += rand * 0.25
8183
c += 0.1
@@ -88,3 +90,20 @@ def draw
8890
def mouse_pressed
8991
@hide = false if hide
9092
end
93+
94+
def draw_shape(args)
95+
case args[0]
96+
when 'triangle'
97+
x0 = args[1] - (args[3] * 0.6)
98+
x1 = args[1]
99+
x2 = args[1] + (args[3] * 0.6)
100+
y0 = args[2] + (args[4] * 0.396)
101+
y1 = args[2] - (args[4] * 0.792)
102+
y2 = args[2] + (args[4] * 0.396)
103+
triangle(x0, y0, x1, y1, x2, y2)
104+
when 'oval'
105+
oval(args[1], args[2], args[3], args[4])
106+
when 'square'
107+
rect(args[1], args[2], args[3], args[4])
108+
end
109+
end

0 commit comments

Comments
 (0)