PDA

View Full Version : Trigonometry)



peter
17-10-2012, 21:23
Hi,

You remember the old days at school? (trigonometry)


Uses "ui","math"


DWord hdc,hwin
hwin=Canvas_Window("Sinus Wave",1,1,640,240)
Canvas_Attach(hwin,0,%TRUE)
Canvas_Font("comic",16,%CANVAS_FONTSTYLE_BOLD)


Long i,width
Single px,py,px2,py2,angle,angle2,radius,frequency,frequency2,x,x2
radius=100
frequency=2
frequency2=2
width=640


While IsWindow(hwin)
Canvas_Clear(&h808080)
Canvas_Circle(width/8,75,radius/2,&hFFFFFF)
px= width/8 + Cos(DegToRad(angle))*(radius/2)
py= 75+Sin(DegToRad(angle))*(radius/2)
Canvas_Circle(px,py,6,&h00FF00)
Canvas_Line( (width/8,75),(px,py),0)
angle2=0
For i=0 To width
px2= width/8 + Cos(DegToRad(angle2))*(radius/2)
py2= 75 + Sin(DegToRad(angle2))*(radius/2)
Canvas_Color(0)
Canvas_SetPixel(width/8+radius/2+i,py2)
angle2 -= frequency2
Next
Canvas_Circle(width/8+radius/2+x,py,0)
angle -= frequency
x +=1
If x>= width-60 Then
x=0
angle=0
End If
Canvas_Line( (px,py),(width/8+radius/2+x,py),0)
SetText(0, 185,"y = sin x",&hFFFFFF,&h808080)
SetText(200,185,"px= " + px,&hFFFFFF,&h808080)
SetText(420,185,"py= " + py,&hFFFFFF,&h808080)
Canvas_Redraw
If GetAsyncKeyState(27) Then Exit While
sleep 10
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
17-10-2012, 21:24
Uses "ui","math"


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


Single a,b,x2,y2,angle,angle_difference
Long counter,color_value,difference,length,x,y
color_value=7:difference=2:length=500:x=50:y=550:angle=1:angle_difference=0.8
y2=y-length
y=y2
length=length-difference


Canvas_Clear(&hC8C8F8)
While counter <180
a =Sin(DegToRad(angle))*length
b =Cos(DegToRad(angle))*length
x2=x+b
y2=y+a
Canvas_Line((x,y),(x2,y2),Rgb(color_value,color_value,color_value))
angle=angle+angle_difference
length=length-difference
a= Sin(DegToRad(angle))*length
b= Cos(DegToRad(angle))*length
x= x2-a
y= y2+b
Canvas_Line((x2,y2),(x,y),Rgb(color_value,color_value,color_value))
angle=angle+angle_difference
length=length-difference
a= Sin(DegToRad(angle))*length
b= Cos(DegToRad(angle))*length
x2=x-b
y2=y-a
Canvas_Line((x,y),(x2,y2),Rgb(color_value,color_value,color_value))
angle=angle+angle_difference
length=length-difference
a=Sin(DegToRad(angle))*length
b=Cos(DegToRad(angle))*length
x=x2+a
y=y2-b
Canvas_Line((x2,y2),(x,y),Rgb(color_value,color_value,color_value))
length=length-difference
angle =angle +angle_difference
counter +=1
color_value += Rnd(4,8)
Wend
Canvas_Redraw
While IsWindow(hwin)
If GetAsyncKeyState(27) Then Exit While
Sleep 10
Wend
Canvas_Window End