trans-pride-flag.nv
· 2.6 KiB · Text
Неформатований
Playground
|| :@include: (
lib/rpn.nv
lib/nv/meta.nv
lib/platforms/browser_game.nv
lib/platforms/browser_dom.nv
)
||:: 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
|:: draw a $color triangle at $x1 $y1 $x2 $y2 $x3 $y3 |
:@graphics: draw triangle $x1 $y1 $x2 $y2 $x3 $y3 $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. -|
|------------------------------------------------------------------------|
||: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 triangle $x1 $y1 $x2 $y2 $x3 $y3 $color|
:@graphics.draw: triangle $x1 $y1 $x2 $y2 $x3 $y3 $color
|:@graphics.draw: rect $x $y $w $h $color :@@canvas context: $ctx?|
:@js: $ctx.fillStyle = $color;
$ctx.fillRect( $x, $y, $w, $h );
|:@graphics.draw: triangle $x1 $y1 $x2 $y2 $x3 $y3 $color :@@canvas context: $ctx? |
:@js: $ctx.fillStyle = $color;
$ctx.beginPath();
$ctx.moveTo($x1 , $y1 );
$ctx.lineTo($x2 , $y2 );
$ctx.lineTo($x3 , $y3 );
$ctx.fill();
| 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(); |