program66
program66
h>
#ifdef WITH_CAIRO
#include <cairo.h>
#else
#include <SDL/sge.h>
#endif
#include <cairo.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#ifdef WITH_CAIRO
#define PI 3.1415926535
#endif
double rand_fl(){
return (double)rand() / (double)RAND_MAX;
}
cairo_set_line_width(ct, 1);
cairo_set_source_rgba(ct, 0,0,0,1);
cairo_move_to(ct, (int)offsetx, (int)offsety);
cairo_line_to(ct, (int)(offsetx + directionx * size), (int)(offsety + directiony
* size));
cairo_stroke(ct);
#else
sge_AALine(surface,
(int)offsetx, (int)offsety,
(int)(offsetx + directionx * size), (int)(offsety + directiony * size),
SDL_MapRGB(surface->format, 0, 0, 0));
#endif
if (depth > 0){
// draw left branch
draw_tree(surface,
offsetx + directionx * size,
offsety + directiony * size,
directionx * cos(rotation) + directiony * sin(rotation),
directionx * -sin(rotation) + directiony * cos(rotation),
size * rand_fl() / SCALE + size * (SCALE - 1) / SCALE,
rotation * ROTATION_SCALE,
depth - 1);
// draw right branch
draw_tree(surface,
offsetx + directionx * size,
offsety + directiony * size,
directionx * cos(-rotation) + directiony * sin(-rotation),
directionx * -sin(-rotation) + directiony * cos(-rotation),
size * rand_fl() / SCALE + size * (SCALE - 1) / SCALE,
rotation * ROTATION_SCALE,
depth - 1);
}
}
int main()
SDL_Surface * screen;
SDL_Event evt;
SDL_Init(SDL_INIT_VIDEO);
srand((unsigned)time(NULL));
render(screen);
while(1{
if (SDL_PollEvent(&evt)){
if(evt.type == SDL_QUIT) break;
}
SDL_Delay(1);
}
SDL_Quit(;
return 0;
}