-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathprocess_stroke_verts_linearly.py
More file actions
53 lines (40 loc) · 1.54 KB
/
process_stroke_verts_linearly.py
File metadata and controls
53 lines (40 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
import math
import copy
from .distance_formula import distance_formula
def process_stroke_verts_linearly(original_stroke_verts, speed):
"""
We have a group of vertices that represents a stroke,
but we need to know how much of that stroke to draw on each frame.
We use the given draw speed to calculate how much more of the stroke
to draw with each frame. The result is a list of vertex-groups to be
drawn with each frame
Parameters
----------
stroke_verts: list of vertices (integer pairs of x and y)
speed: float that is > 0.0
Returns
-------
framed_strokes: list of lists of vertices (x & y coordinate pairs)
"""
stroke_verts = copy.deepcopy(original_stroke_verts)
framed_strokes = [[stroke_verts[0]]]
remaining = speed
i = 1
while i < len(stroke_verts):
v1 = stroke_verts[i - 1]
v2 = stroke_verts[i]
distance = distance_formula(v1, v2)
x = v2[0] - v1[0]
y = v2[1] - v1[1]
if distance > remaining:
new_x = ((remaining / distance) * x) + v1[0]
new_y = ((remaining / distance) * y) + v1[1]
framed_strokes[-1].append([new_x, new_y])
framed_strokes.append(copy.deepcopy(framed_strokes[-1]))
stroke_verts[i - 1] = [new_x, new_y]
remaining = speed
else:
framed_strokes[-1].append(v2)
remaining -= distance
i += 1
return framed_strokes