Hi Nathan,
I have attached a modified code, using your advice. It now flickers totally
randomly. I don't know what's wrong. Could you take a look at the code and
point out what I have done wrong?
Thanks,
Quoc
On Monday, October 22, 2012 11:00:18 AM UTC-5, Nathan wrote:
>
> On Fri, Oct 19, 2012 at 2:29 PM, hotelCA <[email protected] <javascript:>
> > wrote:
>
>> Hi, so basically I have an application with a square in the middle that
>> blinks at a certain frequency. The frequency is determined by
>> pyglet.clock.schedule_interval(Blinker, Rate). It basically calls the
>> function Blinker at the time interval of Rate. Now, I have @window.event
>> section, where I have defined on_draw(). Everything works fine, except that
>> on_draw() is triggered on every window event, including hovering the mouse
>> over the window. How do I disable all window events, except the function
>> call? Thanks.
>
>
> You could just not implement the on_draw() event. Just rename your
> on_draw() to some other name, and don't decorate it as the on_draw() event,
> and then just call it when you want to.
>
> ~ Nathan
>
--
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/pyglet-users/-/G4RQ7A9Hpx4J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pyglet-users?hl=en.
import pyglet
from pyglet.gl import *
# Background color definition
colors = {
'grey' : (0.7,0.7,0.7,0),
'black' : (0,0,0,0),
'white' : (1,1,1,0)}
# Stimuli settings
x1Position = 100
y1Position = 350
stimulus1Size = 120.0# Change fastRate and slowRate variables to change the flickering rate
stimulus1Rate = 1/2.0 #2Hz
# ------------------
showStimulus1 = True
showStimulus2 = True
window = pyglet.window.Window(1280, 1024, resizable=True)
#pyglet.window.Window.set_vsync(window, False)
pyglet.gl.glClearColor(*colors['grey']) # Set background color
glPointSize(stimulus1Size)
def stimulus1(time):
global showStimulus1
showStimulus1 = not showStimulus1
if showStimulus1:
pyglet.graphics.draw( 1, pyglet.gl.GL_POINTS,
('v2f', (100, 350) ),
('c3B', (0, 0, 0) ) )
else:
pyglet.graphics.draw( 1, pyglet.gl.GL_POINTS,
('v2f', (100, 350) ),
('c3B', (255, 255, 255) ) )
def on_resize(width, height):
print 'The window was resized to %dx%d' % (width, height)
# def on_resize(width, height):
# glViewport(0, 0, width, height)
pyglet.clock.schedule_interval(stimulus1, stimulus1Rate) # Stimulus on the left
# pyglet.clock.schedule_interval(stimulus2, stimulus2Rate) # Stimulus on the right
pyglet.app.run()