Skip to content

Commit 875e94a

Browse files
committed
skatolo gem examples
1 parent 0a4f455 commit 875e94a

File tree

5 files changed

+341
-0
lines changed

5 files changed

+341
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env jruby
2+
require 'propane'
3+
require 'skatolo'
4+
# In this simple sketch we attach three buttons to skatolo in the regular way,
5+
# named buttons 'press_me' and 'reset' thanks to some fancy metaprogramming
6+
# we can create methods :red_color, :green_color and :blue_color for the buttons
7+
class SkatoloButtonGroup < Propane::App
8+
9+
include EventMethod
10+
attr_reader :skatolo, :back_color
11+
12+
def settings
13+
size(400, 300)
14+
end
15+
16+
def setup
17+
sketch_title 'Skatolo Button Group'
18+
create_gui
19+
skatolo.update # this step is important
20+
@back_color = color(200, 0, 200)
21+
end
22+
23+
def draw
24+
background(back_color)
25+
end
26+
27+
def red_color
28+
@back_color = color(200, 0, 0)
29+
end
30+
31+
def green_color
32+
@back_color = color(0, 200, 0)
33+
end
34+
35+
def blue_color
36+
@back_color = color(0, 0, 200)
37+
end
38+
39+
def create_gui
40+
@skatolo = Skatolo.new(self)
41+
color_group = skatolo.add_group('colors')
42+
skatolo.add_button('red_color')
43+
.set_group(color_group)
44+
.set_position(0, 10)
45+
.set_size(50, 20)
46+
.set_label('Red')
47+
skatolo.add_button('green_color')
48+
.set_group(color_group)
49+
.set_position(0, 30)
50+
.set_size(50, 20)
51+
.set_label('Green')
52+
skatolo.add_button('blue_color')
53+
.set_group(color_group)
54+
.set_position(0, 50)
55+
.set_size(50, 20)
56+
.set_label('Blue')
57+
skatolo.add_accordion('acc')
58+
.set_position(20, 10)
59+
.set_size(50, 20)
60+
.add_item(color_group)
61+
end
62+
end
63+
64+
SkatoloButtonGroup.new
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env jruby
2+
require 'propane'
3+
require 'skatolo'
4+
# In this simple sketch we attach two buttons to skatolo in the regular way,
5+
# named buttons 'press_me' and 'reset' thanks to some fancy metaprogramming
6+
# we can create methods :press_me and :reset for the buttons
7+
class SkatoloButtons < Propane::App
8+
include EventMethod
9+
attr_reader :skatolo, :back_color
10+
11+
def settings
12+
size(400, 300)
13+
end
14+
15+
def setup
16+
sketch_title 'Skatolo Buttons on Propane'
17+
@skatolo = Skatolo.new(self)
18+
skatolo.add_button('press_me')
19+
.set_position(10, 10)
20+
.set_size(50, 20)
21+
.set_label('Press Me!')
22+
skatolo.add_button('reset')
23+
.set_position(10, 40)
24+
.set_size(50, 20)
25+
.set_label('Reset!')
26+
skatolo.update # this step is important
27+
@back_color = color(200, 0, 200)
28+
end
29+
30+
def draw
31+
background(back_color)
32+
end
33+
34+
def reset
35+
@back_color = color(200, 0, 200)
36+
end
37+
38+
def press_me
39+
@back_color = color(200, 0, 0)
40+
end
41+
end
42+
43+
SkatoloButtons.new
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
#!/usr/bin/env jruby
2+
require 'propane'
3+
require 'skatolo'
4+
5+
class JWishy < Propane::App
6+
include EventMethod
7+
8+
VIEWPORT_W = 600
9+
VIEWPORT_H = 600
10+
GUI_X = 20
11+
GUI_Y = 20
12+
GUI_W = 200
13+
SHAPES = %w[oval square triangle].freeze
14+
attr_reader :skatolo, :back_color, :x_wiggle, :y_wiggle, :magnitude, :big
15+
16+
def setup
17+
sketch_title 'Wishy Worm'
18+
create_gui
19+
skatolo.update
20+
@shape = 'oval'
21+
@big = false
22+
@x_wiggle, @y_wiggle = 10.0, 0
23+
@magnitude = 8.15
24+
@back_color = [0.06, 0.03, 0.18]
25+
color_mode RGB, 1
26+
ellipse_mode CORNER
27+
end
28+
29+
def draw_background
30+
back_color[3] = alpha_value
31+
fill(*back_color.to_java(:float))
32+
rect 0, 0, width - GUI_W, height
33+
end
34+
35+
def reset!
36+
@y_wiggle = 0
37+
@shape = 'oval'
38+
end
39+
40+
def toggle_big
41+
@big = !big
42+
end
43+
44+
def random_shape
45+
srand
46+
@shape = SHAPES.sample
47+
end
48+
49+
def draw
50+
draw_background
51+
# Seed the random numbers for consistent placement from frame to frame
52+
srand(0)
53+
horiz, vert, mag = x_wiggle, y_wiggle, magnitude
54+
55+
if big
56+
mag *= 2
57+
vert /= 2
58+
end
59+
60+
blu = bluish_value
61+
x, y = (width / 2), -27
62+
c = 0.0
63+
64+
64.times do
65+
x += cos(horiz) * mag
66+
y += log10(vert) * mag + sin(vert) * 2
67+
fill(sin(y_wiggle + c), rand * 0.2, rand * blu, 0.5)
68+
s = 42 + cos(vert) * 17
69+
args = [@shape, x - s / 2, y - s / 2, s, s]
70+
draw_shape(args)
71+
vert += rand * 0.25
72+
horiz += rand * 0.25
73+
c += 0.1
74+
end
75+
76+
@x_wiggle += 0.05
77+
@y_wiggle += 0.1
78+
end
79+
80+
def draw_shape(args)
81+
case args[0]
82+
when 'triangle'
83+
draw_triangle(args)
84+
when 'square'
85+
rect(args[1], args[2], args[3], args[4])
86+
else
87+
oval(args[1], args[2], args[3], args[4]) # ellipse alias
88+
end
89+
end
90+
91+
def draw_triangle(args)
92+
x2 = args[1] + (args[3] * 0.6)
93+
y0 = args[2] + (args[4] * 0.396)
94+
y1 = args[2] - (args[4] * 0.792)
95+
y2 = args[2] + (args[4] * 0.396)
96+
triangle(args[1] - (args[3] * 0.6), y0, args[1], y1, x2, y2)
97+
end
98+
99+
def settings
100+
size VIEWPORT_W + GUI_W, VIEWPORT_H
101+
end
102+
103+
def create_gui
104+
@skatolo = Skatolo.new(self)
105+
sx = 100
106+
sy = 14
107+
oy = (sy * 1.5).to_i
108+
######################################
109+
# GUI - FLUID
110+
######################################
111+
control = skatolo.add_group('control')
112+
control.set_title('Control Panel')
113+
.set_height(20)
114+
.set_size(GUI_W, VIEWPORT_H)
115+
.set_position(VIEWPORT_W, 0)
116+
.set_background_color(color(100))
117+
.set_color_background(color(100))
118+
px = 10
119+
py = 15
120+
skatolo.add_slider('bluish')
121+
.set_size(sx, sy)
122+
.set_position(px, py += oy)
123+
.set_range(0, 1.0)
124+
.set_value(0.5)
125+
.set_group(control)
126+
skatolo.add_slider('alpha')
127+
.set_size(sx, sy)
128+
.set_position(px, py += oy)
129+
.set_range(0, 1.0)
130+
.set_value(0.5)
131+
.set_group(control)
132+
skatolo.add_button('toggle_big')
133+
.set_size(sx, 15)
134+
.set_position(px, py += oy)
135+
.set_group(control)
136+
skatolo.add_button('reset!')
137+
.set_size(sx, 15)
138+
.set_position(px, py += oy)
139+
.set_group(control)
140+
skatolo.add_button('random_shape')
141+
.set_size(sx, 15)
142+
.set_position(px, py += oy)
143+
.set_group(control)
144+
end
145+
end
146+
147+
JWishy.new
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env jruby
2+
require 'propane'
3+
require 'skatolo'
4+
# In this simple sketch we attach a slider to skatolo in the regular way, with
5+
# a named slider 'background_color' and thanks to some fancy metaprogramming
6+
# we can read the result from background_color_value
7+
class SkatoloSlider < Propane::App
8+
include EventMethod
9+
attr_reader :skatolo
10+
11+
def settings
12+
size(400, 300)
13+
end
14+
15+
def setup
16+
sketch_title 'Skatolo Slider'
17+
@skatolo = Skatolo.new(self)
18+
skatolo.add_slider('background_color')
19+
.set_position(10, 10)
20+
.set_size(150, 20)
21+
.set_range(80, 255)
22+
.set_value(180)
23+
.set_label('Background color')
24+
skatolo.update # this step is important
25+
end
26+
27+
def draw
28+
background(background_color_value)
29+
end
30+
end
31+
32+
SkatoloSlider.new
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env jruby
2+
require 'propane'
3+
require 'skatolo'
4+
# In this simple sketch we attach three buttons to skatolo in the regular way,
5+
# named buttons 'press_me' and 'reset' thanks to some fancy metaprogramming
6+
# we can create methods :red_color, :green_color and :blue_color for the buttons
7+
class SkatoloSliderGroup < Propane::App
8+
9+
include EventMethod
10+
attr_reader :skatolo, :back_color
11+
12+
def settings
13+
size(400, 300)
14+
end
15+
16+
def setup
17+
sketch_title 'Skatolo Slider Group'
18+
create_gui
19+
skatolo.update # this step is important
20+
@back_color = color(200, 0, 200)
21+
end
22+
23+
def draw
24+
background(red_value, green_value, blue_value)
25+
end
26+
27+
def create_gui
28+
@skatolo = Skatolo.new(self)
29+
color_group = skatolo.add_group('colors')
30+
skatolo.add_slider('red')
31+
.set_group(color_group)
32+
.set_size(100, 15)
33+
.set_position(0, 10)
34+
.set_range(0, 255)
35+
.set_value(50)
36+
skatolo.add_slider('green')
37+
.set_group(color_group)
38+
.set_size(100, 15)
39+
.set_position(0, 30)
40+
.set_range(0, 255)
41+
.set_value(50)
42+
skatolo.add_slider('blue')
43+
.set_group(color_group)
44+
.set_size(100, 15)
45+
.set_position(0, 50)
46+
.set_range(0, 255)
47+
.set_value(50)
48+
skatolo.add_accordion('acc')
49+
.set_position(10, 10)
50+
.set_size(120, 20)
51+
.add_item(color_group)
52+
end
53+
end
54+
55+
SkatoloSliderGroup.new

0 commit comments

Comments
 (0)