- This wiki is out of date, use the continuation of this wiki instead
Tutorial:Cosine
From FenixWiki
(Difference between revisions)
Revision as of 22:44, 6 August 2007 (edit) Sandman (Talk | contribs) m ← Previous diff |
Current revision (00:15, 9 August 2007) (edit) (undo) Sandman (Talk | contribs) m (Cosine moved to Tutorial:Cosine: tutorial namespace) |
Current revision
Some sine and cosine program. Check it out. More of example code, but useful anyway.
Note that this is code for Fenix versions 0.93 and up. Should the code work for other versions as well, be so kind to note this here.
[edit] Example code
Program cosine; Const seconds = 2.3; ball_width = 20; ball_height = 20; screen_width = 320; screen_height = 200; screen_depth = 8; screen_fps = 60; cos_factor = 2000; sin_factor = 4000; timer_spawn = 0; timer_ball = 1; Begin // make the movement a bit more smooth set_fps(screen_fps,0); // spawn a ball process every <seconds> seconds with random colors. timer[timer_spawn]= seconds*100; Repeat if(timer[timer_spawn]>=seconds*100) timer[timer_spawn]-=seconds*100; x = new_map(ball_width,ball_height,screen_depth); map_clear(0,x,rgb(rand(0,255),rand(0,255),rand(0,255))); ball(x); end frame; Until(key(_esc)) // kill all other remaining processes and exit let_me_alone(); exit(); End Process ball(graph) Private int start_time; Begin // remember starting time start_time = timer[timer_ball]; // position the ball according to the passed time (timer[timer_ball]) Loop x = screen_width /2 + cos((timer[timer_ball]-start_time)*cos_factor) * (screen_width /2-ball_width /2); y = screen_height/2 + sin((timer[timer_ball]-start_time)*sin_factor) * (screen_height/2-ball_height/2); frame; End End
Used in example: set_fps(), new_map(), map_clear(), rand(), key(), let_me_alone(), cos(), sin(), timer, x, y
This will result in something like:
Or with seconds=0.25; cos_factor=6000;sin_factor=2000 something like this:
Try fiddling around with the parameters yourself and she what you can conjure.