当前位置: 首页>>代码示例>>Python>>正文


Python Canvas.drawLine方法代码示例

本文整理汇总了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))
开发者ID:pedrokost,项目名称:robotics,代码行数:49,代码来源:sonarScanner.py


注:本文中的Canvas.drawLine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。