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
|
rem Rotating Triangle Example
rem
rem Copyright (C) 2001 P.B. IJdens
rem Released under the GNU Public License (GPL)
main()
sub main()
init_scene()
open_grwin()
while ( 1 = 1 )
draw_scene()
show_scene()
rotate_scene()
wend
end sub
sub open_grwin()
open window 640, 512
dispduf = 0
setdispbuf dispbuf
setdrawbuf 1 - dispbuf
end sub
sub show_scene()
dispbuf = 1 - dispbuf
setdispbuf dispbuf
setdrawbuf 1 - dispbuf
end sub
sub init_scene()
dim coords(3,2,2)
dim centre(2)
for obj = 1 to 3 step 1
for corner = 1 to 2 step 1
for coord = 1 to 2 step 1
read coords(obj, corner, coord)
next coord
next corner
next obj
centre(1) = 313
centre(2) = 259
end sub
sub rotate_scene()
for obj = 1 to 3 step 1
for corner = 1 to 2 step 1
rx = coords(obj, corner, 1) - centre(1)
ry = coords(obj, corner, 2) - centre(2)
alpha = pi / 100
coords(obj, corner, 1) = (rx * cos(alpha) - ry * sin(alpha)) + centre(1)
coords(obj, corner, 2) = (rx * sin(alpha) + ry * cos(alpha)) + centre(2)
next corner
next obj
end sub
sub draw_scene()
setrgb 0, 0, 0, 77
clear window
setrgb 1, 255, 0, 0
setrgb 2, 0, 255, 0
setrgb 3, 0, 0, 255
for obj = 1 to 3 step 1
gtriangle coords(obj, 1, 1), coords(obj, 1, 2) to coords(obj, 2, 1), coords(obj, 2, 2) to centre(1), centre(2)
next obj
setrgb 1, 0, 0, 77
filled circle centre(1), centre(2), 60
setrgb 1, 0, 0, 255
filled circle centre(1), centre(2), 40
setrgb 1, 255, 255, 255
text centre(1), centre(2), "YaBasic", "cb"
text centre(1), centre(2), "Rocks", "ct"
end sub
data 150, 60, 371, 30
data 550, 320, 448, 56
data 400, 480, 100, 400
|