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 ...@@ -3,7 +3,7 @@ import pygame, sys, time
from touch import add, MultiTouchListener from touch import add, MultiTouchListener
from math import degrees, cos, sin from math import degrees, cos, sin
from events import RotateEvent from events import Rotate
pygame.init() pygame.init()
...@@ -16,16 +16,12 @@ BG_COLOR = 0, 0, 0 ...@@ -16,16 +16,12 @@ BG_COLOR = 0, 0, 0
LINE_COLOR = 128, 128, 128 LINE_COLOR = 128, 128, 128
CIRCLE_COLOR = 255, 255, 255 CIRCLE_COLOR = 255, 255, 255
RECT_COLOR = 0, 200, 0 RECT_COLOR = 0, 200, 0
RECT_SIZE = 150, 100
RECT_POS = W / 2, H / 2 RECT_POS = W / 2, H / 2
RECT_SIZE = W / 6., H / 6.
# Create canvas GUI in the current thread # Create canvas GUI in the current thread
screen = pygame.display.set_mode((W, H)) 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): def rotate_point(point, axis, angle):
...@@ -44,27 +40,21 @@ def coord(x, y): ...@@ -44,27 +40,21 @@ def coord(x, y):
# Rotated rectangle # Rotated rectangle
angle = 0 angle = 0
scale = 1 scale = 1
w, h = W, H
def update(): def update():
global rotations, w, h, scale
cx, cy = coord(*listener.centroid) cx, cy = coord(*listener.centroid)
# Clear previous frame # Clear previous frame
screen.fill(BG_COLOR) screen.fill(BG_COLOR)
# Apply rotation to rectangle canvas # Apply scale and rotation to a fixed-size rectangle canvas
canvas = pygame.Surface((w, h)) canvas = pygame.Surface(RECT_SIZE)
canvas.fill(BG_COLOR) canvas.fill(RECT_COLOR)
pygame.draw.rect(canvas, RECT_COLOR, RECT_POS + RECT_SIZE) transformed = pygame.transform.rotozoom(canvas, degrees(angle), scale * 2)
w, h = int(round(scale * w)), int(round(scale * h)) rect = transformed.get_rect()
scale = 1
scaled_canvas = pygame.transform.scale(canvas, (w, h))
rotated_canvas = pygame.transform.rotate(scaled_canvas, degrees(angle))
rect = rotated_canvas.get_rect()
rect.center = W / 2, H / 2 rect.center = W / 2, H / 2
screen.blit(rotated_canvas, rect) screen.blit(transformed, rect)
# Draw touch points # Draw touch points
for p in listener.points: for p in listener.points:
...@@ -76,19 +66,24 @@ def update(): ...@@ -76,19 +66,24 @@ def update():
# Draw outlined circle around touch point # Draw outlined circle around touch point
pygame.draw.circle(screen, CIRCLE_COLOR, (x, y), FINGER_RADIUS, 1) 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 # Draw filled circle around centroid
pygame.draw.circle(screen, CIRCLE_COLOR, (cx, cy), CENTROID_RADIUS) pygame.draw.circle(screen, CIRCLE_COLOR, (cx, cy), CENTROID_RADIUS)
# Update canvas # Update canvas
pygame.display.flip() pygame.display.flip()
def rotate(event): def rotate(event):
global angle global angle
angle += event.angle angle += event.angle
def pinch(event): def pinch(event):
global scale global scale
scale = event.amount scale += event.amount
# Start touch event listener in separate thread # Start touch event listener in separate thread
...@@ -99,13 +94,9 @@ listener.start(threaded=True) ...@@ -99,13 +94,9 @@ listener.start(threaded=True)
# Start GUI event loop # Start GUI event loop
try: try:
while True: while not filter(lambda e: e.type == pygame.QUIT, pygame.event.get()):
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
update() update()
except KeyboardInterrupt: except KeyboardInterrupt:
pass pass
finally: 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