Skip to content

Commit d1b04c8

Browse files
committed
Cairo tiling
1 parent 691f481 commit d1b04c8

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

contributed/cairo_tiling.rb

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
ANGLE = PI / 2
2+
PTS = [Vec2D.new(-30, 0), Vec2D.new(30, 0), Vec2D.new(45, 45), Vec2D.new(0, 60), Vec2D.new(-45, 45)]
3+
S = 15
4+
W = 12 * S
5+
H = 6 * S
6+
7+
def settings
8+
size(W * 3, H * 6)
9+
end
10+
11+
def setup
12+
sketch_title 'Cairo tiling'
13+
@renderer ||= GfxRender.new(g)
14+
cols = width + W
15+
rows = height + H
16+
grid(cols, rows, W, H) do |x, y|
17+
(y % W).zero? ? composite_tile(x + W / 2, y, S) : composite_tile(x, y, S)
18+
end
19+
end
20+
21+
def composite_tile(x, y, s)
22+
stroke_weight 2
23+
fill(255, 220, 0)
24+
pentagon(x, y, s)
25+
fill(255, 220, 155)
26+
pentagon(x + 6 * s, y, s, r = 1)
27+
fill(0, 100, 200)
28+
pentagon(x - 6 * s, y, s, r = 3)
29+
fill(140, 180, 255)
30+
pentagon(x, y, s, r = 2)
31+
end
32+
33+
def pentagon(xo, yo, s, r = 0)
34+
push_matrix
35+
translate(xo, yo)
36+
rotate(ANGLE * r)
37+
begin_shape
38+
PTS.map { |vec| vec.to_vertex(@renderer) }
39+
end_shape
40+
pop_matrix
41+
end

0 commit comments

Comments
 (0)