Skip to content
Snippets Groups Projects
Commit 9fa3dcb1 authored by Peter Gerwinski's avatar Peter Gerwinski
Browse files

Beispiele 23.11.2023

parent d57c07b6
No related branches found
No related tags found
No related merge requests found
Showing
with 723 additions and 0 deletions
#include <stdio.h>
#include <stdint.h>
#include <string.h>
int main (void)
{
uint8_t a;
uint16_t b;
uint8_t c;
memset (&a, 0xff, 4);
printf ("a = %d\nb = %d\nc = %d\n", a, b, c);
return 0;
}
#include <stdio.h>
#include <stdint.h>
#include <string.h>
uint8_t a;
uint16_t b;
uint8_t c;
int main (void)
{
memset (&a, 0xff, 4);
printf ("a = %d\nb = %d\nc = %d\n", a, b, c);
return 0;
}
#include <stdio.h>
#include <stdint.h>
#include <string.h>
uint8_t a;
uint16_t b;
uint8_t c;
int main (void)
{
memset (&a, 0xff, 8);
printf ("a = %d\nb = %d\nc = %d\n", a, b, c);
return 0;
}
#include <stdio.h>
#include <stdint.h>
#include <string.h>
uint8_t a;
uint16_t b;
uint8_t c;
int main (void)
{
memset (&a, 0xff, 5);
printf ("a = %d\nb = %d\nc = %d\n", a, b, c);
return 0;
}
#include <stdio.h>
#include <stdint.h>
#include <string.h>
uint8_t a;
uint64_t b;
uint8_t c;
int main (void)
{
memset (&a, 0xff, 5);
printf ("a = %d\nb = %d\nc = %d\n", a, b, c);
return 0;
}
#include <stdio.h>
#include <stdint.h>
#include <string.h>
uint8_t a;
uint64_t b;
uint8_t c;
int main (void)
{
memset (&a, 0xff, 9);
printf ("a = %d\nb = %d\nc = %d\n", a, b, c);
return 0;
}
#include <stdio.h>
float f (float x)
{
return x * x;
}
float df_a (float x)
{
return 2.0 * x;
}
float df_n (float x)
{
float dx = 0.0000001;
float df = f (x + 0.5 * dx) - f (x - 0.5 * dx);
return df / dx;
}
int main (void)
{
for (float x = -3.0; x <= 3.0; x += 0.1)
printf ("%10f%10f%10f%10f\n", x, f (x), df_a (x), df_n (x));
return 0;
}
-3.000000 9.000000 -6.000000 0.000000
-2.900000 8.410001 -5.800000 0.000000
-2.800000 7.840001 -5.600000 0.000000
-2.700000 7.290001 -5.400001 0.000000
-2.600000 6.760002 -5.200001 0.000000
-2.500000 6.250002 -5.000001 0.000000
-2.400001 5.760003 -4.800001 0.000000
-2.300001 5.290003 -4.600001 0.000000
-2.200001 4.840003 -4.400002 0.000000
-2.100001 4.410004 -4.200002 0.000000
-2.000001 4.000004 -4.000002 0.000000
-1.900001 3.610003 -3.800002 0.000000
-1.800001 3.240003 -3.600002 0.000000
-1.700001 2.890003 -3.400002 0.000000
-1.600001 2.560003 -3.200002 0.000000
-1.500001 2.250003 -3.000002 0.000000
-1.400001 1.960002 -2.800002 0.000000
-1.300001 1.690002 -2.600002 0.000000
-1.200001 1.440002 -2.400002 0.000000
-1.100001 1.210002 -2.200001 0.000000
-1.000001 1.000001 -2.000001 0.000000
-0.900001 0.810001 -1.800001 -2.384186
-0.800001 0.640001 -1.600001 -1.788139
-0.700001 0.490001 -1.400001 -1.788139
-0.600001 0.360001 -1.200001 -1.490116
-0.500001 0.250001 -1.000001 -1.192093
-0.400001 0.160000 -0.800001 -1.043081
-0.300001 0.090000 -0.600001 -0.670552
-0.200001 0.040000 -0.400001 -0.372529
-0.100001 0.010000 -0.200001 -0.204891
-0.000001 0.000000 -0.000001 -0.000001
0.099999 0.010000 0.199999 0.214204
0.199999 0.040000 0.399999 0.372529
0.299999 0.090000 0.599999 0.745058
0.399999 0.160000 0.799999 0.894070
0.499999 0.249999 0.999999 1.192093
0.599999 0.359999 1.199999 1.192093
0.699999 0.489999 1.399999 1.788139
0.799999 0.639999 1.599999 1.788139
0.899999 0.809999 1.799999 2.384186
0.999999 0.999999 1.999999 2.384186
1.099999 1.209999 2.199999 0.000000
1.199999 1.439999 2.399999 0.000000
1.299999 1.689999 2.599999 0.000000
1.399999 1.959999 2.799999 0.000000
1.500000 2.249999 2.999999 0.000000
1.600000 2.559999 3.199999 0.000000
1.700000 2.889998 3.399999 0.000000
1.800000 3.239999 3.599999 0.000000
1.900000 3.609998 3.799999 0.000000
2.000000 3.999999 3.999999 0.000000
2.100000 4.409998 4.199999 0.000000
2.200000 4.839998 4.399999 0.000000
2.299999 5.289998 4.599999 0.000000
2.399999 5.759997 4.799999 0.000000
2.499999 6.249997 4.999999 0.000000
2.599999 6.759996 5.199998 0.000000
2.699999 7.289995 5.399998 0.000000
2.799999 7.839994 5.599998 0.000000
2.899999 8.409993 5.799998 0.000000
2.999999 8.999993 5.999998 0.000000
plot "deriv-01.dat" using 1:2 with lines title "f(x)", \
"deriv-01.dat" using 1:3 with lines title "df_a(x)", \
"deriv-01.dat" using 1:4 with lines lc "red" dashtype "-" title "df_n(x)"
pause -1
#include <stdio.h>
float f (float x)
{
return x * x * x;
}
float df_a (float x)
{
return 3.0 * x * x;
}
float df_n (float x)
{
float dx = 0.1;
float df = f (x + 0.5 * dx) - f (x - 0.5 * dx);
return df / dx;
}
int main (void)
{
for (float x = -3.0; x <= 3.0; x += 0.1)
printf ("%11f %11f %11f %11f\n", x, f (x), df_a (x), df_n (x));
return 0;
}
-3.000000 -27.000000 27.000000 27.002468
-2.900000 -24.389004 25.230001 25.232487
-2.800000 -21.952005 23.520002 23.522472
-2.700000 -19.683006 21.870005 21.872482
-2.600000 -17.576008 20.280006 20.282497
-2.500000 -15.625009 18.750008 18.752489
-2.400001 -13.824010 17.280008 17.282486
-2.300001 -12.167011 15.870009 15.872488
-2.200001 -10.648011 14.520010 14.522505
-2.100001 -9.261011 13.230011 13.232498
-2.000001 -8.000011 12.000011 12.002497
-1.900001 -6.859010 10.830010 10.832500
-1.800001 -5.832009 9.720010 9.722505
-1.700001 -4.913008 8.670009 8.672500
-1.600001 -4.096007 7.680008 7.682502
-1.500001 -3.375006 6.750008 6.752501
-1.400001 -2.744005 5.880007 5.882499
-1.300001 -2.197004 5.070006 5.072502
-1.200001 -1.728003 4.320005 4.322501
-1.100001 -1.331003 3.630005 3.632501
-1.000001 -1.000002 3.000004 3.002503
-0.900001 -0.729002 2.430004 2.432504
-0.800001 -0.512001 1.920003 1.922504
-0.700001 -0.343001 1.470003 1.472503
-0.600001 -0.216001 1.080002 1.082503
-0.500001 -0.125000 0.750002 0.752502
-0.400001 -0.064000 0.480001 0.482502
-0.300001 -0.027000 0.270001 0.272501
-0.200001 -0.008000 0.120001 0.122501
-0.100001 -0.001000 0.030000 0.032500
-0.000001 -0.000000 0.000000 0.002500
0.099999 0.001000 0.030000 0.032500
0.199999 0.008000 0.119999 0.122499
0.299999 0.027000 0.269999 0.272499
0.399999 0.064000 0.479998 0.482499
0.499999 0.125000 0.749998 0.752498
0.599999 0.215999 1.079998 1.082498
0.699999 0.342999 1.469997 1.472498
0.799999 0.511999 1.919997 1.922498
0.899999 0.728999 2.429997 2.432498
0.999999 0.999998 2.999997 3.002497
1.099999 1.330998 3.629996 3.632492
1.199999 1.727998 4.319996 4.322493
1.299999 2.196997 5.069996 5.072492
1.399999 2.743997 5.879996 5.882490
1.500000 3.374997 6.749996 6.752491
1.600000 4.095996 7.679996 7.682493
1.700000 4.912996 8.669995 8.672490
1.800000 5.831996 9.719995 9.722486
1.900000 6.858996 10.829996 10.832486
2.000000 7.999996 11.999996 12.002501
2.100000 9.260995 13.229996 13.232479
2.200000 10.647994 14.519995 14.522486
2.299999 12.166991 15.869993 15.872469
2.399999 13.823989 17.279991 17.282476
2.499999 15.624988 18.749989 18.752470
2.599999 17.575983 20.279987 20.282459
2.699999 19.682980 21.869986 21.872482
2.799999 21.951977 23.519983 23.522453
2.899999 24.388971 25.229980 25.232468
2.999999 26.999969 26.999979 27.002430
plot "deriv-02.dat" using 1:2 with lines title "f(x)", \
"deriv-02.dat" using 1:3 with lines title "df_a(x)", \
"deriv-02.dat" using 1:4 with lines lc "red" dashtype "-" title "df_n(x)"
pause -1
#include <gtk/gtk.h>
double x = 137;
double y = 255;
static void draw (GtkDrawingArea *drawing_area, cairo_t *c,
int width, int height, gpointer user_data)
{
GdkRGBA blue = { 0.0, 0.5, 1.0, 1.0 };
gdk_cairo_set_source_rgba (c, &blue);
cairo_arc (c, x, y, 10, 0, 2 * G_PI);
cairo_fill (c);
}
static void activate (GtkApplication *app, gpointer user_data)
{
GtkWidget *window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Hello");
GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
gtk_window_set_child (GTK_WINDOW (window), vbox);
GtkWidget *drawing_area = gtk_drawing_area_new ();
gtk_widget_set_size_request (drawing_area, 1024, 768);
gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (drawing_area), draw, NULL, NULL);
gtk_box_append (GTK_BOX (vbox), drawing_area);
GtkWidget *quit_button = gtk_button_new_with_label ("Quit");
g_signal_connect_swapped (quit_button, "clicked", G_CALLBACK (gtk_window_destroy), window);
gtk_box_append (GTK_BOX (vbox), quit_button);
gtk_window_present (GTK_WINDOW (window));
}
int main (int argc, char **argv)
{
GtkApplication *app = gtk_application_new ("de.hs-bochum.cvh.hp.hello-gtk", G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
int status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}
#include <gtk/gtk.h>
#define WIDTH 1024
#define HEIGHT 768
double x = 137;
double y = 255;
static void draw (GtkDrawingArea *drawing_area, cairo_t *c,
int width, int height, gpointer user_data)
{
GdkRGBA blue = { 0.0, 0.5, 1.0, 1.0 };
gdk_cairo_set_source_rgba (c, &blue);
cairo_arc (c, x, y, 10, 0, 2 * G_PI);
cairo_fill (c);
}
gboolean timer (GtkWidget *widget)
{
x += 3;
y += 2;
gtk_widget_queue_draw (widget);
g_timeout_add (50, (GSourceFunc) timer, widget);
return FALSE;
}
static void activate (GtkApplication *app, gpointer user_data)
{
GtkWidget *window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Hello");
GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
gtk_window_set_child (GTK_WINDOW (window), vbox);
GtkWidget *drawing_area = gtk_drawing_area_new ();
gtk_widget_set_size_request (drawing_area, WIDTH, HEIGHT);
gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (drawing_area), draw, NULL, NULL);
gtk_box_append (GTK_BOX (vbox), drawing_area);
GtkWidget *quit_button = gtk_button_new_with_label ("Quit");
g_signal_connect_swapped (quit_button, "clicked", G_CALLBACK (gtk_window_destroy), window);
gtk_box_append (GTK_BOX (vbox), quit_button);
g_timeout_add (50, (GSourceFunc) timer, drawing_area);
gtk_window_present (GTK_WINDOW (window));
}
int main (int argc, char **argv)
{
GtkApplication *app = gtk_application_new ("de.hs-bochum.cvh.hp.hello-gtk", G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
int status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}
#include <gtk/gtk.h>
#define WIDTH 1024
#define HEIGHT 768
double x = 137;
double y = 255;
static void draw (GtkDrawingArea *drawing_area, cairo_t *c,
int width, int height, gpointer user_data)
{
GdkRGBA blue = { 0.0, 0.5, 1.0, 1.0 };
gdk_cairo_set_source_rgba (c, &blue);
cairo_arc (c, x, y, 10, 0, 2 * G_PI);
cairo_fill (c);
}
gboolean timer (GtkWidget *widget)
{
x += 3;
y += 2;
gtk_widget_queue_draw (widget);
return TRUE;
}
static void activate (GtkApplication *app, gpointer user_data)
{
GtkWidget *window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Hello");
GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
gtk_window_set_child (GTK_WINDOW (window), vbox);
GtkWidget *drawing_area = gtk_drawing_area_new ();
gtk_widget_set_size_request (drawing_area, WIDTH, HEIGHT);
gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (drawing_area), draw, NULL, NULL);
gtk_box_append (GTK_BOX (vbox), drawing_area);
GtkWidget *quit_button = gtk_button_new_with_label ("Quit");
g_signal_connect_swapped (quit_button, "clicked", G_CALLBACK (gtk_window_destroy), window);
gtk_box_append (GTK_BOX (vbox), quit_button);
g_timeout_add (50, (GSourceFunc) timer, drawing_area);
gtk_window_present (GTK_WINDOW (window));
}
int main (int argc, char **argv)
{
GtkApplication *app = gtk_application_new ("de.hs-bochum.cvh.hp.hello-gtk", G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
int status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}
#include <gtk/gtk.h>
#define WIDTH 1024
#define HEIGHT 768
double x = 0.0;
double y = 2.0;
double vx = 2.0;
double vy = 1.0;
double dt = 0.05;
static void draw (GtkDrawingArea *drawing_area, cairo_t *c,
int width, int height, gpointer user_data)
{
GdkRGBA blue = { 0.0, 0.5, 1.0, 1.0 };
gdk_cairo_set_source_rgba (c, &blue);
cairo_arc (c, x * 10.0, HEIGHT - y * 10, 10, 0, 2 * G_PI);
cairo_fill (c);
}
gboolean timer (GtkWidget *widget)
{
x += vx * dt;
y += vy * dt;
gtk_widget_queue_draw (widget);
return TRUE;
}
static void activate (GtkApplication *app, gpointer user_data)
{
GtkWidget *window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Hello");
GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
gtk_window_set_child (GTK_WINDOW (window), vbox);
GtkWidget *drawing_area = gtk_drawing_area_new ();
gtk_widget_set_size_request (drawing_area, WIDTH, HEIGHT);
gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (drawing_area), draw, NULL, NULL);
gtk_box_append (GTK_BOX (vbox), drawing_area);
GtkWidget *quit_button = gtk_button_new_with_label ("Quit");
g_signal_connect_swapped (quit_button, "clicked", G_CALLBACK (gtk_window_destroy), window);
gtk_box_append (GTK_BOX (vbox), quit_button);
g_timeout_add (50, (GSourceFunc) timer, drawing_area);
gtk_window_present (GTK_WINDOW (window));
}
int main (int argc, char **argv)
{
GtkApplication *app = gtk_application_new ("de.hs-bochum.cvh.hp.hello-gtk", G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
int status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}
#include <gtk/gtk.h>
#define WIDTH 1024
#define HEIGHT 768
double x = 0.0;
double y = 2.0;
double vx = 2.0;
double vy = 1.0;
double dt = 0.2;
static void draw (GtkDrawingArea *drawing_area, cairo_t *c,
int width, int height, gpointer user_data)
{
GdkRGBA blue = { 0.0, 0.5, 1.0, 1.0 };
gdk_cairo_set_source_rgba (c, &blue);
cairo_arc (c, x * 10.0, HEIGHT - y * 10, 10, 0, 2 * G_PI);
cairo_fill (c);
}
gboolean timer (GtkWidget *widget)
{
x += vx * dt;
y += vy * dt;
gtk_widget_queue_draw (widget);
return TRUE;
}
static void activate (GtkApplication *app, gpointer user_data)
{
GtkWidget *window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Hello");
GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
gtk_window_set_child (GTK_WINDOW (window), vbox);
GtkWidget *drawing_area = gtk_drawing_area_new ();
gtk_widget_set_size_request (drawing_area, WIDTH, HEIGHT);
gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (drawing_area), draw, NULL, NULL);
gtk_box_append (GTK_BOX (vbox), drawing_area);
GtkWidget *quit_button = gtk_button_new_with_label ("Quit");
g_signal_connect_swapped (quit_button, "clicked", G_CALLBACK (gtk_window_destroy), window);
gtk_box_append (GTK_BOX (vbox), quit_button);
g_timeout_add (50, (GSourceFunc) timer, drawing_area);
gtk_window_present (GTK_WINDOW (window));
}
int main (int argc, char **argv)
{
GtkApplication *app = gtk_application_new ("de.hs-bochum.cvh.hp.hello-gtk", G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
int status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}
#include <gtk/gtk.h>
#define WIDTH 1024
#define HEIGHT 768
double x = 0.0;
double y = 2.0;
double vx = 2.0;
double vy = 1.0;
double dt = 0.2;
double g = 9.81;
static void draw (GtkDrawingArea *drawing_area, cairo_t *c,
int width, int height, gpointer user_data)
{
GdkRGBA blue = { 0.0, 0.5, 1.0, 1.0 };
gdk_cairo_set_source_rgba (c, &blue);
cairo_arc (c, x * 10.0, HEIGHT - y * 10, 10, 0, 2 * G_PI);
cairo_fill (c);
}
gboolean timer (GtkWidget *widget)
{
x += vx * dt;
y += vy * dt;
vx += 0.0 * dt;
vy += -g * dt;
gtk_widget_queue_draw (widget);
return TRUE;
}
static void activate (GtkApplication *app, gpointer user_data)
{
GtkWidget *window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Hello");
GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
gtk_window_set_child (GTK_WINDOW (window), vbox);
GtkWidget *drawing_area = gtk_drawing_area_new ();
gtk_widget_set_size_request (drawing_area, WIDTH, HEIGHT);
gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (drawing_area), draw, NULL, NULL);
gtk_box_append (GTK_BOX (vbox), drawing_area);
GtkWidget *quit_button = gtk_button_new_with_label ("Quit");
g_signal_connect_swapped (quit_button, "clicked", G_CALLBACK (gtk_window_destroy), window);
gtk_box_append (GTK_BOX (vbox), quit_button);
g_timeout_add (50, (GSourceFunc) timer, drawing_area);
gtk_window_present (GTK_WINDOW (window));
}
int main (int argc, char **argv)
{
GtkApplication *app = gtk_application_new ("de.hs-bochum.cvh.hp.hello-gtk", G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
int status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}
#include <gtk/gtk.h>
#define WIDTH 1024
#define HEIGHT 768
double x = 0.0;
double y = 2.0;
double vx = 2.0;
double vy = 1.0;
double dt = 0.2;
double g = 0.1;
static void draw (GtkDrawingArea *drawing_area, cairo_t *c,
int width, int height, gpointer user_data)
{
GdkRGBA blue = { 0.0, 0.5, 1.0, 1.0 };
gdk_cairo_set_source_rgba (c, &blue);
cairo_arc (c, x * 10.0, HEIGHT - y * 10, 10, 0, 2 * G_PI);
cairo_fill (c);
}
gboolean timer (GtkWidget *widget)
{
x += vx * dt;
y += vy * dt;
vx += 0.0 * dt;
vy += -g * dt;
gtk_widget_queue_draw (widget);
return TRUE;
}
static void activate (GtkApplication *app, gpointer user_data)
{
GtkWidget *window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Hello");
GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
gtk_window_set_child (GTK_WINDOW (window), vbox);
GtkWidget *drawing_area = gtk_drawing_area_new ();
gtk_widget_set_size_request (drawing_area, WIDTH, HEIGHT);
gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (drawing_area), draw, NULL, NULL);
gtk_box_append (GTK_BOX (vbox), drawing_area);
GtkWidget *quit_button = gtk_button_new_with_label ("Quit");
g_signal_connect_swapped (quit_button, "clicked", G_CALLBACK (gtk_window_destroy), window);
gtk_box_append (GTK_BOX (vbox), quit_button);
g_timeout_add (50, (GSourceFunc) timer, drawing_area);
gtk_window_present (GTK_WINDOW (window));
}
int main (int argc, char **argv)
{
GtkApplication *app = gtk_application_new ("de.hs-bochum.cvh.hp.hello-gtk", G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
int status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}
#include <gtk/gtk.h>
#define WIDTH 1024
#define HEIGHT 768
double x = 0.0;
double y = 6.0;
double vx = 1.5;
double vy = 4.0;
double dt = 0.5;
double g = 0.2;
static void draw (GtkDrawingArea *drawing_area, cairo_t *c,
int width, int height, gpointer user_data)
{
GdkRGBA blue = { 0.0, 0.5, 1.0, 1.0 };
gdk_cairo_set_source_rgba (c, &blue);
cairo_arc (c, x * 10.0, HEIGHT - y * 10, 10, 0, 2 * G_PI);
cairo_fill (c);
}
gboolean timer (GtkWidget *widget)
{
x += vx * dt;
y += vy * dt;
vx += 0.0 * dt;
vy += -g * dt;
gtk_widget_queue_draw (widget);
return TRUE;
}
static void activate (GtkApplication *app, gpointer user_data)
{
GtkWidget *window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Hello");
GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
gtk_window_set_child (GTK_WINDOW (window), vbox);
GtkWidget *drawing_area = gtk_drawing_area_new ();
gtk_widget_set_size_request (drawing_area, WIDTH, HEIGHT);
gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (drawing_area), draw, NULL, NULL);
gtk_box_append (GTK_BOX (vbox), drawing_area);
GtkWidget *quit_button = gtk_button_new_with_label ("Quit");
g_signal_connect_swapped (quit_button, "clicked", G_CALLBACK (gtk_window_destroy), window);
gtk_box_append (GTK_BOX (vbox), quit_button);
g_timeout_add (50, (GSourceFunc) timer, drawing_area);
gtk_window_present (GTK_WINDOW (window));
}
int main (int argc, char **argv)
{
GtkApplication *app = gtk_application_new ("de.hs-bochum.cvh.hp.hello-gtk", G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
int status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment