add accessor methods in shapes to get vars
This commit is contained in:
parent
0ce01c7b58
commit
5678df7dbb
@ -22,3 +22,9 @@ class Circle(Shape):
|
|||||||
return ([1, 0, -1], [0, 1, 0])
|
return ([1, 0, -1], [0, 1, 0])
|
||||||
elif ptNum == 4:
|
elif ptNum == 4:
|
||||||
return ([1, 0, 0], [0, 1, -1])
|
return ([1, 0, 0], [0, 1, -1])
|
||||||
|
|
||||||
|
def getCenter(self):
|
||||||
|
return (self.vars[0], self.vars[1])
|
||||||
|
|
||||||
|
def getRadius(self):
|
||||||
|
return self.vars[2]
|
||||||
|
6
Line.py
6
Line.py
@ -18,3 +18,9 @@ class Line(Shape):
|
|||||||
return ([0, 0, 1, 0], [0, 0, 0, 1])
|
return ([0, 0, 1, 0], [0, 0, 0, 1])
|
||||||
elif ptNum == 2:
|
elif ptNum == 2:
|
||||||
return ([0.5, 0, 0.5, 0], [0, 0.5, 0, 0.5])
|
return ([0.5, 0, 0.5, 0], [0, 0.5, 0, 0.5])
|
||||||
|
|
||||||
|
def getPt(self, ptNum):
|
||||||
|
if ptNum == 0:
|
||||||
|
return (self.vars[0], self.vars[1])
|
||||||
|
elif ptNum == 1:
|
||||||
|
return (self.vars[2], self.vars[3])
|
||||||
|
@ -89,19 +89,22 @@ class SketchWidget:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def drawLine(self, shape, size):
|
def drawLine(self, shape, size):
|
||||||
self.drawFilledLine(shape.vars[0], shape.vars[1],
|
pt0 = shape.getPt(0)
|
||||||
shape.vars[2], shape.vars[3], size)
|
pt1 = shape.getPt(1)
|
||||||
|
self.drawFilledLine(pt0[0], pt0[1], pt1[0], pt1[1], size)
|
||||||
|
|
||||||
def drawCircle(self, shape, size):
|
def drawCircle(self, shape, size):
|
||||||
steps = 16
|
steps = 16
|
||||||
step = 2 * math.pi / steps
|
step = 2 * math.pi / steps
|
||||||
|
center = shape.getCenter()
|
||||||
|
rad = shape.getRadius()
|
||||||
for i in range(steps + 1):
|
for i in range(steps + 1):
|
||||||
angle = i * step
|
angle = i * step
|
||||||
next_angle = (i + 1) * step
|
next_angle = (i + 1) * step
|
||||||
x0 = shape.vars[0] + shape.vars[2] * math.cos(angle)
|
x0 = center[0] + rad * math.cos(angle)
|
||||||
y0 = shape.vars[1] + shape.vars[2] * math.sin(angle)
|
y0 = center[1] + rad * math.sin(angle)
|
||||||
x1 = shape.vars[0] + shape.vars[2] * math.cos(next_angle)
|
x1 = center[0] + rad * math.cos(next_angle)
|
||||||
y1 = shape.vars[1] + shape.vars[2] * math.sin(next_angle)
|
y1 = center[1] + rad * math.sin(next_angle)
|
||||||
self.drawFilledLineUncapped(x0, y0, x1, y1, size)
|
self.drawFilledLineUncapped(x0, y0, x1, y1, size)
|
||||||
self.drawFilledCircle(x0, y0, size, 8)
|
self.drawFilledCircle(x0, y0, size, 8)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user