def send(self, reverse=False): """ Draw the current colors in Turtle Graphics. Also send to Serial. """ colors = self.getColors() n = len(colors) if reverse: colors = reversed(colors) aveColor = Color() # Clear last time's drawings (dots). turtle.clear() # Draw the LEDs. for c in colors: turtle.dot(self.__DOT_SIZE, *c.getRgb()) turtle.fd(self.__SCALE) aveColor.add(c, clamp=False) # Update the background. (Causes an update.) turtle.bgcolor(*aveColor.scaled(0.4 * 1.0/n).getRgb()) # Retrace. turtle.right(180) turtle.fd(self.__SCALE*n) turtle.left(180) SendingBuffer.send(self, reverse=reverse)
def __init__(self, **kwargs): """Initializes the Turtle Graphics canvas.""" SendingBuffer.__init__(self, **kwargs) turtle.colormode(1) turtle.screensize(canvwidth=self.__SCALE * (self.GetSize() + 2), canvheight=self.__SCALE * 2) turtle.setup(height=self.__SCALE * 2 + 100) turtle.setworldcoordinates(-self.__SCALE, -self.__SCALE, self.__SCALE * (self.GetSize() + 1), self.__SCALE) turtle.bgcolor(0.1, 0.1, 0.1) turtle.penup() # no connecting line turtle.hideturtle() # no turtle on screen turtle.tracer(0, 0) # no animation turtle.setundobuffer(None) # no undo buffer
def __init__(self, sendingBuffer=None, reverse=False): PatternList.__init__(self) if sendingBuffer: self.__sendingBuffer = sendingBuffer else: self.__sendingBuffer = SendingBuffer() self.__reverse = reverse
def __init__(self, **kwargs): """ Initialize the Turtle Graphics canvas. """ SendingBuffer.__init__(self, **kwargs) turtle.colormode(1) turtle.screensize(canvwidth=self.__SCALE*(self.getSize()+2), canvheight=self.__SCALE*2) turtle.setup(height=self.__SCALE*2 + 100) turtle.setworldcoordinates(-self.__SCALE, -self.__SCALE, self.__SCALE*(self.getSize()+1), self.__SCALE) turtle.bgcolor(0.1, 0.1, 0.1) turtle.penup() # no connecting line turtle.hideturtle() # no turtle on screen turtle.tracer(0, 0) # no animation turtle.setundobuffer(None) # no undo buffer
class SendingPatternList(PatternList): """ A PatternList which also has a SendingBuffer, simplifying managing a strip which is to display only a set of Python-generated patterns. """ def __init__(self, sendingBuffer=None, reverse=False): PatternList.__init__(self) if sendingBuffer: self.__sendingBuffer = sendingBuffer else: self.__sendingBuffer = SendingBuffer() self.__reverse = reverse def setSender(self, sender): """ Set the DataSender.Sender object used by the SendingBuffer. """ self.__sendingBuffer.setSender(sender) def updateAndSend(self): """ If necessary: clear the sending buffer, apply all patterns to it, and send. @return whether an update (and send) was necessary """ if self.isChanged(): self.__sendingBuffer.clear() self.apply(self.__sendingBuffer) self.__sendingBuffer.send( reverse=self.__reverse) return True else: return False
def Send(self, reverse=False): """Draws the current colors in Turtle Graphics. Also sends to Serial.""" colors = self.GetColors() n = len(colors) if reverse: colors = reversed(colors) ave_color = Color() # Clear last time's drawings (dots). turtle.clear() # Draw the LEDs. for c in colors: turtle.dot(self.__DOT_SIZE, *c.GetRgb()) turtle.fd(self.__SCALE) ave_color.Add(c, clamp=False) # Update the background. (Causes an update.) turtle.bgcolor(*ave_color.Scaled(0.4 * 1.0 / n).GetRgb()) # Retrace. turtle.right(180) turtle.fd(self.__SCALE * n) turtle.left(180) SendingBuffer.Send(self, reverse=reverse)