Repository navigation
Expand file tree
/
Copy pathtest_draw_parameter.py
More file actions
59 lines (49 loc) · 1.54 KB
/
Copy pathtest_draw_parameter.py
File metadata and controls
59 lines (49 loc) · 1.54 KB
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
from __future__ import division, print_function, unicode_literals
# This code is so you can run the samples without installing the package
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
#
testinfo = "s, t 1.5, s, t 3.1, s, q"
tags = "Draw, parameter"
import cocos
from cocos.director import director
from cocos.actions import Lerp, Reverse, Repeat
from cocos import draw
import pyglet, math
class TestFigure(draw.Canvas):
line_width = draw.parameter(5)
def render(self):
x,y = director.get_window_size()
ye = 15
xs = 15
line_width = self.line_width
self.set_color( (255,255,0,125) )
self.set_stroke_width( line_width )
parts = 5
# draw lines
self.set_endcap( draw.ROUND_CAP )
self.translate(( x//2, y//2 ))
for j in range(parts):
self.move_to( (0,0) )
self.rotate( 2*math.pi/ parts )
self.push()
for i in range(parts):
self.line_to( (xs,ye) )
self.translate( (xs,ye) )
self.rotate( math.pi/ parts )
self.pop()
class TestLayer(cocos.layer.Layer):
def __init__(self):
super( TestLayer, self ).__init__()
f = TestFigure()
self.add( f )
a = Lerp("line_width", 5, 55, 3)
f.do( Repeat( a + Reverse( a ) ) )
def main():
director.init()
test_layer = TestLayer ()
main_scene = cocos.scene.Scene (test_layer)
director.run (main_scene)
if __name__ == '__main__':
main()