-
Notifications
You must be signed in to change notification settings - Fork 1
/
brush_stroke.py
63 lines (50 loc) · 1.85 KB
/
brush_stroke.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
import math
import numpy as np
# A wrapper class to hold all data which comprises a brush stroke
class BrushStroke:
# radius : positive, floating point number
def __init__(self, radius = 0, color = (0, 0, 0)):
if radius < 0.0:
self.radius = 0.0
return
self.radius = radius
self.color = color
self.points = []
self.dirs = []
self.pointStrokeRadii = []
self.spline = None
self.npr = None
# Returns the current radius of the BrushStroke
def getRadius(self):
return self.radius
# Sets the radius of the current BrushStroke to the parameter passed
# in, if r is negative, then radius is set to 0
def setRadius(self, r = 0):
if r < 0.0:
self.radius = 0.0
return
self.radius = r
# Returns the current color of the BrushStroke
def getColor(self):
return self.color
# Sets the color of the current BrushStroke to the parameter passed
# in, color should be a 3D tuple in the following format: (B, G, R)
def setColor(self, color):
self.color = color
# Adds the specified (x, y) point to the points list
def addPoint(self, x, y):
self.points.append((x, y))
def addDir(self, x, y):
self.dirs.append((x, y))
def addPointRadii(self, radii):
self.pointStrokeRadii.append(radii)
# Returns the last control point
def getLastControlPoint(self):
return self.points[-1]
def getLastDirection(self):
return self.dirs[-1]
def getPointRadii(self, index):
return self.pointStrokeRadii[index]
def getInterpolatedArray(self):
result = [0]*len(self.pointStrokeRadii)
return [math.ceil(self.pointStrokeRadii[i]-(i*self.pointStrokeRadii[i])/len(self.pointStrokeRadii)) for i in range(len(self.pointStrokeRadii)) ]