Commit 8277b925 authored by Taddeus Kroes's avatar Taddeus Kroes

Started debugging test draw program.

parent 73d8cdfc
......@@ -3,7 +3,7 @@ import pygame, sys, time
from touch import add, MultiTouchListener
from math import degrees, cos, sin
from events import RotateEvent
from events import Rotate
pygame.init()
......@@ -16,16 +16,12 @@ BG_COLOR = 0, 0, 0
LINE_COLOR = 128, 128, 128
CIRCLE_COLOR = 255, 255, 255
RECT_COLOR = 0, 200, 0
RECT_SIZE = 150, 100
RECT_POS = W / 2, H / 2
RECT_SIZE = W / 6., H / 6.
# Create canvas GUI in the current thread
screen = pygame.display.set_mode((W, H))
rotations = [RotateEvent(W / 2, H / 2, 70, 2)]
#rotations = []
#x, y, w, h = RECT_SIZE
#rect = [(x, y), (x, y + h), (x + w, y + h), (x + w, y)]
def rotate_point(point, axis, angle):
......@@ -44,27 +40,21 @@ def coord(x, y):
# Rotated rectangle
angle = 0
scale = 1
w, h = W, H
def update():
global rotations, w, h, scale
cx, cy = coord(*listener.centroid)
# Clear previous frame
screen.fill(BG_COLOR)
# Apply rotation to rectangle canvas
canvas = pygame.Surface((w, h))
canvas.fill(BG_COLOR)
pygame.draw.rect(canvas, RECT_COLOR, RECT_POS + RECT_SIZE)
w, h = int(round(scale * w)), int(round(scale * h))
scale = 1
scaled_canvas = pygame.transform.scale(canvas, (w, h))
rotated_canvas = pygame.transform.rotate(scaled_canvas, degrees(angle))
rect = rotated_canvas.get_rect()
# Apply scale and rotation to a fixed-size rectangle canvas
canvas = pygame.Surface(RECT_SIZE)
canvas.fill(RECT_COLOR)
transformed = pygame.transform.rotozoom(canvas, degrees(angle), scale * 2)
rect = transformed.get_rect()
rect.center = W / 2, H / 2
screen.blit(rotated_canvas, rect)
screen.blit(transformed, rect)
# Draw touch points
for p in listener.points:
......@@ -76,19 +66,24 @@ def update():
# Draw outlined circle around touch point
pygame.draw.circle(screen, CIRCLE_COLOR, (x, y), FINGER_RADIUS, 1)
# Fill outlined circle with background color
pygame.draw.circle(screen, BG_COLOR, (x, y), FINGER_RADIUS - 1, 0)
# Draw filled circle around centroid
pygame.draw.circle(screen, CIRCLE_COLOR, (cx, cy), CENTROID_RADIUS)
# Update canvas
pygame.display.flip()
def rotate(event):
global angle
angle += event.angle
def pinch(event):
global scale
scale = event.amount
scale += event.amount
# Start touch event listener in separate thread
......@@ -99,13 +94,9 @@ listener.start(threaded=True)
# Start GUI event loop
try:
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
while not filter(lambda e: e.type == pygame.QUIT, pygame.event.get()):
update()
except KeyboardInterrupt:
pass
finally:
print 'Stopping program...'
listener.stop()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment