# -*- coding: utf-8 -*- full_screen = True window_size = (1024, 768) import sys, random, pygame, threading, time from pygame.locals import * from math import * background_color = (0,0,0) white=(255,255,255) red=(255,0,0) green=(0,255,0) yellow=(255,255,0) blue=(0,0,255) cyan=(51,255,255) purple=(153,51,153) colors=[red,green,yellow,cyan,blue,purple] colors_no_load=[cyan,blue,purple] letter_colors=['A','a'] time_blank=250 time_letter=500 W=900 H=600 height_letter=20 ntrials=1 circles = ((-1,1),)#((0, 1),) #coordinates of yellow target# -1 = to left #if (0,1) at the middle circle_scale = 0.3# scale of coordinate of yellow target #if 1=> 1 unit <=> half of screen height and target position #at top lim of screen circle_radius = 8 #radius of yellow target n_grid = 6#3 => taille grille; si 3=> grid confined within the screen grid_spacing = 0.2 # space between crosses grid_length = 0.05 # length of grid crosses grid_width = 2 #thickness of grid crosses fix_radius = 25#size of central dehiscence rotation_speed = 20*pi/2#pi/2 bg_color = (0, 0, 0) grid_color = (100, 100, 255)#blue grid circle_color = (255, 255, 0)#yellow target disapp_frames = 1 # I don t know ?? window_center = (window_size[0]/2.0, window_size[1]/2.0) window_scale = min(window_size)/2.0 def coord(real): """takes real coordinates, returns pixel coordinates""" return (int(round(real[0]*window_scale + window_center[0])),\ int(round(-real[1]*window_scale + window_center[1]))) g_cos, g_sin = 1, 0 def set_rotation(angle): """sets up rotation""" global g_cos, g_sin g_cos, g_sin = cos(angle), sin(angle) def rotate(point): """rotates a 3D point about the Z-axis by given angle set by set_rotation()""" return (g_cos*point[0] + g_sin*point[1], -g_sin*point[0] + g_cos*point[1]) def thread_letter(): for trial in range(ntrials): # surf.fill(bg_color) pygame.display.flip() pygame.time.wait(time_blank) theletter=random.randrange(len(letter_colors)) thecolor=random.randrange(len(colors)) police = pygame.font.Font(None, height_letter) letter_to_display=police.render(letter_colors[theletter],1,colors[thecolor]) surf.blit(letter_to_display, coord((0, 0))) pygame.display.flip() # surf.fill(bg_color) pygame.time.wait(time_letter) time.sleep(0.25) # graphics initializations frames, show = 0, True try: pygame.init() if full_screen: surf = pygame.display.set_mode(window_size, HWSURFACE | FULLSCREEN | DOUBLEBUF) else: surf = pygame.display.set_mode(window_size) #police ICI LETTRES TOURNENT UNE FOIS PUIS LE GRID SE LANCE # TROP SEQUENTIEL ++++ t0 = pygame.time.get_ticks() while True: for event in pygame.event.get(): if event.type in (QUIT, KEYDOWN): raise Exception() elif event.type == MOUSEBUTTONDOWN: frames, show = 0, False elif event.type == MOUSEBUTTONUP: frames, show = 0, True surf.fill(bg_color) t = (pygame.time.get_ticks() - t0)/1000.0 set_rotation(rotation_speed*t) for i in range(-n_grid, +n_grid + 1): #i(-3,4) # n_grid : total grid size:3 at onset for j in range(-n_grid, +n_grid + 1): #j(-3,4) center = (grid_spacing*i, grid_spacing*j) # fr = rotate ((center[0] - grid_length , center[1])) to = rotate ((center[0] + grid_length , center[1])) # pygame.draw.line(surf, grid_color, coord(fr), coord(to), grid_width) # fr = rotate ((center[0] , center[1] - grid_length)) to = rotate ((center[0] , center[1] + grid_length)) # pygame.draw.line(surf, grid_color, coord(fr), coord(to), grid_width) # for circ in circles: c = (circle_scale*circ[0], circle_scale*circ[1]) if show: # show=0 graphics initialization col = (150, 150, 0)# color of yellow target (if (250,250,0) + flashy) pygame.draw.circle(surf, col, coord(c), circle_radius, 0) #draw target else: step = 150/disapp_frames lev = max(0, 150 - frames*step) col = (lev, lev, 0) if lev > 0: pygame.draw.circle(surf, col, coord(c), circle_radius, 0) pygame.draw.circle(surf, bg_color, coord((0, 0)), fix_radius)# central dehiscence pygame.display.flip() frames += 1 #ICI LE BLOC NE FAIT Q TOURNER TOUT SEUL GRID ARRETE # GRID SE DEPLACE D UN DEGRE apres chaque serie de LETTRES stop=False thread=threading.Thread(group=None, target=thread_letter, name=None, args=(), kwargs={}) thread.start() stop=True thread.join() # time.sleep(0.25) finally: pygame.quit()