propane 0.5.0-java → 0.6.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +3 -1
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/examples/complete/bw_shader.rb +46 -0
- data/examples/complete/data/bwfrag.glsl +23 -0
- data/examples/complete/data/lachoy.jpg +0 -0
- data/examples/complete/data/landscape.glsl +352 -0
- data/examples/complete/data/monjori.glsl +30 -0
- data/examples/complete/data/moon.jpg +0 -0
- data/examples/complete/data/sea.jpg +0 -0
- data/examples/complete/edge_detection.rb +49 -0
- data/examples/complete/landscape.rb +32 -0
- data/examples/complete/linear_image.rb +51 -0
- data/examples/complete/monjori.rb +33 -0
- data/examples/regular/arcball_box.rb +3 -1
- data/examples/regular/arcball_constrain.rb +38 -0
- data/examples/regular/bezier_playground.rb +205 -0
- data/examples/regular/colors_two.rb +61 -0
- data/examples/regular/creating_colors.rb +10 -3
- data/examples/regular/elegant_ball.rb +1 -1
- data/examples/regular/fibonacci_sphere.rb +90 -0
- data/examples/regular/grapher.rb +39 -0
- data/examples/regular/gravity.rb +120 -0
- data/examples/regular/slider_demo.rb +60 -0
- data/examples/regular/slider_example.rb +53 -0
- data/examples/regular/slider_simple.rb +47 -0
- data/examples/regular/tree.rb +76 -0
- data/lib/propane/app.rb +1 -6
- data/lib/propane/helper_methods.rb +39 -10
- data/lib/propane/version.rb +1 -1
- data/library/slider/slider.rb +43 -0
- data/pom.rb +4 -4
- data/pom.xml +4 -4
- data/propane.gemspec +1 -1
- data/src/monkstone/ColorUtil.java +42 -9
- data/src/monkstone/slider/CustomHorizontalSlider.java +164 -0
- data/src/monkstone/slider/CustomVerticalSlider.java +178 -0
- data/src/monkstone/slider/SimpleHorizontalSlider.java +145 -0
- data/src/monkstone/slider/SimpleSlider.java +175 -0
- data/src/monkstone/slider/SimpleVerticalSlider.java +159 -0
- data/src/monkstone/slider/Slider.java +61 -0
- data/src/monkstone/slider/SliderBar.java +245 -0
- data/src/monkstone/slider/SliderGroup.java +56 -0
- data/src/monkstone/slider/WheelHandler.java +35 -0
- data/src/monkstone/vecmath/vec2/Vec2.java +3 -8
- data/src/monkstone/vecmath/vec3/Vec3.java +8 -13
- data/vendors/Rakefile +2 -2
- metadata +36 -6
- data/VERSION.txt +0 -4
@@ -0,0 +1,61 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
# Creating Colors (Homage to Albers).
|
4
|
+
#
|
5
|
+
require 'propane'
|
6
|
+
|
7
|
+
# Creating variables for colors that may be referred to
|
8
|
+
# in the program by their name, rather than a number.
|
9
|
+
class CreatingColors < Propane::App
|
10
|
+
attr_reader :redder, :yellower, :orangish
|
11
|
+
def setup
|
12
|
+
size 640, 360
|
13
|
+
# palette = web_to_color_array(['#CC6600', '#CC9900', '#993300'].to_java(:string))
|
14
|
+
palette = web_to_color_array(['#CC6600', '#CC9900', '#993300'])
|
15
|
+
# @redder = color 204, 102, 0
|
16
|
+
# @yellower = color 204, 153, 0
|
17
|
+
# @orangish = color 153, 51, 0
|
18
|
+
# These statements are equivalent to the statements above.
|
19
|
+
# Programmers may use the format they prefer.
|
20
|
+
|
21
|
+
# hex color as a String (NB quotes are required)
|
22
|
+
@redder = palette[0]
|
23
|
+
@yellower = palette[1]
|
24
|
+
@orangish = palette[2]
|
25
|
+
|
26
|
+
# @redder = color '#CC6600'
|
27
|
+
# @yellower = color '#CC9900'
|
28
|
+
# @orangish = color '#993300'
|
29
|
+
|
30
|
+
# or alternatively as a hexadecimal
|
31
|
+
|
32
|
+
# @redder = color 0xFFCC6600
|
33
|
+
# @yellower = color 0xFFCC9900
|
34
|
+
# @orangish = color 0xFF993300
|
35
|
+
end
|
36
|
+
|
37
|
+
def draw
|
38
|
+
no_stroke
|
39
|
+
background 51, 0, 0
|
40
|
+
push_matrix
|
41
|
+
translate 80, 80
|
42
|
+
fill orangish
|
43
|
+
rect 0, 0, 200, 200
|
44
|
+
fill yellower
|
45
|
+
rect 40, 60, 120, 120
|
46
|
+
fill redder
|
47
|
+
rect 60, 90, 80, 80
|
48
|
+
pop_matrix
|
49
|
+
push_matrix
|
50
|
+
translate 360, 80
|
51
|
+
fill redder
|
52
|
+
rect 0, 0, 200, 200
|
53
|
+
fill orangish
|
54
|
+
rect 40, 60, 120, 120
|
55
|
+
fill yellower
|
56
|
+
rect 60, 90, 80, 80
|
57
|
+
pop_matrix
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
CreatingColors.new title: 'Homage to Albers'
|
@@ -8,16 +8,22 @@ require 'propane'
|
|
8
8
|
# in the program by their name, rather than a number.
|
9
9
|
class CreatingColors < Propane::App
|
10
10
|
attr_reader :redder, :yellower, :orangish
|
11
|
+
|
12
|
+
WEB = %w(#CC6600 #CC9900 #993300)
|
11
13
|
|
12
14
|
def setup
|
13
15
|
size 640, 360
|
14
|
-
|
15
|
-
@
|
16
|
-
@
|
16
|
+
palette = web_to_color_array(WEB)
|
17
|
+
@redder = palette[0]
|
18
|
+
@yellower = palette[1]
|
19
|
+
@orangish = palette[2]
|
17
20
|
# These statements are equivalent to the statements above.
|
18
21
|
# Programmers may use the format they prefer.
|
19
22
|
|
20
23
|
# hex color as a String (NB quotes are required)
|
24
|
+
@redder = palette[0]
|
25
|
+
@yellower = palette[1]
|
26
|
+
@orangish = palette[2]
|
21
27
|
|
22
28
|
# @redder = color '#CC6600'
|
23
29
|
# @yellower = color '#CC9900'
|
@@ -28,6 +34,7 @@ class CreatingColors < Propane::App
|
|
28
34
|
# @redder = color 0xFFCC6600
|
29
35
|
# @yellower = color 0xFFCC9900
|
30
36
|
# @orangish = color 0xFF993300
|
37
|
+
puts int_to_ruby_colors(palette)
|
31
38
|
end
|
32
39
|
|
33
40
|
def draw
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'propane'
|
2
|
+
require 'arcball'
|
3
|
+
|
4
|
+
class FibonacciSphere < Propane::App
|
5
|
+
# fibonacci_sphere.rb
|
6
|
+
# After a vanilla processing sketch by Jim Bumgardner
|
7
|
+
# http://www.openprocessing.org/sketch/41142
|
8
|
+
#
|
9
|
+
# Controls:
|
10
|
+
# 1. drag mouse to rotate sphere (uses builtin arcball library)
|
11
|
+
# 2. click mouse to toggle add box to sphere surface
|
12
|
+
# 3. press x, y, or z to constrain arcball rotation to that axis
|
13
|
+
#
|
14
|
+
|
15
|
+
PHI = (sqrt(5) + 1) / 2 - 1 # golden ratio
|
16
|
+
GA = PHI * TAU # golden angle
|
17
|
+
|
18
|
+
KMAX_POINTS = 100_000
|
19
|
+
|
20
|
+
attr_reader :pts, :rotation_x, :rotation_y, :nbr_points, :radius, :add_points
|
21
|
+
|
22
|
+
|
23
|
+
def setup
|
24
|
+
size(1024, 768, P3D)
|
25
|
+
Processing::ArcBall.init(self, width / 2.0, height / 2.0)
|
26
|
+
@rotation_x = 0
|
27
|
+
@rotation_y = 0
|
28
|
+
@nbr_points = 2000
|
29
|
+
@radius = 0.8 * height / 2
|
30
|
+
@add_points = true
|
31
|
+
@pts = Array.new(KMAX_POINTS)
|
32
|
+
init_sphere(nbr_points)
|
33
|
+
background(0)
|
34
|
+
end
|
35
|
+
|
36
|
+
def draw
|
37
|
+
if add_points
|
38
|
+
@nbr_points += 1
|
39
|
+
@nbr_points = [nbr_points, KMAX_POINTS].min
|
40
|
+
init_sphere(nbr_points)
|
41
|
+
end
|
42
|
+
|
43
|
+
background 0
|
44
|
+
lights
|
45
|
+
ambient(200, 10, 10)
|
46
|
+
ambient_light(150, 150, 150)
|
47
|
+
render_globe
|
48
|
+
end
|
49
|
+
|
50
|
+
###########################################
|
51
|
+
# For Fibonacci Sphere
|
52
|
+
##################################
|
53
|
+
|
54
|
+
def render_globe
|
55
|
+
push_matrix
|
56
|
+
(0..[nbr_points, pts.length].min).each do |i|
|
57
|
+
lat = pts[i].lat
|
58
|
+
lon = pts[i].lon
|
59
|
+
push_matrix
|
60
|
+
rotate_y(lon)
|
61
|
+
rotate_z(-lat)
|
62
|
+
fill(200, 10, 10)
|
63
|
+
translate(radius, 0, 0)
|
64
|
+
box(4, 7, 7)
|
65
|
+
pop_matrix
|
66
|
+
end
|
67
|
+
pop_matrix
|
68
|
+
end
|
69
|
+
|
70
|
+
def mouse_clicked
|
71
|
+
@add_points = !add_points
|
72
|
+
end
|
73
|
+
|
74
|
+
SpherePoint = Struct.new(:lat, :lon)
|
75
|
+
|
76
|
+
def init_sphere(num)
|
77
|
+
(0..num).each do |i|
|
78
|
+
lon = GA * i
|
79
|
+
lon /= TAU
|
80
|
+
lon -= lon.floor
|
81
|
+
lon *= TAU
|
82
|
+
lon -= TAU if lon > PI
|
83
|
+
# Convert dome height (which is proportional to surface area) to latitude
|
84
|
+
# lat = asin(-1 + 2 * i / num.to_f)
|
85
|
+
pts[i] = SpherePoint.new(asin(-1 + 2 * i / num.to_f), lon)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
FibonacciSphere.new title: 'Fibonacci Sphere'
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'propane'
|
2
|
+
|
3
|
+
class Grapher < Propane::App
|
4
|
+
# Grapher is based on a context free art design
|
5
|
+
# by ColorMeImpressed (takes a bit of time to run)
|
6
|
+
# http://www.contextfreeart.org/gallery/view.php?id=2844
|
7
|
+
#
|
8
|
+
CMIN = -2.0 # Important to specify float else get random int from range?
|
9
|
+
CMAX = 2.0
|
10
|
+
FUZZ = 0.04
|
11
|
+
SZ = 5
|
12
|
+
|
13
|
+
def setup
|
14
|
+
size 600, 600
|
15
|
+
no_stroke
|
16
|
+
color_mode(HSB, 1.0)
|
17
|
+
background(0)
|
18
|
+
frame_rate(4_000)
|
19
|
+
end
|
20
|
+
|
21
|
+
def draw
|
22
|
+
translate(width / 2, height / 2)
|
23
|
+
dot(rand(-180..180), rand(-180..180), rand(CMIN..CMAX)) unless frame_count > 200_000
|
24
|
+
end
|
25
|
+
|
26
|
+
def dot(px, py, c)
|
27
|
+
func = DegLut.sin(px) + DegLut.sin(py) + c
|
28
|
+
# change function to change the graph eg.
|
29
|
+
# func = DegLut.cos(px) + DegLut.sin(py) + c
|
30
|
+
if func.abs <= FUZZ
|
31
|
+
fill(((CMIN - c) / (CMIN - CMAX)), 1, 1)
|
32
|
+
ellipse px * width / 360, py * height / 360, SZ, SZ
|
33
|
+
else
|
34
|
+
dot(rand(-180..180), rand(-180..180), rand(CMIN..CMAX))
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
Grapher.new title: 'Grapher'
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'propane'
|
2
|
+
|
3
|
+
class Gravity < Propane::App
|
4
|
+
# After Gravity by Christian Hahn
|
5
|
+
|
6
|
+
attr_reader :particles, :grabbed
|
7
|
+
|
8
|
+
def setup
|
9
|
+
size 600, 500
|
10
|
+
@particles = []
|
11
|
+
@grabbed = nil
|
12
|
+
background 0
|
13
|
+
smooth 4
|
14
|
+
stroke_weight 4
|
15
|
+
ellipse_mode CENTER
|
16
|
+
color_mode RGB, 255
|
17
|
+
end
|
18
|
+
|
19
|
+
def draw
|
20
|
+
no_stroke
|
21
|
+
fill 0, 60
|
22
|
+
rect 0, 0, width, height
|
23
|
+
particles.each(&:run)
|
24
|
+
end
|
25
|
+
|
26
|
+
def mouse_pressed
|
27
|
+
return if mouse_x == 0 || mouse_y == 0
|
28
|
+
return if particle_grab
|
29
|
+
particles << Particle.new(mouse_x, mouse_y, rand(0.1..8))
|
30
|
+
end
|
31
|
+
|
32
|
+
def mouse_released
|
33
|
+
@grabbed = nil
|
34
|
+
end
|
35
|
+
|
36
|
+
def particle_grab
|
37
|
+
@grabbed = particles.detect { |p| dist(mouse_x, mouse_y, p.x1, p.y1) < p.diameter/2 }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class Particle
|
42
|
+
include Math, Propane::Proxy
|
43
|
+
GRAVITY = 1.0
|
44
|
+
attr_reader :x0, :y0, :x1, :y1, :diameter, :mass_amount
|
45
|
+
|
46
|
+
def initialize(x, y, mass)
|
47
|
+
@x0, @y0, @x1, @y1 = x, y, x, y
|
48
|
+
@x_speed, @y_speed = 0, 0
|
49
|
+
@x_accel, @y_accel = 0, 0
|
50
|
+
@mass_amount = mass
|
51
|
+
@diameter = sqrt(mass_amount) * 20
|
52
|
+
end
|
53
|
+
|
54
|
+
def collect_force
|
55
|
+
@x_accel, @y_accel = 0, 0
|
56
|
+
@min_dist = 1000
|
57
|
+
$app.particles.each do |p|
|
58
|
+
next if p == self
|
59
|
+
g_dist = hypot(x0 - p.x0, y0 - p.y0)
|
60
|
+
g_theta = -angle_of(x0, y0, p.x0, p.y0)
|
61
|
+
@min_dist = g_dist if g_dist < @min_dist
|
62
|
+
force = (GRAVITY * mass_amount * p.mass_amount) / g_dist
|
63
|
+
if g_dist.abs > diameter
|
64
|
+
@x_accel += force / mass_amount * cos(g_theta)
|
65
|
+
@y_accel += force / mass_amount * sin(g_theta)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def move
|
71
|
+
@x_speed, @y_speed = 0, 0 if grabbed?
|
72
|
+
@x_speed += @x_accel
|
73
|
+
@y_speed += @y_accel
|
74
|
+
@x1, @y1 = x0 + @x_speed, y0 + @y_speed
|
75
|
+
end
|
76
|
+
|
77
|
+
def grabbed?
|
78
|
+
$app.grabbed == self
|
79
|
+
end
|
80
|
+
|
81
|
+
def run
|
82
|
+
collect_force
|
83
|
+
move
|
84
|
+
render
|
85
|
+
end
|
86
|
+
|
87
|
+
def render
|
88
|
+
no_stroke
|
89
|
+
grabbed? ? render_grabbed : render_free
|
90
|
+
end
|
91
|
+
|
92
|
+
def render_free
|
93
|
+
charge_col = 1000.0 / @min_dist / 50.0
|
94
|
+
tot_col_1 = 100 + charge_col * 6
|
95
|
+
tot_col_2 = 150 + charge_col * charge_col
|
96
|
+
tot_col_3 = diameter + 8 + charge_col
|
97
|
+
fill(tot_col_1, tot_col_1, 255, charge_col * 150 + 3)
|
98
|
+
ellipse(x1, y1, tot_col_3, tot_col_3)
|
99
|
+
fill 0, 255
|
100
|
+
stroke tot_col_2, tot_col_2, 255, charge_col * 255 + 3
|
101
|
+
ellipse x1, y1, diameter, diameter
|
102
|
+
@x0, @y0 = x1, y1
|
103
|
+
end
|
104
|
+
|
105
|
+
def render_grabbed
|
106
|
+
fill 150, 150, 255, 100
|
107
|
+
ellipse mouse_x, mouse_y, diameter + 8, diameter + 8
|
108
|
+
fill 0, 255
|
109
|
+
stroke 150, 150, 255, 255
|
110
|
+
ellipse mouse_x, mouse_y, diameter, diameter
|
111
|
+
@x0, @y0 = mouse_x, mouse_y
|
112
|
+
end
|
113
|
+
|
114
|
+
def angle_of(x1, y1, x2, y2)
|
115
|
+
Math::PI - atan2(y1 - y2, x1 - x2)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
Gravity.new title: 'Gravity'
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
require 'propane'
|
4
|
+
|
5
|
+
class SliderDemo < Propane::App
|
6
|
+
load_library :slider
|
7
|
+
attr_reader :color1, :color2, :color3, :r, :gs, :b, :back
|
8
|
+
|
9
|
+
def setup
|
10
|
+
size(600, 400)
|
11
|
+
smooth(4)
|
12
|
+
@back = true
|
13
|
+
@r, @gs, @b = 0, 0, 0
|
14
|
+
@color1 = Slider.slider(
|
15
|
+
app: self,
|
16
|
+
vertical: true,
|
17
|
+
x: 100,
|
18
|
+
y: 77,
|
19
|
+
length: 200,
|
20
|
+
range: (-125.0..125.0),
|
21
|
+
name: 'Slider 1',
|
22
|
+
inital_value: 10
|
23
|
+
)
|
24
|
+
@color2 = Slider.slider(
|
25
|
+
app: self,
|
26
|
+
vertical: true,
|
27
|
+
x: 256,
|
28
|
+
y: 77,
|
29
|
+
length: 200,
|
30
|
+
range: (0..255),
|
31
|
+
name: 'Slider 2',
|
32
|
+
initial_value: 180
|
33
|
+
)
|
34
|
+
@color3 = Slider.slider(
|
35
|
+
app: self,
|
36
|
+
vertical: true,
|
37
|
+
x: 410,
|
38
|
+
y: 77,
|
39
|
+
length: 200,
|
40
|
+
range: (0.0..255.0),
|
41
|
+
name: 'Slider 3',
|
42
|
+
initial_value: 134
|
43
|
+
)
|
44
|
+
color1.bar_width(100)
|
45
|
+
color1.widget_colors(color('#930303'), color('#FF0000'))
|
46
|
+
color2.bar_width(100)
|
47
|
+
color2.widget_colors(color('#5BCE4D'), color('#1CFF00'))
|
48
|
+
color3.bar_width(100)
|
49
|
+
color3.widget_colors(color('#4439C9'), color('#9990FF'))
|
50
|
+
end
|
51
|
+
|
52
|
+
def draw
|
53
|
+
background(r + 125, gs, b)
|
54
|
+
@r = color1.read_value
|
55
|
+
@gs = color2.read_value
|
56
|
+
@b = color3.read_value
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
SliderDemo.new(title: 'Slider Demo')
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
require 'propane'
|
4
|
+
|
5
|
+
# Simple slider example
|
6
|
+
class SliderExample < Propane::App
|
7
|
+
load_library :slider
|
8
|
+
attr_reader :color1, :color2, :color3, :r, :gs, :b, :back
|
9
|
+
|
10
|
+
def setup
|
11
|
+
size(600, 400)
|
12
|
+
smooth(4)
|
13
|
+
@back = true
|
14
|
+
@r, @gs, @b = 0, 0, 0
|
15
|
+
@color1 = Slider.slider(
|
16
|
+
app: self,
|
17
|
+
x: 77,
|
18
|
+
y: 200,
|
19
|
+
length: 200,
|
20
|
+
range: (0..255.0),
|
21
|
+
name: 'Slider 1',
|
22
|
+
initial_value: 50
|
23
|
+
)
|
24
|
+
@color2 = Slider.slider(
|
25
|
+
app: self,
|
26
|
+
x: 77,
|
27
|
+
y: 230,
|
28
|
+
length: 200,
|
29
|
+
range: (0..255),
|
30
|
+
name: 'Slider 2',
|
31
|
+
initial_value: 50
|
32
|
+
)
|
33
|
+
@color3 = Slider.slider(
|
34
|
+
app: self,
|
35
|
+
x: 77,
|
36
|
+
y: 260,
|
37
|
+
length: 200,
|
38
|
+
range: (0.0..255.0),
|
39
|
+
name: 'Slider 3'
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
def draw
|
44
|
+
background(b, r, gs)
|
45
|
+
fill(r, gs, b)
|
46
|
+
ellipse(300, 200, 300, 300)
|
47
|
+
@r = color1.read_value
|
48
|
+
@gs = color2.read_value
|
49
|
+
@b = color3.read_value
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
SliderExample.new(title: 'Slider Example')
|