12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- import math
- import time
- import Adafruit_GPIO.SPI as SPI
- import Adafruit_SSD1306
- from PIL import Image
- from PIL import ImageFont
- from PIL import ImageDraw
- RST = 24
- disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST)
- disp.begin()
- width = disp.width
- height = disp.height
- disp.clear()
- disp.display()
- image = Image.new('1', (width, height))
- font = ImageFont.load_default()
- draw = ImageDraw.Draw(image)
- text = 'Floppy Player'
- maxwidth, unused = draw.textsize(text, font=font)
- amplitude = height/4-10
- offset = height/2 - 4
- velocity = -2
- startpos = width
- pos = startpos
- while True:
-
- draw.rectangle((0,0,width,height), outline=0, fill=0)
-
- x = pos
- for i, c in enumerate(text):
-
- if x > width:
- break
-
- if x < -10:
- char_width, char_height = draw.textsize(c, font=font)
- x += char_width
- continue
-
- y = offset+math.floor(amplitude*math.sin(x/float(width)*2.0*math.pi))
-
- draw.text((x, y), c, font=font, fill=255)
-
- char_width, char_height = draw.textsize(c, font=font)
- x += char_width
-
- disp.image(image)
- disp.display()
-
- pos += velocity
-
- if pos < -maxwidth:
- break
-
- time.sleep(0.1)
|