I want to draw a mathematical figure, a so-called asteroid:
This is the old basic code:
[code]Rem ASTEROID
Screen 12:CLS:PI=4ATN(1)
Window(-1.6,-1.2)-(1.6,1.2)
Locate 1,1: Input"Amount of lines between 32 and 128 = ",N
N=2INT(N/2): IF N<32 THEN N=64
Locate 1,1: Print Space$(80)
For I=0 To N-1
T=2PiI/N
Line(Cos(T),0)-(0,Sin(t))
next I
End[/code]
This code is in the paint event of a Canvas:
[code]Dim Pi as Double =4*ATan(1)
dim A as Integer = 64
dim N as Integer
dim T as Integer
N=2*Round(A/2)
If N<32 then
N = 64
end if
g.ForeColor = &c0000FF00
for I as Integer = 0 to N-1
T = 2PiI/N
g.DrawLine(Cos(T),0,0,Sin(T))
next[/code]
I omitted the input and took a fixed value, but I don’t see anything.
[Edit] something is drawn, but too small.
I see something, a dot. That’s because the values of Sin(T) and Cos(T) alternate between 0 and 1.
Change your code like this and trace it yourself. That’s the best way to identify problems like this.
Dim Pi as Double =4*REALbasic.ATan(1)
dim A as Integer = 64
dim N as Integer
dim T as Integer
N=2*Round(A/2)
If N<32 then
N = 64
end if
g.ForeColor = &c0000FF00
for I as Integer = 0 to N-1
T = 2*Pi*I/N
dim tCos as integer = REALbasic.Cos( T )
dim tSin as integer = REALbasic.Sin( T )
g.DrawLine(tCos,0,0,tSin)
next
Oh Kem, why do you have to make me look bad by trying to teach the OP something? LOL
(by the way Alexander, I did just about what Kem did to find it but I used "System.DebugLog str(sin(T)) + “, " + str(cos(T))” to figure out what was going on.)