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