from cozmo_fsm import *
import matplotlib.pyplot as plt

class Histogram(StateMachineProgram):
    def __init__(self):
        super().__init__(cam_viewer=False)

    class PlotIntensity(StateNode):
        def start(self,event=None):
            super().start()
            img = np.array(self.robot.world.latest_image.raw_image)
            plt.imshow(img)
            plt.figure()
            pixels = tuple(img[:,:,1].flat)
            plt.hist(pixels, bins=25)
            plt.show()
            self.post_completion()

    def setup(self):
        """
            StateNode() =T(2)=> self.PlotIntensity()
        """
        
        # Code generated by genfsm on Fri Feb 21 04:34:01 2020:
        
        statenode1 = StateNode() .set_name("statenode1") .set_parent(self)
        plotintensity1 = self.PlotIntensity() .set_name("plotintensity1") .set_parent(self)
        
        timertrans1 = TimerTrans(2) .set_name("timertrans1")
        timertrans1 .add_sources(statenode1) .add_destinations(plotintensity1)
        
        return self
