try: refTime = time() lastFrameNo = 0 while True: drawTime = time() frameTime = drawTime - refTime frameNo = int(frameTime * frameRate) if frameNo - lastFrameNo > 1: print "Skipped %d frame(s)" % (frameNo - lastFrameNo - 1) lastFrameNo = frameNo demoSel = int(frameTime / 20) demoSel %= 30 if demoSel == 1: demo_text.draw(fb, frameTime) else: demo_rainbow.draw(fb, frameTime) lm.put(fb) # Limit update speed to frameRate nextTime = refTime + (int(frameRate * frameTime) + 1) / frameRate frameDelta = nextTime - time() if frameDelta > 1e-9: sleep(frameDelta) finally: print "TEST ENDING" blank = ImageDraw.Draw(fb) blank.rectangle((0, 0, fb.size[0], fb.size[1]), fill=(0, 0, 0)) lm.put(fb)
while True: drawTime = time() frameTime = drawTime - refTime frameNo = int(frameTime * frameRate + 0.5) if frameNo - lastFrameNo > 1: print "Skipped %d frames" % (frameNo - lastFrameNo) lastFrameNo = frameNo backdropPosition = int((backdropSpeed * frameTime) % backdrop.size[0]) backdropCrop = backdrop.offset(backdropPosition, 0).crop( (0, 0, SIZE[0], SIZE[1])) fb.paste(backdropCrop) position = int(-(textSpeed * frameTime) % (textSize[0] + 2)) textCrop = textimg.offset(position, 0).crop((0, 0, SIZE[0], SIZE[1])) comp = ImageChops.multiply(textCrop, gradient) comp = Image.composite(comp, fb, textCrop.convert('L')) lm.put(comp) # Limit update speed to frameRate nextTime = refTime + (int(frameRate * frameTime) + 1) / frameRate frameDelta = nextTime - time() if frameDelta > 1e-9: sleep(frameDelta) finally: print "TEST ENDING" blank = ImageDraw.Draw(fb) blank.rectangle((0, 0, SIZE[0], SIZE[1]), fill=(0, 0, 0)) lm.put(fb)
lastFrameNo = 0 while True: drawTime = time() frameTime = drawTime - refTime frameNo = int(frameTime * frameRate + 0.5) if frameNo - lastFrameNo > 1: print "Skipped %d frames" % (frameNo - lastFrameNo) lastFrameNo = frameNo backdropPosition = int((backdropSpeed * frameTime) % backdrop.size[0]) backdropCrop = backdrop.offset(backdropPosition, 0).crop((0, 0, SIZE[0], SIZE[1])) fb.paste(backdropCrop) position = int(-(textSpeed * frameTime) % (textSize[0] + 2)) textCrop = textimg.offset(position, 0).crop((0, 0, SIZE[0], SIZE[1])) comp = ImageChops.multiply(textCrop, gradient) comp = Image.composite(comp, fb, textCrop.convert('L')) lm.put(comp) # Limit update speed to frameRate nextTime = refTime + (int(frameRate * frameTime) + 1) / frameRate frameDelta = nextTime - time() if frameDelta > 1e-9: sleep(frameDelta) finally: print "TEST ENDING" blank = ImageDraw.Draw(fb) blank.rectangle((0, 0, SIZE[0], SIZE[1]), fill=(0, 0, 0)) lm.put(fb)
frameTime = drawTime - refTime frameNo = int(frameTime * frameRate + 0.5) if frameNo - lastFrameNo > 1: print "Skipped %d frames" % (frameNo - lastFrameNo) lastFrameNo = frameNo # draw sine wave for row in range(0, SIZE[1]): for col in range(0, SIZE[0]): fb.putpixel( (col, row), sin_table[(col + x_offset) % x_steps][SIZE[1] - 1 - row] ) x_offset = (x_offset + 1) % x_steps # push to frame buffer lm.put(fb) # Limit update speed to frameRate nextTime = refTime + (int(frameRate * frameTime) + 1) / frameRate frameDelta = nextTime - time() if frameDelta > 1e-9: sleep(frameDelta) finally: print "Done drawing sine waves for now :)" blank = ImageDraw.Draw(fb) blank.rectangle((0, 0, SIZE[0], SIZE[1]), fill=(0, 0, 0)) lm.put(fb)
""" if (mover <= 28): mover+=1 else: mover=0 if (rowCount == 5) and (mover == 28): rowCount=0 elif(mover == 28): rowCount+=1 else: print "something went wrong" """ lm.put(fb) # draw to screen if (playerPos["x"] == stickPos["x"]) and ( playerPos["y"] == stickPos["y"]): # check for collision between player and stick placeStick() pLength += 1 if (playerPos["x"] < stickPos["x"]): moveDirec = Direction.RIGHT moveDec() # pHist.insert(0, (playerPos["y"], playerPos["x"])) # pHist = pHist[0:pLength] # playerPos["x"] += 1 elif (playerPos["y"] < stickPos["y"]): # pHist.insert(0, (playerPos["y"], playerPos["x"]))