1
+ global mut index: Int64 = 1
2
+
3
+ import imports.draw as draw(
4
+ x: Int64, y: Int64, r: Int64, g: Int64, b: Int64
5
+ ) -> Void
6
+
7
+ function min(floor: Int64, value: Int64) -> Int64 {
8
+ if value > floor then value else floor
9
+ }
10
+
11
+ function max(ceiling: Int64, value: Int64) -> Int64 {
12
+ if value < ceiling then value else ceiling
13
+ }
14
+
15
+ function clamp(
16
+ floor: Int64, ceiling: Int64, value: Int64
17
+ ) -> Int64 { min(floor, max(ceiling, value))}
18
+
19
+ function drawBounded(
20
+ x: Int64, y: Int64, color: (Int64,Int64,Int64)
21
+ ) -> (Int64,Int64,Int64) {
22
+ let maxWidth: Int64 = 600;
23
+ let maxHeight: Int64 = 600;
24
+ let (r, g, b) = color;
25
+ draw(
26
+ clamp(0, maxWidth, x), clamp(0, maxHeight, y), r, g, b
27
+ );
28
+ (r, g, b)
29
+ }
30
+
31
+ function cycle(color: (Int64,Int64,Int64)) -> (Int64,
32
+ Int64,
33
+ Int64) { let (r, g, b) = color; (g, b, r)}
34
+
35
+ function initial(index: Int64) -> (Int64,Int64,Int64) {
36
+ let r = clamp(0, 255, index * 2);
37
+ let g = clamp(0, 255, 255 - r);
38
+ let b = clamp(0, 255, r * 3);
39
+ (r, g, b)
40
+ }
41
+
42
+ export function test() -> Void {
43
+ let color = drawBounded(
44
+ index * 2, index * 3, initial(index)
45
+ );
46
+ let color2 = drawBounded(
47
+ 100 - index, index * 3, cycle(color)
48
+ );
49
+ let color3 = drawBounded(
50
+ 10 + index * 3, 50 - index * 2, cycle(color2)
51
+ );
52
+ drawBounded(index * 4, 200 - index * 3, cycle(color3));
53
+ if index < 200 then
54
+ set(index, index + 1)
55
+ else
56
+ set(index, 0)
57
+ }
0 commit comments