Zuletzt aktiv 1750808423

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