summaryrefslogtreecommitdiffhomepage
path: root/host/inter/test/test_drawable.py
blob: 31200252578e4e542de51cc0816dcccb6b1eb3ca (plain)
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
import sys
sys.path.append (sys.path[0] + '/..')

from drawable import *
from math import pi

class Test (Drawable):

    def draw (self):
	self.draw_rectangle ((-100, -100), (100, 100), fill = '', outline = 'gray')
	self.draw_rectangle ((0, 0), (5, 5), fill = 'red')
	self.draw_rectangle ((20, 20), (50, 50), fill = '', outline = 'blue')
	self.draw_line ((20, 20), (25, 25), (80, 0), (0, 80), fill = 'green')
	self.draw_line ((20, 20), (25, 25), (80, 0), (0, 80), smooth = True)
	self.draw_circle ((40, -40), 10)
	self.draw_arc ((-40, 0), 20, start = pi / 4, extent = pi / 2)

class App (DrawableCanvas):

    def __init__ (self, master = None):
	DrawableCanvas.__init__ (self, 300, 300, 20, 20, master)
	self.pack (expand = True, fill = 'both')
	self.test = Test (self)
	self.animated = False
	self.i = 0

    def animate (self):
	# Real user should reset at each redraw.
	self.after (500, self.animate)
	self.test.draw ()
	self.test.trans_rotate (-pi/12)
	self.test.trans_translate ((10, 10))
	self.test.trans_scale (1.05)
	self.i += 1
	if self.i == 10:
	    self.test.reset ()

    def draw (self):
	if not self.animated:
	    self.animate ()
	    self.animated = True

app = App ()
app.mainloop ()