本文整理汇总了Python中Canvas.drawLine方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.drawLine方法的具体用法?Python Canvas.drawLine怎么用?Python Canvas.drawLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Canvas
的用法示例。
在下文中一共展示了Canvas.drawLine方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import Canvas [as 别名]
# 或者: from Canvas import drawLine [as 别名]
class SonarScanner:
def __init__(self, sonarPort, motorPort):
self.motor = MotorScanner(motorPort)
self.sonar = Sonar(sonarPort)
self.canvas = Canvas()
#
# Function to scan from 0 to 360. Each step takes SCAN_STEP Radian
def scan(self):
# initialize data
data = []
# Go to start angle
self.motor.gotoAngle(SCANNER_START_ANGLE, 'cw')
nStep = int((SCANNER_END_ANGLE - SCANNER_START_ANGLE)/SCANNER_SCAN_STEP)
for i in range(0, nStep):
# go to angle
angle = SCANNER_START_ANGLE + SCANNER_SCAN_STEP*i
self.motor.gotoAngle(angle, 'ccw')
# read sonar data
z = self.sonar.getSmoothSonarDistance(0.05)
data.append(z)
# Back to zero angle
self.motor.gotoAngle(0, 'cw')
return data
def drawScanData(self, data):
for i in range(0, len(data)):
r = data[i]*SCANNER_DRAW_SCALE
th = SCANNER_START_ANGLE + SCANNER_SCAN_STEP*i
if(r > 200):
continue
x0 = int(SCANNER_DRAW_X0)
y0 = int(SCANNER_DRAW_Y0)
x1 = int(x0 + r*cos(th))
y1 = int(y0 + r*sin(th))
print radToDeg(th), r
print (x0, y0, x1, y1)
self.canvas.drawLine((x0, y0, x1, y1))