-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrawing-things.html
190 lines (158 loc) · 6.87 KB
/
drawing-things.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<!DOCTYPE html>
<html>
<head>
<meta name = viewport content = "width=device-width,initial-scale=1">
<link rel = icon href = data/images/favicon.ico sizes = "16x16 32x32 48x48 64x64">
<script src = data/js/setup.js></script>
<script src = data/js/code.js></script>
<link rel = stylesheet href = data/css/fontawesome.css>
<link rel = stylesheet href = data/css/all.css>
<link rel = stylesheet href = data/css/main.css>
<title>JoBase · Drawing Things</title>
</head>
<body>
<section class = top>
<a href = "/">JoBase</a>
<i class = "fa-solid fa-bars"></i>
<i class = "fa-solid fa-sun"></i>
<a href = lessons class = this>Lessons</a>
<a href = demos>Demos</a>
<a href = games>Games</a>
<a href = reference>Reference</a>
<a href = download>Download</a>
<a href = https://github.com/JoBase target = _blank>
<i class = "fa-brands fa-github"></i>
</a>
<a href = https://discord.gg/DzHyvZfa5q target = _blank>
<i class = "fa-brands fa-discord"></i>
</a>
</section>
<section class = main>
<a href = first-steps><i class = "fa-solid fa-chevron-left"></i> Back</a>
<a class = right href = user-interaction>Next <i class = "fa-solid fa-chevron-right"></i></a>
<h1>Drawing Things</h1>
<p>
Now it's time to draw some shapes!
Let's start with a simple rectangle.
</p>
<script>
snippet([
"",
"import JoBase\n\nbox = Rectangle()\n\ndef loop():\n box.draw()\n\nrun()"
])
</script>
<p>
You should now see a default black square on the screen.
We can turn it into a rectangle by changing its size.
</p>
<script>
snippet([
"import JoBase\n\nbox = Rectangle(",
"width = 100, height = 30",
")\n\ndef loop():\n box.draw()\n\nrun()"
])
</script>
<p>
We can also put it in a different place.
</p>
<script>
snippet([
"import JoBase\n\nbox = Rectangle(",
"x = -150, y = 0,",
" width = 100, height = 30)\n\ndef loop():\n box.draw()\n\nrun()"
])
</script>
<p>
As you can see, the code is getting a bit long.
We can shorten it by getting rid of the keyword labels.
</p>
<script>
snippet([
"import JoBase\n\nbox = Rectangle(",
"-150, 0, 100, 30",
")\n\ndef loop():\n box.draw()\n\nrun()"
])
</script>
<p>
Remember that when removing the labels, you need to keep the attributes in the right order.
You must define rectangle attributes in the order of <mark>x</mark>, <mark>y</mark>, <mark>width</mark>, <mark>height</mark>, <mark>angle</mark> and <mark>color</mark>.
Now we can rotate our rectangle with the <mark>angle</mark> attribute.
</p>
<script>
snippet([
"import JoBase\n\nbox = Rectangle(-150, 0, 100, 30,",
" 50",
")\n\ndef loop():\n box.draw()\n\nrun()"
])
</script>
<div class = slot>
<img src = data/images/rect.png>
</div>
<p>
Let's add a circle.
</p>
<script>
snippet([
"import JoBase\n\nbox = Rectangle(-150, 0, 100, 30, 50)",
"\ncircle = Circle(diameter = 80, color = GOLD)",
"\n\ndef loop():\n box.draw()",
"\n circle.draw()",
"\n\nrun()"
])
</script>
<p>
This will draw a circle in the middle of the screen.
Like before we can position our circle and remove the labels.
Cirle attributes must be defined in the order of <mark>x</mark>, <mark>y</mark>, <mark>diameter</mark> and <mark>color</mark>.
</p>
<script>
snippet([
"import JoBase\n\nbox = Rectangle(-150, 0, 100, 30, 50)\ncircle = Circle(",
"150, 0, 80, GOLD",
")\n\ndef loop():\n box.draw()\n circle.draw()\n\nrun()"
])
</script>
<div class = slot>
<img src = data/images/circle.png>
</div>
<p>
Finally, let's create our own custom shape.
We can do this by defining the coordinates for its corners.
</p>
<script>
snippet([
"import JoBase\n\nbox = Rectangle(-150, 0, 100, 30, 50)\ncircle = Circle(150, 0, 80, GOLD)",
"\n\nshape = Shape(((-50, -20), (0, 50), (20, 0)), color = LIGHT_BLUE)",
"\n\ndef loop():\n box.draw()\n circle.draw()",
"\n shape.draw()",
"\n\nrun()"
])
</script>
<p>
As we defined three corners, this makes a blue triangle in the middle of the screen.
The great thing about custom shapes is that you can make them as complex as you like.
</p>
<script>
snippet([
"import JoBase\n\nbox = Rectangle(-150, 0, 100, 30, 50)\ncircle = Circle(150, 0, 80, GOLD)\n\nshape = Shape((",
"\n (0, 50), (15, 15),\n (50, 0), (15, -15),\n (0, -50), (-15, -15),\n (-50, 0), (-15, 15)",
"), color = LIGHT_BLUE)\n\ndef loop():\n box.draw()\n circle.draw()\n shape.draw()\n\nrun()"
])
</script>
<div class = slot>
<img src = data/images/shape.png>
</div>
<p>
Now you can draw things in JoBase!
Experiment with different combinations and add them to your next game.
</p>
<a href = first-steps><i class = "fa-solid fa-chevron-left"></i> Back</a>
<a class = right href = user-interaction>Next <i class = "fa-solid fa-chevron-right"></i></a>
</section>
<footer>
<span>
© Copyright <span id = year></span> JoBase · <a href = mailto:hello@jobase.org>hello@jobase.org</a>
</span>
</footer>
</body>
</html>