本文整理汇总了Python中brain.Brain.from_random方法的典型用法代码示例。如果您正苦于以下问题:Python Brain.from_random方法的具体用法?Python Brain.from_random怎么用?Python Brain.from_random使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类brain.Brain
的用法示例。
在下文中一共展示了Brain.from_random方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from brain import Brain [as 别名]
# 或者: from brain.Brain import from_random [as 别名]
def __init__(self, state, xy: (int, int), bearing: float, color, brain=None):
"""
Creates a germ given the canvas on which to create it, the coordinates, color, and initial velocity.
state - the world state.
xy - coordinates; location of the germ. To prevent sticking, must be between 0 and bounding area, _exclusively_.
color - a tkinter-viable color (can be hex)
"""
# The tag in tkinter representing all parts of this germ. Appended "str" to the front b/c tags don't work if they don't contain letters for some reason.
self.tag = "str" + str(id(self))
# 'Adopts' the canvas, and then creates itself on the canvas with the color given.
# Then moves itself to the given xy coordinate.
self.state = state
self.canvas = state.canvas
self.brain = Brain.from_random() if not brain else brain
self.bearing = bearing
self.body = self.canvas.create_oval(0, 0, 11, 11, fill=color, tags="germ")
self.canvas.move(self.body, *xy)
self.color = color # Saving this mostly just for debugging purposes.