Exemple #1
0
# This Python program was automatically generated by Calico Jigsaw
# http://calicoproject.org

import Common
import Myro

t = .3
s1 = Myro.makeSound(calico.relativePath("../examples/sounds/closed-hat-trimmed.wav"))
s2 = Myro.makeSound(calico.relativePath("../examples/sounds/crash-trimmed.wav"))
s3 = Myro.makeSound(calico.relativePath("../examples/sounds/kick-trimmed.wav"))
s4 = Myro.makeSound(calico.relativePath("../examples/sounds/open-hat-trimmed.wav"))
s5 = Myro.makeSound(calico.relativePath("../examples/sounds/snare-trimmed.wav"))
for _ in xrange(3):
  for _ in xrange(4 * 2):
    s1.Play()
    Myro.wait(t)
  for _ in xrange(4):
    s1.Play()
    Myro.wait(t)
    s3.Play()
    Myro.wait(t)
  for _ in xrange(2):
    s1.Play()
    Myro.wait(t)
    s5.Play()
    Myro.wait(t)
    s1.Play()
    Myro.wait(t)
    s2.Play()
    Myro.wait(t)
  for _ in xrange(2):
    def curve(self, speedLeft, speedRight, duration): #TODO correct screwed up direction after curve
        #set temp
        tempX = self.__X
        tempY = self.__Y

        #set scale
        greaterSpeed = 0
        lesserSpeed = 0
        if (abs(speedLeft) > abs(speedRight)):
            greaterSpeed = speedLeft
            lesserSpeed = speedRight
        elif (abs(speedRight) > abs(speedLeft)):
            greaterSpeed = speedRight
            lesserSpeed = speedLeft
        else:
            duration = (duration / self.Speed) * speedLeft
            self.goForward(duration)
            return

        #move robot
        Myro.robot.motors(speedLeft, speedRight)
        Myro.wait(abs(duration))
        Myro.robot.stop()

        stretch = (1 / self.__Scale) * (greaterSpeed / lesserSpeed)

        divisible = duration // self.__Scale

        Xs = []
        Ys = []
        tempXs = []
        tempYs = []

        overAfterPoint = False

        timesOver = 1
        maxAmount = tempX + divisible + self.__Scale
        minAmount = self.__X + self.__Scale
        #stretch
        for x in xrange(minAmount, maxAmount, self.__Scale):
            #get point
            try:
                y = stretch * sqrt(1 - pow(((x - self.__X - stretch) / stretch), 2)) + self.__Y
                overAfterPoint = True
            except ValueError: #Support for > half circle turns
                if overAfterPoint == True:
                    try:
                        x -= (timesOver * self.__Scale + timesOver)
                        y = -stretch * (sqrt(1 - pow(((x - self.__X - stretch) / stretch), 2))) + self.__Y
                        timesOver += 1
                        maxAmount -= x
                    except ValueError:
                        continue
                else:
                    continue
            #find out if it is a plottable point
            tempXs.append(x)
            tempYs.append(y)

        theta = 90 - degrees(atan(self.getSlope()))

        sina = sin(theta)
        cosa = cos(theta)
    
        for i in xrange(0, len(tempXs)):
            pX = self.__X - self.__MidpointX
            pY = self.__Y - self.__MidpointY

            tempXs[i] = (cosa * pX - sina * pY) + tempXs[i]
            tempYs[i] = (sina * pX + cosa * pY) + tempYs[i]

            if (tempXs[i] % self.__Scale == 0 and tempYs[i] % self.__Scale == 0):
                Xs.append(tempXs[i])
                Ys.append(tempYs[i])

        #Plot the points
        for i in xrange(0, len(Xs)):
            try:
                self.Plot[int(Xs[i])][int(Ys[i])] = MemoryType.Visited
            except IndexError:
                print("Error: Ran out of space. Expanding the plot.\r\n")
                self.ExpandPlot(5)
                i -= 1

        multiplyBy = 1.0 / self.__Scale

        if (stretch >= 0):
            try:
                self.__X = Xs[len(Xs) - 1]
                self.__Y = Ys[len(Ys) - 1]
            except IndexError:
                print("Error: No measurable progression.\r\n")
                return

        else:
            try:
                self.__X = Xs[0]
                self.__Y = Ys[0]
            except IndexError:
                print("Error: No measurable progression.\r\n")
                return

        #add it to the direction using derivative
        slope = 0
        try:
            slope = (tempX - self.__X)/ (stretch * sqrt(1 - (pow(tempX - self.__X, 2)/pow(stretch, 2))))
        except ValueError:
            if (stretch < 0):
                self.__TowardsX = self.__X
                self.__TowardsY = self.__Y + 1
                self.X = self.__X - self.__MidpointX
                self.Y = self.__Y - self.__MidpointY
                return
            else:
                self.__TowardsX = self.__X
                self.__TowardsY = self.__Y - 1
                self.X = self.__X - self.__MidpointX
                self.Y = self.__Y - self.__MidpointY
                return

        theta = 90 - degrees(atan(self.getSlope()))

        sina = sin(theta)
        cosa = cos(theta)

        pX = tempX - self.__MidpointX
        pY = tempY - self.__MidpointY

        if (stretch >= 0):
            newY = slope * (self.__X + 1 - tempX) + tempY
        else:
            newY = slope * (self.__X - 1 - tempX) + tempY

        self.__TowardsX = (cosa * pX - sina * pY) + tempX
        self.__TowardsY = (sina * pX + cosa * pY) + newY

        self.X = self.__X - self.__MidpointX
        self.Y = self.__Y - self.__MidpointY
Exemple #3
0
import Myro
import Rhyduino

with Rhyduino.Arduino("COM5") as arduino:
    arduino.Connect()
    pin = arduino.DigitalPins[13]
    pin.SetPinMode(Rhyduino.PinMode.Output)

    count = 0
    for t in Myro.timer(10):
        if count % 2 == 0:
            pin.SetPinValue(Rhyduino.DigitalPinValue.Low)
        else:
            pin.SetPinValue(Rhyduino.DigitalPinValue.High)
        count += 1
        Myro.wait(1)
    def goForward(self, duration):
        #if line is up and down
        if (self.__TowardsX - self.__X == 0):
            Myro.robot.motors(self.Speed, self.Speed)
            Myro.wait(abs(duration))
            Myro.robot.stop()
            #get the amount of points forward
            divisible = duration // self.__Scale

            if (self.__TowardsY > self.__Y):
                #add them to the direction
                self.__TowardsY += divisible
                tempY = self.__Y

                #add them to plot
                for y in xrange(self.__Y + self.__Scale, divisible + tempY + self.__Scale):
                    if (y % self.__Scale == 0):
                        try:
                            self.Plot[(int) (self.__X)][y] = MemoryType.Visited
                        except IndexError:
                            print("Error: Ran out of space. Expanding the plot\r\n")
                            self.ExpandPlot(5)
                            y -= 1

                #increase y
                self.__Y += divisible
                self.Y += divisible
                return

            else:
                #subtract them from the direction
                self.__TowardsY -= divisible
                tempY = self.__Y

                #add them to plot
                for y in xrange(self.__Y - divisible,  tempY + self.__Scale):
                    if (y % self.__Scale == 0):
                        try:
                            self.Plot[(int) (self.__X)][y] = MemoryType.Visited
                        except IndexError:
                            print("Error: Ran out of space. Expanding the plot\r\n")
                            self.ExpandPlot(5)
                            y -= 1

                #increase y
                self.__Y -= divisible
                self.Y -= divisible
                return


        #calc slope
        slope = (self.__TowardsY - self.__Y) / (self.__TowardsX - self.__X)
        tempX = self.__X
        tempY = self.__Y

        #go forward
        Myro.robot.motors(self.Speed, self.Speed)
        Myro.wait(abs(duration))

        Myro.robot.stop()

        #get the amount of points forward
        divisible = duration // self.__Scale

        #add them to the direction
        self.__TowardsX += divisible
        self.__TowardsY += divisible
        divisible = duration / self.__Scale

        Xs = []
        Ys = []

        if (slope >= 0):
            #positive slope
            for x in xrange(self.__X + self.__Scale, (tempX + divisible) + self.__Scale, self.__Scale):
                #get point
                y = (slope * (x - self.__X)) + self.__Y
                #find out if it is a plottable point
                if (y % self.__Scale == 0.0):
                    Xs.append(int(x))
                    Ys.append(int(y))

        else:
            #negative slope
            for x in xrange((tempX - divisible), self.__X, self.__Scale):
                #get point
                y = (slope * (x - self.__X)) + self.__Y
                #find out if it is a plottable point
                if (y % self.__Scale == 0.0):
                    Xs.append(int(x))
                    Ys.append(int(y))

        #Plot the points
        for i in xrange(0, len(Xs)):
            try:
                self.Plot[Xs[i]][Ys[i]] = MemoryType.Visited
            except IndexError:
                print("Error: Ran out of space. Expanding the plot.\r\n")
                self.ExpandPlot(5)
                i -= 1

        multiplyBy = 1.0 / self.__Scale

        if (slope >= 0):
            try:
                self.__X = Xs[len(Xs) - 1]
                self.__Y = Ys[len(Ys) - 1]
            except IndexError:
                print("Error: No measurable progression.\r\n")

        else:
            try:
                self.__X = Xs[0]
                self.__Y = Ys[0]
            except IndexError:
                print("Error: No measurable progression.\r\n")

        self.X = self.__X - self.__MidpointX
        self.Y = self.__Y - self.__MidpointY