Last active 1752438127

A small Nova program to draw the trans pride flag in the playground.

wryl revised this gist 1752438127. Go to revision

1 file changed, 88 insertions

trans-pride-flag.nv(file created)

@@ -0,0 +1,88 @@
1 + || :@include: (
2 + lib/rpn.nv
3 + lib/nv/meta.nv
4 + lib/platforms/browser_game.nv
5 + lib/platforms/browser_dom.nv
6 + )
7 +
8 + ||:: create a 400 by 400 canvas
9 + :: draw the trans pride flag
10 +
11 + |:: draw the trans pride flag|
12 + :: clear the canvas to black
13 + :: draw a 360 by 360 lightblue rectangle at 20 20
14 + :: draw a 360 by 250 pink rectangle at 20 80
15 + :: draw a 360 by 100 white rectangle at 20 150
16 +
17 + |:: clear the canvas to $color|
18 + :@graphics: clear $color
19 +
20 + |:: draw a $width by $height $color rectangle at $x $y|
21 + :@graphics: draw rect $x $y $width $height $color
22 +
23 + |:: draw a $color triangle at $x1 $y1 $x2 $y2 $x3 $y3 |
24 + :@graphics: draw triangle $x1 $y1 $x2 $y2 $x3 $y3 $color
25 +
26 + |:: create a $width by $height canvas :canvas initialized:?|
27 + :: set the canvas resolution to $width by $height
28 + |:: create a $width by $height canvas|
29 + :: initialize the canvas
30 + :: set the canvas resolution to $width by $height
31 +
32 + |:: set the canvas resolution to $width by $height :canvas initialized:?|
33 + :@graphics: set resolution $width $height
34 + |:: set the canvas resolution to $width by $height|
35 + :error: you need to initialize the canvas first
36 +
37 + |:: initialize the canvas :canvas initialized:?|
38 + |:: initialize the canvas|
39 + :@graphics: canvas init canvas
40 + :canvas initialized:
41 +
42 +
43 +
44 +
45 +
46 +
47 +
48 +
49 + |------------------------------------------------------------------------|
50 + |- The code below this comment modifies the playground to add a canvas. -|
51 + |------------------------------------------------------------------------|
52 +
53 + ||:DOM: (
54 + <query canvas <style center > >
55 + <query #code <style display = none >
56 + <query #code-actions < button innerText = [Edit Code] id = reset on click reset > >
57 + )
58 +
59 + |:click: reset|
60 + :DOM: (
61 + <query #code <style display = unset > >
62 + <query #reset @remove >
63 + )
64 +
65 + |:DOM: @remove :current dom element: $el?| :@js: $el .remove();
66 + |:DOM: center :current dom element: $el?|
67 + :DOM: (
68 + display = block
69 + marginLeft = auto
70 + marginRight = auto
71 + )
72 +
73 + |:@graphics: draw rect $x $y $w $h $color|
74 + :@graphics.draw: rect $x $y $w $h $color
75 + |:@graphics: draw triangle $x1 $y1 $x2 $y2 $x3 $y3 $color|
76 + :@graphics.draw: triangle $x1 $y1 $x2 $y2 $x3 $y3 $color
77 +
78 + |:@graphics.draw: rect $x $y $w $h $color :@@canvas context: $ctx?|
79 + :@js: $ctx.fillStyle = $color;
80 + $ctx.fillRect( $x, $y, $w, $h );
81 +
82 + |:@graphics.draw: triangle $x1 $y1 $x2 $y2 $x3 $y3 $color :@@canvas context: $ctx? |
83 + :@js: $ctx.fillStyle = $color;
84 + $ctx.beginPath();
85 + $ctx.moveTo($x1 , $y1 );
86 + $ctx.lineTo($x2 , $y2 );
87 + $ctx.lineTo($x3 , $y3 );
88 + $ctx.fill();
Newer Older