flag.nv
· 2.1 KiB · Text
Неформатований
Playground
||
:: create a 400 by 400 canvas
:: draw the trans pride flag
|:: draw the trans pride flag|
:: clear the canvas to black
:: draw a 360 by 360 lightblue rectangle at 20 20
:: draw a 360 by 250 pink rectangle at 20 80
:: draw a 360 by 100 white rectangle at 20 150
|:: clear the canvas to $color|
:@graphics: clear $color
|:: draw a $width by $height $color rectangle at $x $y|
:@graphics: draw rect $x $y $width $height $color
|:: create a $width by $height canvas :canvas initialized:?|
:: set the canvas resolution to $width by $height
|:: create a $width by $height canvas|
:: initialize the canvas
:: set the canvas resolution to $width by $height
|:: set the canvas resolution to $width by $height :canvas initialized:?|
:@graphics: set resolution $width $height
|:: set the canvas resolution to $width by $height|
:error: you need to initialize the canvas first
|:: initialize the canvas :canvas initialized:?|
|:: initialize the canvas|
:@graphics: canvas init canvas
:canvas initialized:
|------------------------------------------------------------------------|
|- The code below this comment modifies the playground to add a canvas. -|
|------------------------------------------------------------------------|
|| :@include: (
lib/rpn.nv
lib/nv/meta.nv
lib/platforms/browser_game.nv
lib/platforms/browser_dom.nv
)
||:DOM: (
<query canvas <style center > >
<query #code <style display = none >
<query #code-actions < button innerText = [Edit Code] id = reset on click reset > >
)
|:click: reset|
:DOM: (
<query #code <style display = unset > >
<query #reset @remove >
)
|:DOM: @remove :current dom element: $el?| ⁝@js⁝ $el .remove();
|:DOM: center :current dom element: $el?|
:DOM: (
display = block
marginLeft = auto
marginRight = auto
)
|:@graphics: draw rect $x $y $w $h $color|
:@graphics.draw: rect $x $y $w $h $color
|:@graphics.draw: rect $x $y $w $h $color :@@canvas context: $ctx?|
⁝@js⁝ $ctx .fillStyle = $color;
$ctx .fillRect( $x, $y, $w, $h );
1 | || |
2 | :: create a 400 by 400 canvas |
3 | :: draw the trans pride flag |
4 | |
5 | |:: draw the trans pride flag| |
6 | :: clear the canvas to black |
7 | :: draw a 360 by 360 lightblue rectangle at 20 20 |
8 | :: draw a 360 by 250 pink rectangle at 20 80 |
9 | :: draw a 360 by 100 white rectangle at 20 150 |
10 | |
11 | |:: clear the canvas to $color| |
12 | :@graphics: clear $color |
13 | |
14 | |:: draw a $width by $height $color rectangle at $x $y| |
15 | :@graphics: draw rect $x $y $width $height $color |
16 | |
17 | |:: create a $width by $height canvas :canvas initialized:?| |
18 | :: set the canvas resolution to $width by $height |
19 | |:: create a $width by $height canvas| |
20 | :: initialize the canvas |
21 | :: set the canvas resolution to $width by $height |
22 | |
23 | |:: set the canvas resolution to $width by $height :canvas initialized:?| |
24 | :@graphics: set resolution $width $height |
25 | |:: set the canvas resolution to $width by $height| |
26 | :error: you need to initialize the canvas first |
27 | |
28 | |:: initialize the canvas :canvas initialized:?| |
29 | |:: initialize the canvas| |
30 | :@graphics: canvas init canvas |
31 | :canvas initialized: |
32 | |
33 | |
34 | |
35 | |
36 | |------------------------------------------------------------------------| |
37 | |- The code below this comment modifies the playground to add a canvas. -| |
38 | |------------------------------------------------------------------------| |
39 | |
40 | || :@include: ( |
41 | lib/rpn.nv |
42 | lib/nv/meta.nv |
43 | lib/platforms/browser_game.nv |
44 | lib/platforms/browser_dom.nv |
45 | ) |
46 | |
47 | ||:DOM: ( |
48 | <query canvas <style center > > |
49 | <query #code <style display = none > |
50 | <query #code-actions < button innerText = [Edit Code] id = reset on click reset > > |
51 | ) |
52 | |
53 | |:click: reset| |
54 | :DOM: ( |
55 | <query #code <style display = unset > > |
56 | <query #reset @remove > |
57 | ) |
58 | |
59 | |:DOM: @remove :current dom element: $el?| ⁝@js⁝ $el .remove(); |
60 | |:DOM: center :current dom element: $el?| |
61 | :DOM: ( |
62 | display = block |
63 | marginLeft = auto |
64 | marginRight = auto |
65 | ) |
66 | |
67 | |:@graphics: draw rect $x $y $w $h $color| |
68 | :@graphics.draw: rect $x $y $w $h $color |
69 | |
70 | |:@graphics.draw: rect $x $y $w $h $color :@@canvas context: $ctx?| |
71 | ⁝@js⁝ $ctx .fillStyle = $color; |
72 | $ctx .fillRect( $x, $y, $w, $h ); |