Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
multitouch
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
multitouch
Commits
8277b925
Commit
8277b925
authored
May 04, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Started debugging test draw program.
parent
73d8cdfc
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
26 deletions
+17
-26
src/draw.py
src/draw.py
+17
-26
No files found.
src/draw.py
View file @
8277b925
...
@@ -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
Rotate
Event
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
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment