Why is this not working?

BlitzMax Forums/BlitzMax Beginners Area/Why is this not working?

Jaquio1319(Posted 2011) [#1]
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



Jesse(Posted 2011) [#2]
BMax doesn't do radians. change this:
while (angle < 2*pi)

to
 
While (angle < 360.0)


Last edited 2011

Last edited 2011


Jaquio1319(Posted 2011) [#3]
Thank you Jesse. Much Help.


TomToad(Posted 2011) [#4]
Also, change the angle_stepsize to 1. the drawing will be 10 times faster.


Jesse(Posted 2011) [#5]
or better yet, change this line:
		Local angle_stepsize:Float = 0.1

to this:
		Local angle_stepsize:Float = 1.0/(Pi/180.0 * length)


for a more accurate and less wasteful step.

Last edited 2011