Skip to content

Commit 6af31d6

Browse files
committed
truchet tiling
1 parent 0531523 commit 6af31d6

File tree

8 files changed

+63
-0
lines changed

8 files changed

+63
-0
lines changed
File renamed without changes.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Jim Bumgardner
2+
3+
DIM = 24
4+
attr_reader :cells, :tile1, :tile2
5+
6+
def make_tile(state)
7+
create_graphics(DIM, DIM, P2D).tap do |g|
8+
g.smooth(4)
9+
g.begin_draw
10+
g.background(255)
11+
g.stroke(0)
12+
g.stroke_weight(4)
13+
g.no_fill
14+
g.ellipse_mode(RADIUS)
15+
if state
16+
g.ellipse(0, 0, DIM / 2, DIM / 2)
17+
g.ellipse(DIM, DIM, DIM / 2, DIM / 2)
18+
else
19+
g.ellipse(0, DIM, DIM / 2, DIM / 2)
20+
g.ellipse(DIM, 0, DIM / 2, DIM / 2)
21+
end
22+
g.end_draw
23+
end
24+
end
25+
26+
def setup
27+
sketch_title 'Truchet Tiling'
28+
@tile1 = make_tile(false)
29+
@tile2 = make_tile(true)
30+
@cells = []
31+
32+
grid(width, height, DIM, DIM) do |posx, posy|
33+
cells << Cell.new(Vec2D.new(posx, posy))
34+
end
35+
no_loop
36+
end
37+
38+
def draw
39+
background(255)
40+
cells.each(&:render)
41+
end
42+
43+
def settings
44+
size(576, 576, P2D)
45+
smooth(4)
46+
end
47+
48+
49+
class Cell
50+
include Processing::Proxy
51+
attr_reader :vec, :state
52+
53+
def initialize(vec)
54+
@vec = vec
55+
@state = rand < 0.5
56+
end
57+
58+
def render
59+
return image(tile1, vec.x, vec.y, tile1.width, tile1.height) if state
60+
61+
image(tile2, vec.x, vec.y, tile2.width, tile2.height)
62+
end
63+
end

0 commit comments

Comments
 (0)