Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
hp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Anton Ahrens
hp
Commits
19c17aca
Commit
19c17aca
authored
1 year ago
by
Peter Gerwinski
Browse files
Options
Downloads
Patches
Plain Diff
Tafelbilder und Beispiele 30.11.2023
parent
e2b9626f
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
21
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
20231130/pendulum-3.c
+87
-0
87 additions, 0 deletions
20231130/pendulum-3.c
with
87 additions
and
0 deletions
20231130/pendulum-3.c
0 → 100644
+
87
−
0
View file @
19c17aca
#include
<gtk/gtk.h>
#include
<math.h>
#define WIDTH 320
#define HEIGHT 240
#define GAP (HEIGHT / 20)
#define r GAP
#define visual_length (HEIGHT - 2 * GAP - r)
#define phi0 (-0.5)
#define omega0 0.0
#define t0 0.0
#define g 9.81
#define l 1.0
#define dt 0.02
double
t
=
t0
;
double
phi_with_sin
=
phi0
;
double
omega_with_sin
=
omega0
;
double
phi_without_sin
=
phi0
;
double
omega_without_sin
=
omega0
;
void
draw_pendulum
(
cairo_t
*
c
,
double
phi
,
GdkRGBA
*
colour
)
{
int
x
=
WIDTH
/
2
+
visual_length
*
sin
(
phi
);
int
y
=
GAP
+
visual_length
*
cos
(
phi
);
gdk_cairo_set_source_rgba
(
c
,
colour
);
cairo_move_to
(
c
,
WIDTH
/
2
,
GAP
);
cairo_line_to
(
c
,
x
,
y
);
cairo_stroke
(
c
);
cairo_arc
(
c
,
x
,
y
,
r
,
0
,
2
*
G_PI
);
cairo_fill
(
c
);
}
gboolean
draw
(
GtkWidget
*
widget
,
cairo_t
*
c
,
gpointer
data
)
{
GdkRGBA
blue
=
{
0
.
0
,
0
.
5
,
1
.
0
,
1
.
0
};
GdkRGBA
orange
=
{
1
.
0
,
0
.
5
,
0
.
0
,
1
.
0
};
GdkRGBA
green
=
{
0
.
0
,
0
.
5
,
0
.
0
,
1
.
0
};
double
A
=
phi0
;
double
B
=
0
.
5
*
M_PI
;
/* 90° */
double
phi_analytic
=
A
*
sin
(
sqrt
(
g
/
l
)
*
t
+
B
);
/* Näherungen: Kleinwinkel dt */
draw_pendulum
(
c
,
phi_with_sin
,
&
blue
);
/* blau nein ja */
draw_pendulum
(
c
,
phi_without_sin
,
&
orange
);
/* orange ja ja */
draw_pendulum
(
c
,
phi_analytic
,
&
green
);
/* grün ja nein */
return
FALSE
;
/* TRUE to stop other handlers from being invoked for the event.
FALSE to propagate the event further. */
}
gboolean
timer
(
GtkWidget
*
widget
)
{
t
+=
dt
;
phi_with_sin
+=
omega_with_sin
*
dt
;
omega_with_sin
+=
-
dt
*
g
/
l
*
sin
(
phi_with_sin
);
phi_without_sin
+=
omega_without_sin
*
dt
;
omega_without_sin
+=
-
dt
*
g
/
l
*
phi_without_sin
;
gtk_widget_queue_draw_area
(
widget
,
0
,
0
,
WIDTH
,
HEIGHT
);
g_timeout_add
(
50
,
(
GSourceFunc
)
timer
,
widget
);
return
FALSE
;
}
int
main
(
int
argc
,
char
**
argv
)
{
gtk_init
(
&
argc
,
&
argv
);
GtkWidget
*
window
=
gtk_window_new
(
GTK_WINDOW_TOPLEVEL
);
gtk_widget_show
(
window
);
gtk_window_set_title
(
GTK_WINDOW
(
window
),
"Hello"
);
g_signal_connect
(
window
,
"destroy"
,
G_CALLBACK
(
gtk_main_quit
),
NULL
);
GtkWidget
*
drawing_area
=
gtk_drawing_area_new
();
gtk_widget_show
(
drawing_area
);
gtk_container_add
(
GTK_CONTAINER
(
window
),
drawing_area
);
gtk_widget_set_size_request
(
drawing_area
,
WIDTH
,
HEIGHT
);
g_signal_connect
(
drawing_area
,
"draw"
,
G_CALLBACK
(
draw
),
NULL
);
g_timeout_add
(
50
,
(
GSourceFunc
)
timer
,
drawing_area
);
gtk_main
();
return
0
;
}
This diff is collapsed.
Click to expand it.
Prev
1
2
Next
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment