Merge branch 'cairo' into faces
This commit is contained in:
commit
32cd25bd56
27
balls.c
27
balls.c
@ -39,6 +39,8 @@ unsigned int n_balls = 50;
|
|||||||
static double g_y = 20;
|
static double g_y = 20;
|
||||||
static double g_x = 0;
|
static double g_x = 0;
|
||||||
|
|
||||||
|
static double clear_alpha = 1.0;
|
||||||
|
|
||||||
void random_velocity(struct ball * p) {
|
void random_velocity(struct ball * p) {
|
||||||
double r2;
|
double r2;
|
||||||
do {
|
do {
|
||||||
@ -142,7 +144,11 @@ const char * face_filename = 0;
|
|||||||
cairo_surface_t * face_surface = 0;
|
cairo_surface_t * face_surface = 0;
|
||||||
int face_x_offset, face_y_offset;
|
int face_x_offset, face_y_offset;
|
||||||
|
|
||||||
|
static int gravity_vector_countdown = 0;
|
||||||
|
static int gravity_vector_init = 300;
|
||||||
|
|
||||||
static void draw_gravity_vector() {
|
static void draw_gravity_vector() {
|
||||||
|
if (gravity_vector_countdown != 0) {
|
||||||
cairo_new_path(cr);
|
cairo_new_path(cr);
|
||||||
cairo_move_to(cr, width/2, height/2);
|
cairo_move_to(cr, width/2, height/2);
|
||||||
cairo_line_to(cr, width/2 + g_x, height/2 + g_y);
|
cairo_line_to(cr, width/2 + g_x, height/2 + g_y);
|
||||||
@ -151,6 +157,9 @@ static void draw_gravity_vector() {
|
|||||||
cairo_stroke(cr);
|
cairo_stroke(cr);
|
||||||
cairo_arc(cr, width/2 + g_x, height/2 + g_y, 3, 0, 2*M_PI);
|
cairo_arc(cr, width/2 + g_x, height/2 + g_y, 3, 0, 2*M_PI);
|
||||||
cairo_fill(cr);
|
cairo_fill(cr);
|
||||||
|
if (gravity_vector_countdown > 0)
|
||||||
|
--gravity_vector_countdown;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void draw_balls_onto_window () {
|
static void draw_balls_onto_window () {
|
||||||
@ -158,7 +167,7 @@ static void draw_balls_onto_window () {
|
|||||||
cr = gdk_cairo_create(window->window);
|
cr = gdk_cairo_create(window->window);
|
||||||
|
|
||||||
/* clear pixmap */
|
/* clear pixmap */
|
||||||
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);
|
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, clear_alpha);
|
||||||
cairo_paint(cr);
|
cairo_paint(cr);
|
||||||
|
|
||||||
draw_gravity_vector();
|
draw_gravity_vector();
|
||||||
@ -212,20 +221,23 @@ static gint keyboard_input (GtkWidget *widget, GdkEventKey *event) {
|
|||||||
switch(event->keyval) {
|
switch(event->keyval) {
|
||||||
case GDK_KEY_Up:
|
case GDK_KEY_Up:
|
||||||
g_y -= 10;
|
g_y -= 10;
|
||||||
|
gravity_vector_countdown = gravity_vector_init;
|
||||||
break;
|
break;
|
||||||
case GDK_KEY_Down:
|
case GDK_KEY_Down:
|
||||||
g_y += 10;
|
g_y += 10;
|
||||||
|
gravity_vector_countdown = gravity_vector_init;
|
||||||
break;
|
break;
|
||||||
case GDK_KEY_Left:
|
case GDK_KEY_Left:
|
||||||
g_x -= 10;
|
g_x -= 10;
|
||||||
|
gravity_vector_countdown = gravity_vector_init;
|
||||||
break;
|
break;
|
||||||
case GDK_KEY_Right:
|
case GDK_KEY_Right:
|
||||||
g_x += 10;
|
g_x += 10;
|
||||||
|
gravity_vector_countdown = gravity_vector_init;
|
||||||
break;
|
break;
|
||||||
case GDK_KEY_F:
|
case GDK_KEY_G:
|
||||||
case GDK_KEY_f:
|
case GDK_KEY_g:
|
||||||
g_x = rand() % 201 - 100;
|
gravity_vector_countdown = gravity_vector_init;
|
||||||
g_y = rand() % 201 - 100;
|
|
||||||
break;
|
break;
|
||||||
case GDK_KEY_Q:
|
case GDK_KEY_Q:
|
||||||
case GDK_KEY_q:
|
case GDK_KEY_q:
|
||||||
@ -259,7 +271,8 @@ void print_usage (const char * progname) {
|
|||||||
"\tfy=<y-force>\n"
|
"\tfy=<y-force>\n"
|
||||||
"\tradius=<min-radius>-<max-radius>\n"
|
"\tradius=<min-radius>-<max-radius>\n"
|
||||||
"\tv=<min-velocity>-<max-velocity>\n"
|
"\tv=<min-velocity>-<max-velocity>\n"
|
||||||
"\tdelta=<frame-delta-time>\n",
|
"\tdelta=<frame-delta-time>\n"
|
||||||
|
"\tclear=<clear-alpha>\n",
|
||||||
progname);
|
progname);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,6 +334,8 @@ int main (int argc, const char *argv[]) {
|
|||||||
define_face_surface(argv[i] + 5);
|
define_face_surface(argv[i] + 5);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (sscanf(argv[i], "clear=%lf", &clear_alpha) == 1)
|
||||||
|
continue;
|
||||||
print_usage(argv[0]);
|
print_usage(argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user