aboutsummaryrefslogtreecommitdiff
path: root/fieldicle.py
diff options
context:
space:
mode:
authorAdrian Kummerlaender2019-05-26 13:18:01 +0200
committerAdrian Kummerlaender2019-05-26 13:18:01 +0200
commit25d82ada250326bca3df529f08dcfe183632678d (patch)
treefcfc367a70273fbfe549f45732505ecbf5736e74 /fieldicle.py
parent6cc755242f650de5bddd47170360d0ec81d0f661 (diff)
downloadsymlbm_playground-25d82ada250326bca3df529f08dcfe183632678d.tar
symlbm_playground-25d82ada250326bca3df529f08dcfe183632678d.tar.gz
symlbm_playground-25d82ada250326bca3df529f08dcfe183632678d.tar.bz2
symlbm_playground-25d82ada250326bca3df529f08dcfe183632678d.tar.lz
symlbm_playground-25d82ada250326bca3df529f08dcfe183632678d.tar.xz
symlbm_playground-25d82ada250326bca3df529f08dcfe183632678d.tar.zst
symlbm_playground-25d82ada250326bca3df529f08dcfe183632678d.zip
Make config window togglable
Tying the GTK loop into the OpenGL update loop works ok but is probably not how this should be done.
Diffstat (limited to 'fieldicle.py')
-rw-r--r--fieldicle.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/fieldicle.py b/fieldicle.py
index 42d421a..42af810 100644
--- a/fieldicle.py
+++ b/fieldicle.py
@@ -26,6 +26,8 @@ class ParticleWindow:
num_particles = 100000
time_step = .005
+ gtk_active = False
+
def glut_window(self):
glutInit(sys.argv)
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH)
@@ -34,7 +36,8 @@ class ParticleWindow:
window = glutCreateWindow("fieldicle")
glutDisplayFunc(self.on_display)
- glutTimerFunc(10, self.on_timer, 10)
+ glutSpecialFunc(self.on_keyboard)
+ glutTimerFunc(5, self.on_timer, 5)
glutReshapeFunc(self.on_window_resize)
glViewport(0, 0, self.window_width, self.window_height)
@@ -49,6 +52,11 @@ class ParticleWindow:
return(window)
+ def on_keyboard(self, key, x, y):
+ if key == GLUT_KEY_F1:
+ self.gtk_active = True
+ ParamWindow(self).show_all()
+
def initial_buffers(self, num_particles):
self.np_position = numpy.ndarray((self.num_particles, 4), dtype=numpy.float32)
self.np_color = numpy.ndarray((num_particles, 4), dtype=numpy.float32)
@@ -68,6 +76,8 @@ class ParticleWindow:
def on_timer(self, t):
glutTimerFunc(t, self.on_timer, t)
glutPostRedisplay()
+ if self.gtk_active:
+ Gtk.main_iteration_do(False)
def set_particle_start_positions(self):
self.np_position[:,0] = self.world_width * numpy.random.random_sample((self.num_particles,)) - (self.world_width/2)
@@ -166,8 +176,8 @@ class ParticleWindow:
life = 1.0f;
}
- p.x += $fx * $time_step;
- p.y += $fy * $time_step;
+ p.x += ($fx) * $time_step;
+ p.y += ($fy) * $time_step;
position[i] = p;
color[i].w = life;
@@ -210,9 +220,3 @@ class ParamWindow(Gtk.Dialog):
self.entryFx.get_text(),
self.entryFy.get_text()
)
-
-
-paramWindow = ParamWindow(particleWindow)
-paramWindow.connect("destroy", Gtk.main_quit)
-paramWindow.show_all()
-Gtk.main()