-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSlice.py
87 lines (66 loc) · 2.85 KB
/
Slice.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# This file is part of FoodPuter.
# Foobar is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# Foobar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with Foobar. If not, see <http://www.gnu.org/licenses/>.
# not used any more
import pygame, math
class Slice_state:
LOCKED = 0
READY = 1
DONE = 2
WAITING = 3
def tup_avg(pair):
return (pair[0] + pair[1]) * .5
class Slice:
inner_r = 16
font = ''
def __init__(self, state = Slice_state.READY, W = 800, H = 600):
self.font = pygame.font.Font("./font/Bender.otf", 32)
self.state = state
self.angle = 0
self.da = 2.0 * math.pi / 3.0
self.center = (W/2, H/2)
self.r = min(W,H) / 3.0
def draw(self, surface):
# print "draw me like one of your french girls"
color = (0,255,0)
if (Slice_state.READY == self.state):
color = (255,255,0)
elif (Slice_state.LOCKED == self.state):
color = (255,0,0)
center = (self.center[0] + self.inner_r * math.cos(self.angle + self.da * .5),
self.center[1] + self.inner_r * math.sin(self.angle + self.da * .5))
p1 = (center[0] + self.r * math.cos(self.angle),
center[1] + self.r * math.sin(self.angle))
p2 = (center[0] + self.r * math.cos(self.angle + self.da),
center[1] + self.r * math.sin(self.angle + self.da))
pygame.draw.aaline(surface, color, center, p1, 6)
pygame.draw.aaline(surface, color, center, p2, 6)
#create amn Rect covering ze points
# left = self.center[0] - self.r
# top = self.center[1] - self.r
# rect = pygame.Rect(left, top, self.r * 2,self.r * 2)
# pygame.draw.arc(surface, color, rect , self.angle, self.angle + self.da, 16)
#arc sucks
last = p1
steps = 17
ss = self.da/steps
for i in range(steps + 1):
da = i * ss
cur = (center[0] + self.r * math.cos(self.angle + da),
center[1] + self.r * math.sin(self.angle + da))
pygame.draw.aaline(surface, color, last, cur, 6)
last = cur
#the label
label = self.font.render(self.get_text() ,1, (0,255,0))
surface.blit(label, map(tup_avg, zip(p1,p2)))
def update(self, clock):
self.angle += .0001;
Slice.inner_r = 12 + 3 * math.sin(clock*.001)