-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshape.bah
85 lines (70 loc) · 2.03 KB
/
shape.bah
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
/////////////////////////////////////////////////////////////
// Shapes demo using OpenGL and GLUT in Bah. //
// To compile, use 'bah ./shape.bah -d'. //
// //
// © Aloïs Laurent Boë //
/////////////////////////////////////////////////////////////
#import "iostream.bah"
#import "../vbah.bah"
win = new window
tex rgb
//shape defined by the user
struct userShape {
//array containing every points of the shape
shape: []float
//the texture of the shape
tex: rgb
//used for drawing the shape
draw() {
drawShape(this.shape, this.tex)
}
//used for drawing the points
drawPoints() {
i=0; for i < len(this.shape) {
drawCircle(vec(this.shape[i], this.shape[i+1]), 0.02, rgb(1.0, 0.0, 0.0))
i += 2
}
}
}
shape userShape
display() {
//Defines triangles point
triangle = []float{
-0.5, 0.0, //left point
0.0, 0.5, //top point
0.5, 0.0 //right point
}
//draws the triangle
drawShape(triangle, tex)
//draws the user defined shape
shape.draw()
//draws the every points of the shape
shape.drawPoints()
}
init() {
//Note: texture from: https://www.vecteezy.com/free-vector/lines
tex = rgbTexture("./assets/tex.bmp", 1920, 1229)
shape = userShape{}
shape.tex = tex
}
//when the user clicks the window
click(btn int, pressed bool, x int, y int) {
//if it is a click and not a click release
if pressed == true {
//translate the window coordinates (pixels) to object coordinates
f = vec(<float>x, <float>y)
pixelsToCoords(&f)
//adds the coordinates to the array
shape.shape[len(shape.shape)] = f.x
shape.shape[len(shape.shape)] = f.y
}
}
main(args []str) int {
//launching the window
win = window(600, 600, "Shape")
win.display = display
win.init = init
win.click = click
win.launch()
return 0
}