double velocity;
double distance;
- distance = radius * get_random_double();
+ distance = radius * pow(get_random_double(), 2);
velocity = sqrt(total_mass / radius);
velocity *= pow(distance / radius, 0.2);
double sum = 0;
struct planet *new_planet;
- for (i = 1; i < num; i++) {
+ setup_planet(p,
+ total_mass / num * 2 * get_random_double(),
+ total_mass,
+ radius);
+
+ for (i = 0; i < num; i++) {
new_planet = malloc(sizeof(*new_planet));
init_planet(new_planet);
list_add(&new_planet->list, &p->list);
sum += new_planet->mass;
}
-
- printf("Requested mass: %f, got %f\n", total_mass, sum);
}
void draw_planet(SDL_Surface *screen, struct planet *p,
struct vector pos;
float radius = p->radius * cam->zoom;
float r2 = radius * radius;
- int x, x_start, y, x_end, y_end;
+ int x, x_start, y, x_end;
vector_sub(&p->pos, &cam->pos, &pos);
vector_scale(&pos, cam->zoom, &pos);
y = MAX(pos.y - radius, 0);
- if (radius * 2 <= 1 ) {
+ if (radius * 2 <= 1) {
if (pos.x >= 0 && pos.x < screen->w &&
pos.y >= 0 && pos.y < screen->h)
putpixel(screen, (int)pos.x, (int)pos.y,