Skip to content

Commit 1a3b1d0

Browse files
committed
first proper commit
1 parent 8e58972 commit 1a3b1d0

944 files changed

Lines changed: 60401 additions & 35 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,5 @@
11
*.gem
22
*.rbc
3-
/.config
4-
/coverage/
5-
/InstalledFiles
6-
/pkg/
7-
/spec/reports/
8-
/spec/examples.txt
9-
/test/tmp/
10-
/test/version_tmp/
11-
/tmp/
12-
13-
## Specific to RubyMotion:
14-
.dat*
15-
.repl_history
16-
build/
17-
18-
## Documentation cache and generated files:
19-
/.yardoc/
20-
/_yardoc/
21-
/doc/
22-
/rdoc/
23-
24-
## Environment normalization:
25-
/.bundle/
26-
/vendor/bundle
27-
/lib/bundler/man/
28-
29-
# for a library or gem, you might want to ignore these files since the code is
30-
# intended to run in multiple environments; otherwise, check them in:
31-
# Gemfile.lock
32-
# .ruby-version
33-
# .ruby-gemset
34-
35-
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
3+
*~
4+
*.swp
365
.rvmrc

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
# JRubyArt-examples
2-
Example sketches for JRubyArt
1+
# JRubyArt-examples for JRubyArt-1.1+
2+
Example sketches for JRubyArt, feel free to contribute your own examples to the contributed section:-
3+
4+
The sketches under the processing_app folder approximate to those included with vanilla processing, with the addition of some JRubyArt library sketches. External library sketches
5+
corresponding to vanilla processing contributed libraries and gem libraries are organised in the external_library folder.
6+

contributed/Rakefile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Simple demo Rakefile to autorun samples in current directory
2+
# adjust path to rp5 executable, and or opts as required
3+
4+
SAMPLES_DIR = './'
5+
6+
desc 'run demo'
7+
task default: [:demo]
8+
9+
desc 'demo'
10+
task :demo do
11+
samples_list.shuffle.each { |sample| run_sample sample }
12+
end
13+
14+
def samples_list
15+
files = []
16+
Dir.chdir(SAMPLES_DIR)
17+
Dir.glob('*.rb').each do |file|
18+
files << File.join(SAMPLES_DIR, file)
19+
end
20+
return files
21+
end
22+
23+
def run_sample(sample_name)
24+
puts "Running #{sample_name}...quit to run next sample"
25+
open("|k9 run #{sample_name}", 'r') do |io|
26+
while l = io.gets
27+
puts(l.chop)
28+
end
29+
end
30+
end

contributed/animator.rb

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# From the Processing Examples
2+
# Uses the "bare" style, where a Processing::App sketch is implicitly wrapped
3+
# around the code.
4+
# -- omygawshkenas
5+
6+
FRAME_COUNT = 12
7+
8+
def setup
9+
sketch_title 'Animator'
10+
@frames = []
11+
@last_time = 0
12+
@current_frame = 0
13+
@draw = false
14+
@back_color = 204
15+
stroke_weight 4
16+
smooth
17+
background @back_color
18+
FRAME_COUNT.times { @frames << get }
19+
end
20+
21+
def draw
22+
time = millis
23+
if time > @last_time + 100
24+
next_frame
25+
@last_time = time
26+
end
27+
line(pmouse_x, pmouse_y, mouse_x, mouse_y) if @draw
28+
end
29+
30+
def mouse_pressed
31+
@draw = true
32+
end
33+
34+
def mouse_released
35+
@draw = false
36+
end
37+
38+
def key_pressed
39+
background @back_color
40+
@frames.size.times { |i| @frames[i] = get }
41+
end
42+
43+
def next_frame
44+
@frames[@current_frame] = get
45+
@current_frame += 1
46+
@current_frame = 0 if @current_frame >= @frames.size
47+
image(@frames[@current_frame], 0, 0)
48+
end
49+
50+
def settings
51+
size 350, 350
52+
end

contributed/bezier_playground.rb

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
# A Bezier playground. Click to shape the curve. Drag to move it.
2+
# Arrows toggle between curves, delete removes them.
3+
# You can print out the parametric equations for t = 0..1
4+
module Olap
5+
def self.overlaps(x, y, point_x, point_y)
6+
Math.hypot(x - point_x, y - point_y) < RADIUS
7+
end
8+
end
9+
10+
class Curve
11+
include Olap, Processing::Proxy
12+
attr_accessor :x1, :y1, :c1x, :c1y, :c2x, :c2y, :x2, :y2
13+
14+
def initialize
15+
@x1, @y1, @x2, @y2 = X1, Y1, X2, Y2
16+
set_control_points(X1 + 30, Y1, X2 - 30, Y2)
17+
end
18+
19+
def contains(x, y)
20+
return :one if Olap.overlaps(x1, y1, x, y)
21+
return :two if Olap.overlaps(x2, y2, x, y)
22+
end
23+
24+
def all_points
25+
return x1, y1, c1x, c1y, c2x, c2y, x2, y2
26+
end
27+
28+
def control_points
29+
return c1x, c1y, c2x, c2y
30+
end
31+
32+
def set_control_points(*points)
33+
@c1x, @c1y, @c2x, @c2y = *points
34+
end
35+
36+
def draw
37+
bezier(*all_points)
38+
oval x1, y1, 3, 3
39+
oval x2, y2, 3, 3
40+
end
41+
42+
def print_equation(id)
43+
pt = all_points.map(&:to_i)
44+
puts ''
45+
puts format('*** line #%s ***', id)
46+
xformat = 'x = (1-t)^3 %s + 3(1-t)^2 t%s + 3(1-t)t^2 %s + t^3 %s'
47+
yformat = 'y = -1 * ((1-t)^3 %s + 3(1-t)^2 t%s + 3(1-t)t^2 %s + t^3 %s'
48+
puts format(xformat, pt[0], pt[2], pt[4], pt[6])
49+
puts format(yformat, pt[1], pt[3], pt[5], pt[7])
50+
puts ''
51+
end
52+
end
53+
54+
attr_accessor :curves, :c1x, :c1y, :c2x, :c2y
55+
attr_reader :panel, :hide
56+
57+
X1, Y1, X2, Y2 = 50.0, 50.0, 250.0, 250.0
58+
REDDISH = [250, 100, 100]
59+
RADIUS = 7
60+
61+
load_library :control_panel
62+
63+
include Olap
64+
65+
def setup
66+
sketch_title 'Bezier playground'
67+
@curves = []
68+
@hide = false
69+
control_panel do |c|
70+
c.look_feel 'Nimbus'
71+
c.button :new_curve
72+
c.button :print_equations
73+
@panel = c
74+
end
75+
generate_curve
76+
end
77+
78+
def draw
79+
unless hide
80+
panel.set_visible true
81+
@hide = true
82+
end
83+
background 50
84+
draw_control_tangent_lines
85+
draw_curves
86+
draw_current_control_points
87+
end
88+
89+
def print_equations
90+
curves.each_with_index { |c, i| c.print_equation(i + 1) }
91+
end
92+
93+
def control_points
94+
return c1x, c1y, c2x, c2y
95+
end
96+
97+
def set_control_points(*points)
98+
@c1x, @c1y, @c2x, @c2y = points.any? ? points : [X1, Y1, X2, Y2]
99+
end
100+
101+
def generate_curve
102+
curves << current_curve = Curve.new
103+
@current = curves.length - 1
104+
set_control_points(*current_curve.control_points)
105+
end
106+
107+
def current_curve
108+
curves[@current]
109+
end
110+
111+
def new_curve
112+
current_curve.set_control_points(c1x, c1y, c2x, c2y)
113+
generate_curve
114+
end
115+
116+
def clicked_control_point?
117+
x, y = mouse_x, mouse_y
118+
return :one if Olap.overlaps(c1x, c1y, x, y)
119+
return :two if Olap.overlaps(c2x, c2y, x, y)
120+
end
121+
122+
def mouse_pressed
123+
switch_curve_if_endpoint_clicked
124+
@control = clicked_control_point?
125+
return if @control
126+
curve = curves.detect { |c| c.contains(mouse_x, mouse_y) }
127+
@end_point = curve.contains(mouse_x, mouse_y) if curve
128+
end
129+
130+
def mouse_released
131+
@control, @end_point = nil, nil
132+
@hide = false
133+
end
134+
135+
def mouse_dragged
136+
offs = compute_offsets
137+
return if offs.map(&:abs).max > 100
138+
return move_control_point(*offs) if @control
139+
return move_end_point(*offs) && move_control_point(*offs) if @end_point
140+
move_current_curve(*offs)
141+
end
142+
143+
def switch_curve_if_endpoint_clicked
144+
become = curves.detect { |c| c.contains(mouse_x, mouse_y) }
145+
return unless become && become != current_curve
146+
current_curve.set_control_points(*control_points)
147+
self.set_control_points(*become.control_points)
148+
@current = curves.index(become)
149+
end
150+
151+
def move_current_curve(x_off, y_off)
152+
@c1x += x_off; @c2x += x_off
153+
@c1y += y_off; @c2y += y_off
154+
current_curve.set_control_points(*control_points)
155+
current_curve.x1 += x_off; current_curve.x2 += x_off
156+
current_curve.y1 += y_off; current_curve.y2 += y_off
157+
end
158+
159+
def move_control_point(x_off, y_off)
160+
case @control || @end_point
161+
when :one then @c1x += x_off and @c1y += y_off
162+
when :two then @c2x += x_off and @c2y += y_off
163+
end
164+
current_curve.set_control_points(*control_points)
165+
end
166+
167+
def move_end_point(x_off, y_off)
168+
c = current_curve
169+
case @end_point
170+
when :one then c.x1 += x_off and c.y1 += y_off
171+
when :two then c.x2 += x_off and c.y2 += y_off
172+
end
173+
end
174+
175+
def compute_offsets
176+
return mouse_x - pmouse_x, mouse_y - pmouse_y
177+
end
178+
179+
def draw_curves
180+
stroke 255
181+
no_fill
182+
stroke_width 2
183+
curves.each(&:draw)
184+
end
185+
186+
def draw_current_control_points
187+
fill color(*REDDISH)
188+
no_stroke
189+
oval c1x, c1y, 5, 5
190+
oval c2x, c2y, 5, 5
191+
end
192+
193+
def draw_control_tangent_lines
194+
c = current_curve
195+
stroke color(*REDDISH)
196+
stroke_width 1
197+
line c1x, c1y, c.x1, c.y1
198+
line c2x, c2y, c.x2, c.y2
199+
end
200+
201+
def settings
202+
size 300, 300
203+
end

0 commit comments

Comments
 (0)