-
Notifications
You must be signed in to change notification settings - Fork 0
/
drawing-testing.go
288 lines (213 loc) · 8.87 KB
/
drawing-testing.go
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
package main
/*
import rl "github.com/gen2brain/raylib-go/raylib"
func main() { // VS Code is very unhappy with this...
rl.InitWindow(450, 450, "Raylib-go Drawing Test")
defer rl.CloseWindow()
rl.SetTargetFPS(60)
for !rl.WindowShouldClose() {
rl.BeginDrawing()
rl.ClearBackground(rl.RayWhite)
// drawOnLaptop()
drawOnDesktop()
// p1 := rl.Vector2{X: 10., Y: 10.}
// p2 := rl.Vector2{X: 20., Y: 10.}
// p3 := rl.Vector2{X: 20., Y: 20.}
// p4 := rl.Vector2{X: 10., Y: 20.}
// rl.DrawPixel(9, 9, rl.Green)
// rl.DrawPixel(19, 9, rl.Green)
// rl.DrawPixel(19, 19, rl.Green)
// rl.DrawPixel(9, 19, rl.Green)
/*
// Remove Block comment to include grouped stuff
rl.DrawLine(100, 50, 100, 200, rl.Green)
rl.DrawLine(110, 50, 110, 200, rl.Green)
// Draw Pixel Functions are Zero-Indexed
rl.DrawPixel(100-1, 100-1, rl.Orange)
rl.DrawPixel(110-1, 100-1, rl.Orange)
rl.DrawPixel(100-1, 110-1, rl.Orange)
rl.DrawPixel(110-1, 110-1, rl.Orange)
// rl.DrawPixelV(rl.Vector2{X: 99.1, Y: 99.1}, rl.Green)
// rl.DrawPixelV(rl.Vector2{X: 108.9, Y: 98.9}, rl.Green)
// rl.DrawPixelV(rl.Vector2{X: 99.5, Y: 109.5}, rl.Green) // Rounds up
// rl.DrawPixelV(rl.Vector2{X: 108.5, Y: 108.5}, rl.Green) // Rounds Down
// Draw Line Functions are not zero indexed (round down), and don't include the starting pixel (because they draw from a )
rl.DrawLineV(rl.Vector2{X: 100.0, Y: 100.}, rl.Vector2{X: 110, Y: 100}, rl.Black)
rl.DrawLine(100, 110, 110, 110, rl.Black)
rl.DrawLine(110, 120, 100, 120, rl.Black)
// rl.DrawLine(0, 0, 100, 0, rl.Black)
// rl.DrawLine(0, 1, 100, 1, rl.Orange)
// rl.DrawLine(1, 1, 100, 1, rl.Black)
// rl.DrawLine(1, 1, 1, 1, rl.Black)
// rl.DrawLineV(p1, p2, rl.Black)
// rl.DrawLineV(p2, p3, rl.Red)
// rl.DrawLineV(p3, p4, rl.Blue)
// rl.DrawLineV(p4, p1, rl.Orange)
// */ /*
rl.EndDrawing()
}
}
func drawOnLaptop() {
drawSquareOnLaptop()
drawPixelsAndLinesOnLaptop()
}
func drawOnDesktop() {
drawLinesExample(200, 10, 1)
drawSquareOnDesktop()
drawPixelsOnDesktop()
drawLinesOnDesktop()
}
func drawLinesExample(offsetX int32, offsetY int32, spacingX int32) {
ex := offsetX
ey := offsetY
if spacingX < 6 {
spacingX = 6
}
// 45 Deg Diagonal: behaves as expected
// ------------------------
rl.DrawPixel(0+ex, 0+ey, rl.Black)
rl.DrawPixel(1+ex, 1+ey, rl.Black)
rl.DrawPixel(2+ex, 2+ey, rl.Black)
rl.DrawPixel(3+ex, 3+ey, rl.Black)
rl.DrawPixel(4+ex, 4+ey, rl.Black)
rl.DrawLine(1+ex, 1+ey, 4+ex, 4+ey, rl.Red)
// ------------------------
ex += spacingX
// Horizontal (Exacting): behaves as expected
// ------------------------
rl.DrawPixel(0+ex, 1+ey, rl.Black)
rl.DrawPixel(1+ex, 1+ey, rl.Black)
rl.DrawPixel(2+ex, 1+ey, rl.Black)
rl.DrawPixel(3+ex, 1+ey, rl.Black)
rl.DrawPixel(4+ex, 1+ey, rl.Black)
rl.DrawLine(1+ex, 1+ey, 4+ex, 2+ey, rl.Red)
// ------------------------
ex += spacingX
// Horizontal (Ambuguous): Y draws higher pixel value, filling the pixel below the line index
// ------------------------
rl.DrawPixel(0+ex, 1+ey, rl.Black)
rl.DrawPixel(1+ex, 1+ey, rl.Black)
rl.DrawPixel(2+ex, 1+ey, rl.Black)
rl.DrawPixel(3+ex, 1+ey, rl.Black)
rl.DrawPixel(4+ex, 1+ey, rl.Black)
rl.DrawLine(1+ex, 1+ey, 4+ex, 1+ey, rl.Red) // Y draws higher pixel value, filling the pixel below the line index
// ------------------------
ex += spacingX
// Vertical (Exacting): behaves as expected
// ------------------------
rl.DrawPixel(1+ex, 0+ey, rl.Black)
rl.DrawPixel(1+ex, 1+ey, rl.Black)
rl.DrawPixel(1+ex, 2+ey, rl.Black)
rl.DrawPixel(1+ex, 3+ey, rl.Black)
rl.DrawPixel(1+ex, 4+ey, rl.Black)
rl.DrawLine(1+ex, 1+ey, 2+ex, 4+ey, rl.Red)
// ------------------------
ex += spacingX
// Vertical (ambuguous): X draws the lower pixel value, filling the pixel left of the line index
// ------------------------
rl.DrawPixel(1+ex, 0+ey, rl.Black)
rl.DrawPixel(1+ex, 1+ey, rl.Black)
rl.DrawPixel(1+ex, 2+ey, rl.Black)
rl.DrawPixel(1+ex, 3+ey, rl.Black)
rl.DrawPixel(1+ex, 4+ey, rl.Black)
rl.DrawLine(1+ex, 1+ey, 1+ex, 4+ey, rl.Red) // X draws the lower pixel value, filling the pixel left of the line index
// ------------------------
}
func drawSquareOnLaptop() {
// On my laptop:
// Pixels are Zero-indexed
// Orange (Lines) :- Pixels: (0,0) - (0,49); (0,49) - (49,49); (0,0) - (49,0); (49,0) - (49,49)
// Red (Pixels) :- Pixels: (0,0); (0,49); (49,49); (49,0)
// Black (Rectangle) :- Pixels: (1,1) - (1,48); (1,48) - (48,48); (1,1) - (48,1); (48,1) - (48,48); And everything in between
rl.DrawLine(0, 1, 50, 1, rl.Orange)
rl.DrawLine(1, 0, 1, 50, rl.Orange)
rl.DrawLine(50, 0, 50, 50, rl.Orange)
rl.DrawLine(0, 50, 50, 50, rl.Orange)
rl.DrawPixel(0, 0, rl.Red)
rl.DrawPixel(0, 49, rl.Red)
rl.DrawPixel(49, 49, rl.Red)
rl.DrawPixel(49, 0, rl.Red)
rl.DrawRectangle(1, 1, 48, 48, rl.Black)
}
func drawSquareOnDesktop() {
// On my laptop:
// Pixels are Zero-indexed
// Orange (Lines) :- Pixels: (0,0) - (0,49); (0,49) - (49,49); (0,0) - (49,0); (49,0) - (49,49)
// Red (Pixels) :- Pixels: (0,0); (0,49); (49,49); (49,0)
// Black (Rectangle) :- Pixels: (1,1) - (1,48); (1,48) - (48,48); (1,1) - (48,1); (48,1) - (48,48); And everything in between
// rl.DrawPixel(0, 0, rl.Red)
rl.DrawLine(0, 0, 50, 0, rl.Orange) // Pixels: ( 0, 0) - (49, 0)
rl.DrawLine(1, 0, 1, 50, rl.Orange) // Pixels: ( 0, 0) - ( 0,49)
rl.DrawLine(50, 0, 50, 50, rl.Orange) // Pixels: (49, 0) - (49,49)
rl.DrawLine(0, 49, 50, 49, rl.Orange) // Pixels: ( 0,49) - (49,49)
rl.DrawPixel(0, 0, rl.Red)
rl.DrawPixel(0, 49, rl.Red)
rl.DrawPixel(49, 49, rl.Red)
rl.DrawPixel(49, 0, rl.Red)
rl.DrawRectangle(1, 1, 48, 48, rl.Black)
}
func drawPixelsAndLinesOnLaptop() {
// p1 := rl.Vector2{X: 10., Y: 10.}
// p2 := rl.Vector2{X: 20., Y: 10.}
// p3 := rl.Vector2{X: 20., Y: 20.}
// p4 := rl.Vector2{X: 10., Y: 20.}
// rl.DrawPixel(9, 9, rl.Green)
// rl.DrawPixel(19, 9, rl.Green)
// rl.DrawPixel(19, 19, rl.Green)
// rl.DrawPixel(9, 19, rl.Green)
rl.DrawLine(100, 50, 100, 200, rl.Green)
rl.DrawLine(110, 50, 110, 200, rl.Green)
// Draw Pixel Functions are Zero-Indexed
rl.DrawPixel(100-1, 100-1, rl.Orange)
rl.DrawPixel(110-1, 100-1, rl.Orange)
rl.DrawPixel(100-1, 110-1, rl.Orange)
rl.DrawPixel(110-1, 110-1, rl.Orange)
// rl.DrawPixelV(rl.Vector2{X: 99.1, Y: 99.1}, rl.Green)
// rl.DrawPixelV(rl.Vector2{X: 108.9, Y: 98.9}, rl.Green)
// rl.DrawPixelV(rl.Vector2{X: 99.5, Y: 109.5}, rl.Green) // Rounds up
// rl.DrawPixelV(rl.Vector2{X: 108.5, Y: 108.5}, rl.Green) // Rounds Down
// Draw Line Functions are not zero indexed (round down), and don't include the starting pixel (because they draw from a )
rl.DrawLineV(rl.Vector2{X: 100.0, Y: 100.}, rl.Vector2{X: 110, Y: 100}, rl.Black)
rl.DrawLine(100, 110, 110, 110, rl.Black)
rl.DrawLine(110, 120, 100, 120, rl.Black)
// rl.DrawLine(0, 0, 100, 0, rl.Black)
// rl.DrawLine(0, 1, 100, 1, rl.Orange)
// rl.DrawLine(1, 1, 100, 1, rl.Black)
// rl.DrawLine(1, 1, 1, 1, rl.Black)
// rl.DrawLineV(p1, p2, rl.Black)
// rl.DrawLineV(p2, p3, rl.Red)
// rl.DrawLineV(p3, p4, rl.Blue)
// rl.DrawLineV(p4, p1, rl.Orange)
// */ /*
}
func drawPixelsOnDesktop() {
// Vector rounding behaves differently for X and Y: X Rounds Down, Y Rounds Up
rl.DrawPixel(200, 200, rl.Black)
rl.DrawPixel(210, 200, rl.Black)
rl.DrawPixel(200, 210, rl.Black)
rl.DrawPixel(210, 210, rl.Black)
rl.DrawPixelV(rl.Vector2{X: 200.4, Y: 200.4}, rl.Green) // (200, 200)
rl.DrawPixelV(rl.Vector2{X: 209.6, Y: 199.6}, rl.Green) // (210, 200)
rl.DrawPixelV(rl.Vector2{X: 200.5, Y: 210.5}, rl.Green) // (200, 211) :- X Rounds Down, Y Rounds Up
rl.DrawPixelV(rl.Vector2{X: 209.5, Y: 209.5}, rl.Green) // (209, 211) :- X Rounds Down, Y Rounds Up (even with the same float value!! WTF is that?!)
}
func drawLinesOnDesktop() {
// Here, X behaves as zero-indexed, Y behaves as one-indexed
rl.DrawLine(100, 50, 100, 200, rl.Green) // Pixels: ( 99, 50) - ( 99, 199)
rl.DrawLine(110, 200, 110, 50, rl.Green) // Pixels: (109, 50) - (109, 199)
// Draw Pixel Functions are Zero-Indexed
rl.DrawPixel(99, 50, rl.Orange) // First Pixel (Line 1)
rl.DrawPixel(109, 51, rl.Orange) // Second Pixel (Line 2)
rl.DrawPixel(99, 199, rl.Orange) // Last Pixel (Line 1)
rl.DrawPixel(109, 198, rl.Orange) // Second to Last Pixel (Line 2)
rl.DrawPixel(100-1, 100, rl.Orange) // ( 99, 100)
rl.DrawPixel(110-1, 100, rl.Orange) // (109, 100)
rl.DrawPixel(100-1, 110, rl.Orange) // ( 99, 110)
rl.DrawPixel(110-1, 110, rl.Orange) // (109, 110)
rl.DrawPixel(100-1, 120, rl.Orange) // ( 99, 120)
rl.DrawPixel(110-1, 120, rl.Orange) // (109, 120)
rl.DrawLineV(rl.Vector2{X: 100., Y: 100.}, rl.Vector2{X: 110, Y: 100}, rl.Black) // Pixels: (100,100) - (109, 100)
rl.DrawLine(100, 110, 110, 110, rl.Black) // Pixels: (100,110) - (109, 110)
rl.DrawLine(110, 120, 100, 120, rl.Black) // Pixels: (100,120) - (109, 120)
}
*/