Skip to content

Commit fc0a644

Browse files
committed
add cairo_tiling
1 parent 0362ef2 commit fc0a644

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

contributed/cairo_tiling.rb

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env jruby
2+
3+
require 'picrate'
4+
5+
class CairoTiling < Processing::App
6+
ANGLE = PI / 2
7+
PTS = [Vec2D.new(-30, 0), Vec2D.new(30, 0), Vec2D.new(45, 45), Vec2D.new(0, 60), Vec2D.new(-45, 45)]
8+
S = 15
9+
W = 12 * S
10+
H = 6 * S
11+
12+
def settings
13+
size(W * 3, H * 6)
14+
end
15+
16+
def setup
17+
sketch_title 'Cairo tiling'
18+
cols = width + W
19+
rows = height + H
20+
grid(cols, rows, W, H) do |x, y|
21+
(y % W).zero? ? composite_tile(x + W / 2, y, S) : composite_tile(x, y, S)
22+
end
23+
end
24+
25+
# An example of GfxRenderer usage for Vec3D => vertex conversion
26+
def renderer
27+
@renderer ||= GfxRender.new(self.g)
28+
end
29+
30+
def composite_tile(x, y, s)
31+
stroke_weight 2
32+
fill(255, 220, 0)
33+
pentagon(x, y, s)
34+
fill(255, 220, 155)
35+
pentagon(x + 6 * s, y, s, r = 1)
36+
fill(0, 100, 200)
37+
pentagon(x - 6 * s, y, s, r = 3)
38+
fill(140, 180, 255)
39+
pentagon(x, y, s, r = 2)
40+
end
41+
42+
def pentagon(xo, yo, _s, r = 0)
43+
push_matrix
44+
translate(xo, yo)
45+
rotate(ANGLE * r)
46+
begin_shape
47+
PTS.map { |vec| vec.to_vertex(renderer) }
48+
end_shape
49+
pop_matrix
50+
end
51+
end
52+
53+
CairoTiling.new

0 commit comments

Comments
 (0)