本文整理汇总了Python中nodebox.graphics.Transform.rotate方法的典型用法代码示例。如果您正苦于以下问题:Python Transform.rotate方法的具体用法?Python Transform.rotate怎么用?Python Transform.rotate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nodebox.graphics.Transform
的用法示例。
在下文中一共展示了Transform.rotate方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: copy
# 需要导入模块: from nodebox.graphics import Transform [as 别名]
# 或者: from nodebox.graphics.Transform import rotate [as 别名]
def copy(shape, copies, transform_order='tsr', translate=Point.ZERO, rotate=0, scale=Point.ZERO):
"""Create multiple copies of a shape."""
if shape is None: return None
if isinstance(shape, Path):
shape = shape.asGeometry()
g = Geometry()
tx = ty = r = 0.0
sx = sy = 1.0
for i in xrange(copies):
t = Transform()
# Each letter of the order describes an operation.
for op in transform_order:
if op == 't':
t.translate(tx, ty)
elif op == 'r':
t.rotate(r)
elif op == 's':
t.scale(sx, sy)
g.extend(t.map(shape))
tx += translate.x
ty += translate.y
r += rotate
sx += scale.x / 100.0
sy += scale.y / 100.0
return g
示例2: filter
# 需要导入模块: from nodebox.graphics import Transform [as 别名]
# 或者: from nodebox.graphics.Transform import rotate [as 别名]
def filter(shape):
"""Serve as a template for future functions that filter geometry"""
if shape is None:
return None
t = Transform()
t.rotate(45)
return t.map(shape)
示例3: shape_on_path
# 需要导入模块: from nodebox.graphics import Transform [as 别名]
# 或者: from nodebox.graphics.Transform import rotate [as 别名]
def shape_on_path(shape, template, amount, dist, start, keep_geometry):
if shape is None: return None
if template is None: return None
if isinstance(shape, Path):
shape = shape.asGeometry()
if isinstance(template, Path):
template = template.asGeometry()
g = Geometry()
if keep_geometry:
g.extend(template.clone())
first = True
for i in range(amount):
if first:
t = start / 100
first = False
else:
t += dist / 500.0
pt1 = template.pointAt(t)
pt2 = template.pointAt(t + 0.00001)
a = angle(pt2.x, pt2.y, pt1.x, pt1.y)
tp = Transform()
tp.translate(pt1.x, pt1.y)
tp.rotate(a - 180)
new_shape = tp.map(shape)
g.extend(new_shape)
return g
示例4: rotate
# 需要导入模块: from nodebox.graphics import Transform [as 别名]
# 或者: from nodebox.graphics.Transform import rotate [as 别名]
def rotate(shape, angle, origin=Point.ZERO):
"""Rotate the given shape."""
if shape is None: return None
t = Transform()
t.translate(origin)
t.rotate(angle)
t.translate(Point(-origin.x, -origin.y))
return t.map(shape)
示例5: rotate
# 需要导入模块: from nodebox.graphics import Transform [as 别名]
# 或者: from nodebox.graphics.Transform import rotate [as 别名]
def rotate(s):
a = to_number_array(s)
r = a[0]
tx = 0
ty = 0
if len(a) > 1:
tx = a[1]
if len(a) > 2:
ty = a[2]
t = Transform()
t.translate(tx, ty)
t.rotate(r)
t.translate(-tx, -ty)
return t
示例6: shape_on_path
# 需要导入模块: from nodebox.graphics import Transform [as 别名]
# 或者: from nodebox.graphics.Transform import rotate [as 别名]
def shape_on_path(shapes, path, amount, alignment, spacing, margin, baseline_offset):
if not shapes:
return []
if path is None:
return []
if alignment == "trailing":
shapes = list(shapes)
shapes.reverse()
length = path.length - margin
m = margin / path.length
c = 0
new_shapes = []
for i in xrange(amount):
for shape in shapes:
if alignment == "distributed":
p = length / ((amount * len(shapes)) - 1)
pos = c * p / length
pos = m + (pos * (1 - 2 * m))
else:
pos = ((c * spacing) % length) / length
pos = m + (pos * (1 - m))
if alignment == "trailing":
pos = 1 - pos
p1 = path.pointAt(pos)
p2 = path.pointAt(pos + 0.0000001)
a = angle(p1.x, p1.y, p2.x, p2.y)
if baseline_offset:
coords = coordinates(p1.x, p1.y, baseline_offset, a - 90)
p1 = Point(*coords)
t = Transform()
t.translate(p1)
t.rotate(a)
new_shapes.append(t.map(shape))
c += 1
return new_shapes
示例7: l_system
# 需要导入模块: from nodebox.graphics import Transform [as 别名]
# 或者: from nodebox.graphics.Transform import rotate [as 别名]
def l_system(shape, position, generations, length, length_scale, angle, angle_scale, thickness_scale, premise, *rules):
if shape is None:
p = Path()
p.rect(0, -length/2, 2, length)
shape = p.asGeometry()
# Parse all rules
rule_map = {}
for rule_index, full_rule in enumerate(rules):
if len(full_rule) > 0:
if len(full_rule) < 3 or full_rule[1] != '=':
raise ValueError("Rule %s should be in the format A=FFF" % (rule_index + 1))
rule_key = full_rule[0]
rule_value = full_rule[2:]
rule_map[rule_key] = rule_value
# Expand the rules up to the number of generations
full_rule = premise
for gen in xrange(int(round(generations))):
tmp_rule = ""
for letter in full_rule:
if letter in rule_map:
tmp_rule += rule_map[letter]
else:
tmp_rule += letter
full_rule = tmp_rule
# Now run the simulation
g = Geometry()
stack = []
angleStack = []
t = Transform()
t.translate(position.x, position.y)
angle = angle
for letter in full_rule:
if letter == 'F': # Move forward and draw
transformed_shape = t.map(shape)
if isinstance(transformed_shape, Geometry):
g.extend(transformed_shape)
elif isinstance(transformed_shape, Path):
g.add(transformed_shape)
t.translate(0, -length)
elif letter == '+': # Rotate right
t.rotate(angle)
elif letter == '-': # Rotate left
t.rotate(-angle)
elif letter == '[': # Push state (start branch)
stack.append(Transform(t))
angleStack.append(angle)
elif letter == ']': # Pop state (end branch)
t = stack.pop()
angle = angleStack.pop()
elif letter == '"': # Multiply length
t.scale(1.0, length_scale / 100.0)
elif letter == '!': # Multiply thickness
t.scale(thickness_scale / 100.0, 1.0)
elif letter == ';': # Multiply angle
angle *= angle_scale / 100.0
elif letter == '_': # Divide length
t.scale(1.0, 1.0/(length_scale / 100.0))
elif letter == '?': # Divide thickness
t.scale(1.0/(thickness_scale / 100.0), 1.0)
elif letter == '@': # Divide angle
angle /= angle_scale / 100.0
return g