<span style="font-size:18px;">#
#描绘类
class Sketch():
def __init__(self):
self.path = [];
self.currentPoint = None;
self.currentAngle = None;
#起始点的角度
@property
def startAngle(self):
return self.currentAngle;
@startAngle.setter
def startAngle(self, angle):
self.currentAngle = angle;
#给起始角度增加一个角度,相当于逆时针旋转
#顺时针时输入负值
def addAngle(self, angle):
#一般输入默认为角度制,需要转化为弧度
angle = angle /(180/3.1415926);
if self.currentAngle == None:
self.currentAngle = angle;
else:
self.currentAngle += angle;
#设置起始点的位置
def setStartPoint(self, point):
self.currentPoint = point;
#画曲线
def curve(self, span = 100, curveRate = 0):
if self.currentPoint == None:
if (self.currentAngle == None):
c = Curve([0, 0], 0, span, curveRate);
else:
c = Curve([0, 0], self.currentAngle, span, curveRate);
c.calcPath();
self.path.append(c.getPath());
else:
c = Curve(self.currentPoint, self.currentAngle, span, curveRate);
c.calcPath();
self.path.append(c.getPath());
self.currentPoint = c.getEndpoint();
self.currentAngle = c.getEndangle();
def getPath(self):
return self.path;
#连接各条曲线路径
def linkPath(self):
if self.path != []:
path = [];
for i in range(len(self.path)):
path_ = self.path[i];
for j in range(len(path_)):
path.append(path_[j]);
return path;
return self.path;
#</span>
<span style="font-size:18px;">#
def tmp8():
'''
a = Curve();
a.setStartPoint([0, 0]);
a.setSpan(100.5);
lSpace = a.lineSpacing();
print(lSpace);
#设置曲线的曲率
a.setCurveRate(1/50);
a.calcPath();
print(a.getPath());
print(a.getAngle());
'''
a = Sketch();
a.curve(200, 0);
a.curve(200, 1/50);
a.curve(200, -1/50);
print(a.linkPath());
#</span>
#
>>>
[[0, 0], [10.0, 0.0], [20.0, 0.0], [30.0, 0.0], [40.0, 0.0], [50.0, 0.0], [60.0, 0.0], [70.0, 0.0], [80.0, 0.0], [90.0, 0.0], [100.0, 0.0], [100.0, 0.0], [107.07, 7.07], [114.14, 14.14], [121.21, 21.21], [128.28, 28.28], [135.35, 35.35], [142.42, 42.42], [149.49, 49.49], [156.56, 56.56], [163.63, 63.63], [170.7, 70.7], [170.7, 70.7], [177.77, 63.63], [184.84, 56.56], [191.91, 49.49], [198.98, 42.42], [206.05, 35.35], [213.12, 28.28], [220.19, 21.21], [227.26, 14.14], [234.33, 7.07], [241.4, -0.0], [241.4, -0.0], [249.73, -5.53], [259.0, -9.29], [268.83, -11.13], [278.83, -10.98], [288.6, -8.85], [297.75, -4.82], [305.92, 0.95], [312.78, 8.22], [318.06, 16.71], [321.55, 26.08], [323.11, 35.96], [322.67, 45.95], [320.26, 55.65], [315.97, 64.68], [309.97, 72.68], [302.5, 79.33], [293.86, 84.36], [284.39, 87.57], [274.47, 88.84], [264.5, 88.11], [264.5, 88.11], [254.58, 89.38], [245.11, 92.59], [236.47, 97.62], [229.0, 104.27], [223.0, 112.27], [218.71, 121.3], [216.3, 131.0], [215.86, 140.99], [217.42, 150.87], [220.91, 160.24], [226.19, 168.73], [233.05, 176.0], [241.22, 181.77], [250.37, 185.8], [260.14, 187.93], [270.14, 188.08], [279.97, 186.24], [289.24, 182.48], [297.57, 176.95], [304.64, 169.88]]
-0.7854
0.8
>>>
def tmp8():
'''
a = Curve();
a.setStartPoint([0, 0]);
a.setSpan(100.5);
lSpace = a.lineSpacing();
print(lSpace);
#设置曲线的曲率
a.setCurveRate(1/50);
a.calcPath();
print(a.getPath());
print(a.getAngle());
'''
a = Sketch();
#两个参数是长度和曲率
a.curve(100, 0);
a.addAngle(45);
a.curve(100, 0);
a.addAngle(-90);
a.curve(100, 0);
a.curve(200, 1/50);
a.curve(200, -1/50);
print(a.linkPath());
print(a.startAngle);
a.startAngle = 0.8;
print(a.startAngle);
#
本节到此结束,欲知后事如何,请看下回分解。