from kivy.app import App
from kivy.lang import Builder
from kivy.clock import Clock
from kivy.uix.widget import Widget
from kivy.properties import ColorProperty
kv = """
<ColorBox>:
canvas:
Color:
rgba: self.color
Rectangle:
size: self.size
pos: self.pos
BoxLayout:
orientation: 'vertical'
Label:
text: 'Color Changing Boxes'
size_hint_y: None
height: dp(30)
Button:
id: start_button
text: 'Start'
size_hint_y: None
height: dp(48)
on_release: app.start_color_change()
GridLayout:
id: grid
spacing: dp(2)
cols: 10
"""
class ColorBox(Widget):
color = ColorProperty('gray')
class ScheduleChangeApp(App):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.widgets = None # use to hold iter of widgets
def build(self):
return Builder.load_string(kv)
def on_start(self):
for _ in range(100):
self.root.ids.grid.add_widget(ColorBox())
def start_color_change(self):
self.root.ids.start_button.disabled = True
self.widgets = iter(self.root.ids.grid.children[::-1])
self.next_color_change()
def next_color_change(self, *args):
try:
w = next(self.widgets)
w.color = 'yellow'
Clock.schedule_once(self.next_color_change, .1)
except StopIteration:pass
ScheduleChangeApp().run()
--
run
method has returned, you can query the statistics
member of the population (a neat.statistics.StatisticsReporter
object) to get the best genome(s) seen during the run. In this example, we take the ‘winner’ genome to be that returned by pop.statistics.best_genome()
.To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/DM4PR14MB6205E767D772CA54B3C7965DFD0A2%40DM4PR14MB6205.namprd14.prod.outlook.com.