<commit_before>#!/usr/bin/env python
"""Control a target with the mouse, using your own event loop."""

# Variables to store the mouse position
mouse_position = (320.0, 240.0)
last_mouse_position = (0.0,0.0)

############################
#  Import various modules  #
############################

from VisionEgg.Core import *
from VisionEgg.MoreStimuli import *
from VisionEgg.Text import *
from math import *
import pygame

#################################
#  Initialize the various bits  #
#################################

# Initialize OpenGL graphics screen.
screen = get_default_screen()

# Set the background color to white (RGBA).
screen.parameters.bgcolor = (1.0,1.0,1.0,1.0)

# Create an instance of the Target2D class with appropriate parameters.
target = Target2D(size  = (25.0,10.0),
                  color      = (0.0,0.0,0.0,1.0)) # Set the target color (RGBA) black

text = Text( text = "Press Esc to quit, arrow keys to change size of target.",
             position = (screen.size[0]/2.0,5),
             anchor='bottom',
             color = (0.0,0.0,0.0,1.0))

# Create a Viewport instance
viewport = Viewport(screen=screen, stimuli=[target,text])

################
#  Math stuff  #
################

def cross_product(b,c):
    """Cross product between vectors, represented as tuples of length 3."""
    det_i = b[1]*c[2] - b[2]*c[1]
    det_j = b[0]*c[2] - b[2]*c[0]
    det_k = b[0]*c[1] - b[1]*c[0]
    return (det_i,-det_j,det_k)

def mag(b):
    """Magnitude of a vector."""
    return b[0]**2.0 + b[1]**2.0 + b[2]**2.0
    
# target size
target_w = 50.0
target_h = 10.0

# key state
up = 0
down = 0
left = 0
right = 0

# The main loop below is an alternative to using the
# VisionEgg.Core.Presentation class.

quit_now = 0
frame_timer = FrameTimer()
while not quit_now:
    for event in pygame.event.get():
        if event.type == pygame.locals.QUIT:
            quit_now = 1
        elif event.type == pygame.locals.KEYDOWN:
            if event.key == pygame.locals.K_ESCAPE:
                quit_now = 1
            elif event.key == pygame.locals.K_UP:
                up = 1
            elif event.key == pygame.locals.K_DOWN:
                down = 1
            elif event.key == pygame.locals.K_RIGHT:
                right = 1
            elif event.key == pygame.locals.K_LEFT:
                left = 1
        elif event.type == pygame.locals.KEYUP:
            if event.key == pygame.locals.K_UP:
                up = 0
            elif event.key == pygame.locals.K_DOWN:
                down = 0
            elif event.key == pygame.locals.K_RIGHT:
                right = 0
            elif event.key == pygame.locals.K_LEFT:
                left = 0

    just_current_pos = mouse_position
    (x,y) = pygame.mouse.get_pos()
    y = screen.size[1]-y # convert to OpenGL coords
    mouse_position = (x,y)
    if just_current_pos != mouse_position:
        last_mouse_position = just_current_pos
        
    # Set target position
    target.parameters.center = mouse_position
    
    # Set target orientation
    b = (float(last_mouse_position[0]-mouse_position[0]),
         float(last_mouse_position[1]-mouse_position[1]),
         0.0)<commit_msg>trivial: cleanup of code to use booleans<commit_after>#!/usr/bin/env python
"""Control a target with the mouse, using your own event loop."""

# Variables to store the mouse position
mouse_position = (320.0, 240.0)
last_mouse_position = (0.0,0.0)

############################
#  Import various modules  #
############################

from VisionEgg.Core import *
from VisionEgg.MoreStimuli import *
from VisionEgg.Text import *
from math import *
import pygame

# Use Python's bool constants if available, make aliases if not
try:
    True
except NameError:
    True = 1==1
    False = 1==0

#################################
#  Initialize the various bits  #
#################################

# Initialize OpenGL graphics screen.
screen = get_default_screen()

# Set the background color to white (RGBA).
screen.parameters.bgcolor = (1.0,1.0,1.0,1.0)

# Create an instance of the Target2D class with appropriate parameters.
target = Target2D(size  = (25.0,10.0),
                  color      = (0.0,0.0,0.0,1.0)) # Set the target color (RGBA) black

text = Text( text = "Press Esc to quit, arrow keys to change size of target.",
             position = (screen.size[0]/2.0,5),
             anchor='bottom',
             color = (0.0,0.0,0.0,1.0))

# Create a Viewport instance
viewport = Viewport(screen=screen, stimuli=[target,text])

################
#  Math stuff  #
################

def cross_product(b,c):
    """Cross product between vectors, represented as tuples of length 3."""
    det_i = b[1]*c[2] - b[2]*c[1]
    det_j = b[0]*c[2] - b[2]*c[0]
    det_k = b[0]*c[1] - b[1]*c[0]
    return (det_i,-det_j,det_k)

def mag(b):
    """Magnitude of a vector."""
    return b[0]**2.0 + b[1]**2.0 + b[2]**2.0
    
# target size
target_w = 50.0
target_h = 10.0

# key state
up = False
down = False
left = False
right = False

# The main loop below is an alternative to using the
# VisionEgg.FlowControl.Presentation class.

quit_now = False
frame_timer = FrameTimer()
while not quit_now:
    for event in pygame.event.get():
        if event.type == pygame.locals.QUIT:
            quit_now = True
        elif event.type == pygame.locals.KEYDOWN:
            if event.key == pygame.locals.K_ESCAPE:
                quit_now = True
            elif event.key == pygame.locals.K_UP:
                up = True
            elif event.key == pygame.locals.K_DOWN:
                down = True
            elif event.key == pygame.locals.K_RIGHT:
                right = True
            elif event.key == pygame.locals.K_LEFT:
                left = True
        elif event.type == pygame.locals.KEYUP:
            if event.key == pygame.locals.K_UP:
                up = False
            elif event.key == pygame.locals.K_DOWN:
                down = False
            elif event.key == pygame.locals.K_RIGHT:
                right = False
            elif event.key == pygame.locals.K_LEFT:
                left = False

    just_current_pos = mouse_position
    (x,y) = pygame.mouse.get_pos()
    y = screen.size[1]-y # convert to OpenGL coords
    mouse_position = (x,y)
    if just_current_pos != mouse_position:
        last_mouse_position = just_current_pos
        
    # Set target position
    target.parameters.center = mouse_position
    
    # Set target orientation
    b = (float(last_mouse_position[0]-mouse_position[0]),
         float(last_mouse_position[1]-mouse_position[1]),
         0.0)
{'fraction_non_alphanumeric': 0.15924916742355436, 'fraction_numerical': 0.028004844081138357, 'mean_word_length': 2.464604090194022, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3283123', 'n_tokens_mistral': 2217, 'n_tokens_neox': 2132, 'n_words': 555}