def draw(): global max_twist age = now() - start if mouse_x is not None: m_a = (mouse_x / float(screen_width) - 0.5) * 2 * real_max_twist max_twist = m_a else: m_a = cos(age / 2.) * max_twist * exp(-age / 20) color("black") box(0, 0, screen_width, screen_height) for i in range(0, num_triangles): size = min_size + (max_size - min_size) * float(i) / num_triangles size = max_size - size size *= (sin(now() + pulse_offset[i]) * pulse_magnitude + 1) l = min_l + (max_l - min_l) * float(i) / num_triangles tri = make_triangle( screen_width / 2., screen_height / 2., size, i * m_a + sin(now() + rot_pulse_offset[i]) * pulse_magnitude) color("hsl(230,100%," + str(round(l)) + "%)") fill_polygon(tri) color("hsl(230,100%," + str(round(l - 10)) + "%)") polygon(tri)
def handle_frame(): global last_frame if now() - last_frame < 1. / 30.: #print "dropping frame" return draw() last_frame = now() sleep(1000. / 30. - 10)
def handle_frame(): global i,stopCount if (i % 60) == 0 and stopCount != "true": newTime = now() - startTime doSecond() # Do everything else on framechange i=i+1
def handle_frame(): global i if (i % 60) == 0: newTime = now() - startTime doSecond() # Do everything else on framechange i=i+1
from tealight.utils import now from tealight.art import text,box,color, background, screen_width, screen_height startTime = now() i=0 stopCount = "false" global points points = 31 def doSecond(): global points points = points - 1 color("white") box(0,screen_height - 100, 100, 100) color("black") if points < 0: points = 0 text(10,screen_height - 30, ("Points: " + str(points))) def handle_frame(): global i,stopCount if (i % 60) == 0 and stopCount != "true": newTime = now() - startTime doSecond() # Do everything else on framechange i=i+1
def handle_frame(): global prev_data, last_hb_sent, last_sent, score, current_direction, previous_direction, current_x, current_y, current_velocity, accelerating, rotating if rotating == 1: current_direction -= 5 elif rotating == 2: current_direction += 5 draw_track() color("white") text(150,5,"RACETRACK by Adam, Calin, Matt") color("white") text(5,5,"Score: " + str(score)) movement_data = movement(current_x, current_y, current_velocity, current_direction, current_size) if check_finish(current_x, current_y) == True: color("white") text(5,20,"You win!") network_client.authenticated_send({"state": "win"}, "server", "status") current_x = 77 current_y = 412 current_velocity = -900 if "losing" in movement_data: current_x = 77 current_y = 412 current_velocity = 0 current_direction = 0 accelerating = 0 rotating = 0 lose() else: if accelerating == 0: if current_velocity <= 0.1: current_velocity = 0 else: current_velocity *= 0.95 elif current_velocity > 0 and current_velocity <= 0.1: current_velocity = 0 elif current_velocity < 0: current_velocity += 0.1 current_x = movement_data['x'] current_y = movement_data['y'] data = {"x": current_x, "y": current_y, "d": current_direction} if data != prev_data: network_client.authenticated_send(data, "all", "position") prev_data = data if accelerating == 1: data = movement_handle_keydown("up", current_velocity) if data is not None: current_velocity = data['speed'] draw_triangle(current_x,current_y,current_direction,current_size,"red") previous_direction = current_direction if accelerating > 0 and now()- last_sent > 0.5: last_sent = now() score += 1 if now() - last_hb_sent > 5: network_client.client_handle_frame() last_hb_sent = now() #print test_polygon(100, 100, [(100,200), (50, 50), (200,100), (150,250)])
# Main project file # Written by Adam, Matt and Calin # GH: a-l-williams, lordvile018 calintat # I apologise for the global variables and general mess from github.calintat.art.racetrack import * from tealight.utils import github_load, now, sleep project_globals = github_load("a-l-williams", "art", "project-globals") key_handlers = github_load("lordvile018", "art", "racetrack") network_client = github_load("lordvile018", "art", "racetrackclient") y = project_globals.Globals() print y.get_connection_string() draw_track() current_direction = 0 last_sent = now() last_hb_sent = now() previous_direction = 0 current_acceleration = 0 rotating = 0 # 0 for not, 1 for left, 2 for right accelerating = 0 # 0 for not, 1 for forward, 2 for back current_x = 77 current_y = 412 current_velocity = 0 current_size = 10 score = 0 prev_data = {} def lose(): global score
def handle_mouseup(): global start, mouse_x start = now() mouse_x = None
max_size = max(min(screen_width, screen_height) / 2. - 10, 10) min_size = max_size / num_triangles max_l = 95 min_l = 20 max_pulse_magnitude = 0.4 def make_triangle(x, y, size, angle=0): pts = [] for i in range(0, 3): theta = angle + i * 2 * pi / 3 pts.append((x + size * sin(theta), y + size * cos(theta))) return pts start = now() mouse_x = None pulse_offset = [random() * 2 * pi for i in range(0, num_triangles)] rot_pulse_offset = [random() * 2 * pi for i in range(0, num_triangles)] pulse_magnitude = max_pulse_magnitude / 4 real_max_twist = 2 * pi * 3 / num_triangles max_twist = real_max_twist def draw(): global max_twist age = now() - start if mouse_x is not None: m_a = (mouse_x / float(screen_width) - 0.5) * 2 * real_max_twist