-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfountain.agate
111 lines (86 loc) · 3.16 KB
/
fountain.agate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import "agraphics" for Antialias, Color, LinearGradientPattern, Operator, Path, RadialGradientPattern, Surface, vec2
import "parts/colors" for Colors
import "parts/objects" for Brick
def SIZE = 128.0
def STONE_SIZE = 10.0
def random = Random.new(System.time)
def stone = Brick.new(random, vec2(STONE_SIZE, STONE_SIZE), 1.0, Colors.STONE)
def blue = Color.new(0x007577FF)
def square(x) { x * x }
once {
def FOUNTAIN_RADIUS = 55.0
def INNER_RADIUS = FOUNTAIN_RADIUS - STONE_SIZE / 2.0
def CIRCUM = 2.0 * Math.PI * FOUNTAIN_RADIUS
def STONE_NUMBER = (CIRCUM / STONE_SIZE).to_i
IO.println("Stones: %(STONE_NUMBER)")
IO.println("Surface (round): %((Math.PI * square(INNER_RADIUS)).to_i)")
def water = RadialGradientPattern.new(vec2(0.0, 0.0), 0.0, vec2(0.0, 0.0), INNER_RADIUS)
water.add_color_stop(0.0, blue)
water.add_color_stop(0.9, blue)
water.add_color_stop(1.0, Color.darker(blue))
def surface = Surface.new(vec2(SIZE, SIZE))
surface.draw {|ctx|
ctx.set_antialias(Antialias.BEST)
ctx.translate(SIZE / 2.0, SIZE / 2.0)
ctx.sub {|ctx|
ctx.circle(0.0, 0.0, INNER_RADIUS)
ctx.set_source_pattern(water)
ctx.fill()
}
for (i in 1..STONE_NUMBER) {
ctx.sub {|ctx|
ctx.rotate(i.to_f * Math.PI * 2.0 / STONE_NUMBER.to_f)
ctx.draw(stone.at(vec2(0.0 - STONE_SIZE / 2.0, FOUNTAIN_RADIUS - STONE_SIZE / 2.0)))
}
}
}
surface.export("fountain_round.png")
}
once {
def FOUTAIN_SIZE = 110.0
def STONE_NUMBER = (FOUTAIN_SIZE / STONE_SIZE).to_i
def OFFSET = (SIZE - FOUTAIN_SIZE) / 2.0
IO.println("Surface (square): %(square(FOUTAIN_SIZE - 2.0 * STONE_SIZE))")
def water_x = LinearGradientPattern.new(vec2(STONE_SIZE, 0.0), vec2((STONE_NUMBER - 1).to_f * STONE_SIZE, 0.0))
def water_y = LinearGradientPattern.new(vec2(0.0, STONE_SIZE), vec2(0.0, (STONE_NUMBER - 1).to_f * STONE_SIZE))
for (water in [ water_x, water_y ]) {
water.add_color_stop(0.0, Color.darker(blue))
water.add_color_stop(0.05, blue)
water.add_color_stop(0.95, blue)
water.add_color_stop(1.0, Color.darker(blue))
}
def surface = Surface.new(vec2(SIZE, SIZE))
surface.draw {|ctx|
ctx.set_antialias(Antialias.BEST)
ctx.translate(OFFSET, OFFSET)
ctx.sub {|ctx|
ctx.rectangle(vec2(STONE_SIZE, STONE_SIZE), vec2((STONE_NUMBER - 2).to_f * STONE_SIZE, (STONE_NUMBER - 2).to_f * STONE_SIZE))
ctx.set_source_pattern(water_x)
ctx.fill(Path.PRESERVE)
ctx.set_operator(Operator.DARKEN)
ctx.set_source_pattern(water_y)
ctx.fill()
}
for (i in 0...STONE_NUMBER) {
ctx.sub {|ctx|
ctx.draw(stone.at(vec2(i.to_f * STONE_SIZE, 0.0)))
ctx.draw(stone.at(vec2(i.to_f * STONE_SIZE, (STONE_NUMBER - 1).to_f * STONE_SIZE)))
}
}
for (i in 1...(STONE_NUMBER - 1)) {
ctx.sub {|ctx|
ctx.draw(stone.at(vec2(0.0, i.to_f * STONE_SIZE)))
ctx.draw(stone.at(vec2((STONE_NUMBER - 1).to_f * STONE_SIZE, i.to_f * STONE_SIZE)))
}
}
}
surface.export("fountain_square.png")
}
once {
def surface = Surface.new(vec2(SIZE, SIZE))
surface.draw {|ctx|
ctx.set_source_color(blue)
ctx.paint()
}
surface.export("fountain.png")
}