Uses "tbgl"
Dim hwnd,hfnt As DWord
hwnd=TBGL_CreateWindowEx("Circles",800,600,32, %TBGL_WS_WINDOWED | %TBGL_WS_DONTSIZE | %TBGL_WS_CLOSEBOX)
TBGL_ShowWindow
TBGL_RenderMatrix2D (0,0,800,600)
TBGL_BackColor (0,0,0)
hfnt=TBGL_FontHandle("arial",24)
TBGL_BuildFont(hfnt)
TBGL_SetActiveFont(1)
Randomize()
Dim cx(120),cy(120),cd(120) As Single
Dim c1(120),c2(120),c3(120) As Byte
Dim c As Long
For c=1 To 100
cx(c)=400
cy(c)=300
cd(c)=Rnd(1,8)
c1(c)=Rgb(Rnd(64,255),Rnd(64,255),Rnd(32,255))
c2(c)=Rgb(Rnd(64,255),Rnd(64,255),Rnd(32,255))
c3(c)=Rgb(Rnd(64,255),Rnd(64,255),Rnd(32,255))
Next
While TBGL_IsWindow(hWnd)
TBGL_ClearFrame
TBGL_Color(249,202,253)
TBGL_PrintFont("Circles",340,542)
For c=1 To 100
If cd(c)=1 Then
cx(c)=cx(c)+1
bound()
ElseIf cd(c)=2 Then
cx(c)=cx(c)-1
bound()
ElseIf cd(c)=3 Then
cy(c)=cy(c)-1
bound()
ElseIf cd(c)=4 Then
cy(c)=cy(c)+1
bound()
ElseIf cd(c)=5 Then
cy(c)=cy(c)-1
cx(c)=cx(c)-1
bound()
ElseIf cd(c)=6 Then
cy(c)=cy(c)-1
cx(c)=cx(c)+1
bound()
ElseIf cd(c)=7 Then
cy(c)=cy(c)+1
cx(c)=cx(c)-1
bound()
ElseIf cd(c)=8 Then
cy(c)=cy(c)+1
cx(c)=cx(c)+1
bound()
End If
Next
circles()
TBGL_DrawFrame
If key(27) Then Exit While
'Sleep (10)
Wend
TBGL_DestroyWindow
Sub circles()
For c=1 To 100
Circle1(cx(c),cy(c),40,c1(c),c2(c),c3(c))
'FillCircle(cx(c),cy(c),40,c1(c),c2(c),c3(c))
Next
End Sub
Sub bound()
Dim i As DWord
For i=1 To 100
If cx(i) <=40 Then
cd(i) = Rnd(1,8)
cx(i) =40
End If
If cx(i) >=760 Then
cd(i) = Rnd(1,8)
cx(i) =760
End If
If cy(i) >=560 Then
cd(i) = Rnd(1,8)
cy(i) =560
End If
If cy(i) <=40 Then
cd(i) = Rnd(1,8)
cy(i) =40
End If
Next
End Sub
Sub Circle1(x0,y0 As Single,ra,r,g,b As Byte)
Local f,x,y,ddF_x,ddF_y As Single
f=1-ra : y=ra
ddF_y =-2 * ra
TBGL_Color(r,g,b)
TBGL_Point(x0,y0+ra)
TBGL_Point(x0,y0-ra)
TBGL_Point(x0+ra,y0)
TBGL_Point(x0-ra,y0)
While x < y
If f >= 0 Then
y=y-1
ddF_y=ddf_y+2
f=f+ddF_y
End If
x=x+1
ddF_x=ddf_x+2
f=f+ddF_x+1
TBGL_Point(x0+x,y0+y)
TBGL_Point(x0-x,y0+y)
TBGL_Point(x0+x,y0-y)
TBGL_Point(x0-x,y0-y)
TBGL_Point(x0+y,y0+x)
TBGL_Point(x0-y,y0+x)
TBGL_Point(x0+y,y0-x)
TBGL_Point(x0-y,y0-x)
Wend
End Sub
Sub FillCircle(x,y,ra As Single,r,g,b As Byte)
TBGL_Color(r,g,b)
TBGL_NGon(x,y,ra,ra)
End Sub
Function Key(xkey As Word) As Word
Return TBGL_GetAsyncKeyState(xkey)
End Function
Bookmarks