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


Python Matrix.getItem方法代码示例

本文整理汇总了Python中Matrix.getItem方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.getItem方法的具体用法?Python Matrix.getItem怎么用?Python Matrix.getItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Matrix的用法示例。


在下文中一共展示了Matrix.getItem方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Breadboard

# 需要导入模块: import Matrix [as 别名]
# 或者: from Matrix import getItem [as 别名]
class Breadboard(object):
	"""represents a Breadboard.  It consists of a matrix (list of lists)
	of Location objects.  Each Location object is then pointed at
	a particular node object. The coordinate system is (x,-y) or column, 
	row in the matrix.  By default, it is powered like a DAQ powers a breadboard,
	going (bottom to top) ground,2.5V,2.5V,5V.  """
	
	def __init__(self): 
		self.numRows = 18
		self.numColumns = 63
		self.locMatrix = Matrix(self.numColumns,self.numRows)
		self.componentList = []
		self.rails= [0 , 2.5 , 2.5 , 5] #voltage rails. bottom to top. y = 17 16 1 0
		self.initializeLocations()		#assigns Location objects to each coordinate
		self.nodeCreation()				#assigns functional Nodes to proper Locations
		self.detailLocations()			#sets power rails and display flags
		
	def initializeLocations(self):
		"""creates Location objects at every spot in the local matrix.
		doesnt deal with nodes, voltages, or flags"""
		for x in range(self.numColumns):
			for y in range(self.numRows):
				self.locMatrix.setItem(x,y,Location(x,y))
	
	def getLocation(self,x,y):
		"""returns the Location object at a given x,y coordinate"""
		if x>=self.numColumns or y>=self.numRows:
			return None
		if (x<0 and x!=-1) or (y<0):
			return None
		return self.locMatrix.getItem(x,y)
		
	def assignNodeHoriz(self,x,y,number):
		"""assigns a Node object to a Location.
		If the previous x Location already has a Node, the current
		Location simply points to that previous one.
		Represents the fact that power at the rails is all the same node electrically"""
		if self.getLocation(x-1,y).Node.number !=-1:
			self.locMatrix.getItem(x,y).Node = self.locMatrix.getItem(x-1,y).Node
		else:
			self.locMatrix.getItem(x,y).Node = Node(number)
	
	def assignNodeVert(self,x,y,number):
		"""assigns a Node object to a Location.
		If the previous y Location already has a Node, the current
		Location simply points to that previous one.
		Represents the fact that power at each 'five family'
		vertical group is at the same electrical node"""
		if self.getLocation(x,y-1).Node.number !=-1:
			self.locMatrix.getItem(x,y).Node = self.locMatrix.getItem(x,y-1).Node
		else:
			self.locMatrix.getItem(x,y).Node=Node(number)
			
	def nodeCreation(self):
		"""goes through each x,y coordinate on the bb and assigns
		Node objects to all Locations that exist (not including the ones between pins)
		nodes are 0,1,2,3 for GND, power 1,	power 2, and power 3."""
		
		for i in range(self.width):
			self.assignNodeHoriz(i,0,1) #5 Volts
			self.assignNodeHoriz(i,1,2) # 2.5V
			self.assignNodeHoriz(i,16,3) # 2.5V
			self.assignNodeHoriz(i,17,0) # 0 is ground
		for y in range(3,8):
			for x in range(self.width):
				self.assignNodeVert(x,y,4*x)
		for y in range(10,15):
			for x in range(self.width):
				self.assignNodeVert(x,y,4*x+1)
	
	def detailLocations(self):
		"""assigns display flags, which are for coloring the GUI.
		Sets the Location objects at coordinates at which there are no pins 
		to Filled.
		adds voltage at the rails"""
				
		for x in range(self.numColumns):
			for y in range(self.numRows):
				if y==2: #fills pins between rows
					self.setFilled(x,y)
					self.setDisplayFlag(x,y,Location.BLUE_LINE)
				if y==15:
					self.setFilled(x,y)
					self.setDisplayFlag(x,y,Location.RED_LINE)
				if y==8:
					self.setFilled(x,y)
					self.setDisplayFlag(x,y,Location.CENTER_BOTTOM)
				if y==9:
					self.setFilled(x,y)
					self.setDisplayFlag(x,y,Location.CENTER_TOP)
				if (x+1)%6==0 and (y==0 or y==1 or y==16 or y==17): #fills pins between power fivesomes
					self.setFilled(x,y)
					self.setDisplayFlag(x,y,Location.BLANK)
				if y==0:	
					self.setNodeVoltage(x,y,self.rails[3])	#sets power at top rail
				if y==1:
					self.setNodeVoltage(x,y,self.rails[2])	#sets power at second from top rail
				if y==16:
					self.setNodeVoltage(x,y,self.rails[1])	#sets power at third from top rail
				if y==17:
#.........这里部分代码省略.........
开发者ID:ProjectArchive,项目名称:MinchsMagicStoreyLand,代码行数:103,代码来源:Breadboard.py


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