- This wiki is out of date, use the continuation of this wiki instead
Tutorial:Cosine
From FenixWiki
(Difference between revisions)
| Revision as of 23:21, 29 May 2007 (edit) Sandman (Talk | contribs) ← Previous diff |
Revision as of 23:22, 29 May 2007 (edit) (undo) Sandman (Talk | contribs) Next diff → |
||
| Line 59: | Line 59: | ||
| </pre> | </pre> | ||
| Used in example: [[set_fps]](), [[new_map]](), [[map_clear]](), [[rand]](), [[key]](), [[let_me_alone]](), [[cos]](), [[sin]](), [[timer]], [[x]], [[y]] | 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:<br> | ||
| + | http://wwwhome.cs.utwente.nl/~bergfi/fenix/wiki/cosine.PNG | ||
Revision as of 23:22, 29 May 2007
Some sine and cosine program. Check it out. More of example code, but useful anyway.
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:
