I downloaded this code from the net that draws a circle using the sine and cosine functions, but I can't figure out what I'm doing wrong in Max.
Code I converted to Max:
And here is the code written in C using Allegro:
Code I converted to Max:
Global SCREEN_W:Int = 800 Global SCREEN_H:Int = 600 Graphics SCREEN_W, SCREEN_H, 0 Local x:Int, y:Int Local length:Int = 50 Local angle:Float = 0.0 Local angle_stepsize:Float = 0.1; SetColor 255, 255, 255 Cls '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) Plot((x + (SCREEN_W / 2)), (y + (SCREEN_H / 2))) angle:+angle_stepsize Wend Flip WaitKey
And here is the code written in C using Allegro:
/* CIRCLE 1 Written by Amarillion (amarillion@...) This program demonstrates the use of sin and cos with floats. All it does is draw a circle on the screen. */ #include <allegro.h> #include <math.h> // Make sure PI is defined. // MinGW has some problems with this. #ifndef PI #define PI 3.1415927 #endif 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; } } int main () { // initialize Allegro if (allegro_init () < 0) { allegro_message ("Error: Could not initialize Allegro"); return -1; } // initialize gfx mode if (set_gfx_mode (GFX_AUTODETECT, 320, 200, 0, 0) < 0) { allegro_message ("Error: Could not set graphics mode"); return -1; } // initialize keyboard install_keyboard (); clear_keybuf (); // call the example function draw_circle (); // wait for a user key-press readkey (); // exit Allegro allegro_exit (); return 0; } END_OF_MAIN ();