PDA

View Full Version : Enhanced Trigonometry



peter
18-10-2012, 13:49
Hi,


Uses "ui","math"


DWord hdc,hwin
hwin=Canvas_Window("Newton",1,1,300,310)
Canvas_Attach(hwin,0,%TRUE)
Canvas_Font("verdana",16,%CANVAS_FONTSTYLE_BOLD)


Single yacc, yvel, xvel, x, y, r
yacc=.98: yvel=-10: xvel=10: x=20: y=100: r=20


While IsWindow(hwin)
Canvas_Clear(Rgb(0,0,255))
yvel=yvel+yacc
y=y+yvel
x=x+xvel
If y >289 Then
yvel = -0.9*yvel
y=289
xvel=xvel*0.9
End If
If x >285 Then
xvel = -xvel
x =285
End If
If x<10 Then
xvel = -xvel
x = 10
End If
Canvas_Circle(x,y,r,0,&hF9CAFD)
If xvel*xvel <0.0001 Then Exit While
SetText(40,8,"Newton Let's Go!",Rgb(255,255,255),&hFF0000)
Canvas_Redraw
Sleep 10
Wend


SetText(80,100,"HIT ESCAPE",Rgb(255,255,255),&hFF0000)
Canvas_Redraw


While IsWindow(hwin)
If GetAsyncKeyState(27) Then Exit While
Wend
Canvas_Window End


Sub SetText(x,y As Long, txt As String, xkol,ykol As Long)
Canvas_Color(xkol,ykol)
Canvas_SetPos(x,y)
Canvas_Print(txt)
End Sub

peter
18-10-2012, 13:50
Uses "ui","math"


DWord hdc,hwin
hwin=Canvas_Window("Stars",1,1,640,480)
Canvas_Attach(hwin,0,%TRUE)
Canvas_Font("comic",16,%CANVAS_FONTSTYLE_BOLD)


Long i, sx, sy, colour, anz, speed, xScreen, yScreen
Dim sternx(3000) As Long
Dim sterny(3000) As Long
Dim sternz(3000) As Long
anz=3000: speed=2: xScreen=640: yScreen=480


StarInit()
While IsWindow(hwin)
Canvas_Clear(Rgb(8,8,8))
StarUpdate()
Canvas_Redraw
If GetAsyncKeyState(27) Then Exit While
Wend
Canvas_Window End


Sub SetText(x,y As Long, txt As String, xkol,ykol As Long)
Canvas_Color(xkol,ykol)
Canvas_SetPos(x,y)
Canvas_Print(txt)
End Sub


Sub StarInit()
For i=1 To anz
sternx(i)=Rnd(-(xscreen/2), (xscreen/2))*128
sterny(i)=Rnd(-(yscreen/2), (yscreen/2))*128
sternz(i)=Rnd(speed,255)
Next
End Sub


Sub StarUpdate()
For i=1 To anz
sternz(i)=sternz(i)-speed
If sternz(i) <= speed Then sternz(i)=255
sx = (sternx(i) / sternz(i))+(xscreen / 2)
sy = (sterny(i) / sternz(i))+(yscreen / 2)
colour=(300-sternz(i))*.8
'Canvas_Color(Rgb(colour,colour,colour))
'Canvas_SetPixel(sx,sy)
Setpoint(sx,sy,4,colour,colour,colour)
Next
End Sub

Sub SetPoint(x,y,po,r,g,b As Long)
Canvas_Box(x,y,po+x,po+y,8,-1,Rgb(r,g,b))
End Sub