Skip to content

Commit be39780

Browse files
committed
arc tesselation example
1 parent 5e08393 commit be39780

File tree

2 files changed

+89
-1
lines changed

2 files changed

+89
-1
lines changed

demo/arc_tesselation.rb

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/env jruby
2+
require 'picrate'
3+
4+
# After an openprocessing sketch by Manoylov AC
5+
# https://www.openprocessing.org/user/23616/
6+
# press mouse to generate new pattern
7+
# use `c` key to toggle colored / greyscale
8+
# use 's' to save
9+
10+
class ArcTesselation < Processing::App
11+
attr_reader :cols, :coloured
12+
13+
PALETTE = %w[#152A3B #158ca7 #F5C03E #D63826 #0F4155 #7ec873 #4B3331].freeze
14+
15+
def settings
16+
size(600, 600)
17+
end
18+
19+
def setup
20+
background 0
21+
sketch_title 'Arc Tesselation'
22+
# create a java primitive array of signed int
23+
@cols = web_to_color_array(PALETTE)
24+
stroke_weight 1.5
25+
stroke_cap SQUARE
26+
stroke(0, 200)
27+
@coloured = true
28+
end
29+
30+
def draw
31+
arc_pattern
32+
end
33+
34+
def sep_index(idx, length)
35+
(idx - (length - 1) * 0.5).abs.floor
36+
end
37+
38+
def sep_color(idx, number)
39+
cols[sep_index(idx - 1, number + 1)]
40+
end
41+
42+
def arc_pattern
43+
circ_number = rand(4..10)
44+
block_size = rand(30..70)
45+
back_color = coloured ? cols.last : 255
46+
fill(back_color)
47+
rect(0, 0, width, height)
48+
half_block = block_size / 2
49+
two_block = 2 * block_size
50+
grid(width + two_block, height + two_block, block_size, block_size) do |x, y|
51+
push_matrix
52+
translate x, y
53+
rotate HALF_PI * rand(0..4)
54+
circ_number.downto(0) do |i|
55+
diam = two_block * i / (circ_number + 1)
56+
ccolor = i < 2 || !coloured ? back_color : sep_color(i, circ_number)
57+
fill ccolor
58+
arc(-half_block, -half_block, diam, diam, 0, HALF_PI)
59+
arc(half_block, half_block, diam, diam, PI, PI + HALF_PI)
60+
end
61+
pop_matrix
62+
end
63+
no_loop
64+
end
65+
66+
def mouse_pressed
67+
@cols = shuffle_array(cols) if coloured
68+
loop
69+
end
70+
71+
def key_typed
72+
case key
73+
when 'c', 'C'
74+
@coloured = !coloured
75+
when 's', 'S'
76+
save(data_path('arc_pattern.png'))
77+
end
78+
end
79+
80+
# do a ruby shuffle! on a primitive java array
81+
def shuffle_array(arr)
82+
cols = arr.to_a
83+
cols.shuffle!
84+
cols.to_java(Java::int)
85+
end
86+
end
87+
88+
ArcTesselation.new

demo/chladni.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Chladni < Processing::App
2323
attr_reader :m, :n, :epsilon, :recompute
2424

2525
def settings
26-
size(500, 500)
26+
size(500, 500, P2D)
2727
end
2828

2929
def setup

0 commit comments

Comments
 (0)