I have never done trig in school so Sin and Cos are new to me. While learning I came upon a tutorial in another programming language and updated the syntax but it is not working. Instead of drawing a circle it draws what looks like a small lowercase R.
When looking at the console output the program produces you can see the X and Y drawing location hardly ever changes in BM even though it's a direct copy of the tutorial code.
Tutorial Code:
void draw_circle ()
{
int x, y;
int length = 50;
float angle = 0.0;
float angle_stepsize = 0.1;
// go through all angles from 0 to 2 * PI radians
while (angle < 2 * PI)
{
// calculate x, y from a vector with known length and angle
x = length * cos (angle);
y = length * sin (angle);
putpixel (screen,
x + SCREEN_W / 2, y + SCREEN_H / 2,
makecol (255, 255, 255));
angle += angle_stepsize;
}
}
My Code:
SuperStrict
Framework BRL.Blitz
Import BRL.StandardIO
Import BRL.System
Import BRL.Graphics
Import BRL.Max2D
Import BRL.GLMax2D
Import BRL.PolledInput
SetGraphicsDriver (GLMax2DDriver())
Graphics (1366, 768, 32, 0)
HideMouse()
SetColor (255,255,255)
Repeat
Cls()
FPS.DrawCircle()
FPS.DrawFPS()
Flip()
Until KeyHit(KEY_ESCAPE)
'FPS code from BM website
Type FPS
Global Counter : Int
Global Time : Int
Global TFPS : Int
Function Calc : Int()
Counter = Counter + 1
If Time < MilliSecs()
TFPS = Counter ' <-Frames/Sec
Time = MilliSecs() + 1000 'Update
Counter = 0
EndIf
Return TFPS
EndFunction
Function DrawFPS()
DrawText "FPS = " + FPS.Calc(), 0, 0
EndFunction
'For some reason this code will not draw to screen when inside loop. Put here temp.
Function DrawCircle()
Local x:Int
Local y:Int
Local length:Int = 50
Local angle:Float = 0.0
Local angle_stepsize:Float = 0.1
While (angle < 2 * Pi)
x = length * Cos(angle)
y = length * Sin(angle)
Print ("" + x)
Print ("" + y)
Plot (x + (1366 / 2) , y + (768 / 2))
angle = angle + angle_stepsize
EndWhile
EndFunction
EndType
|