added new script

This commit is contained in:
2021-07-30 14:57:03 +02:00
parent 3ee5ff00ca
commit 6bd0386a0b
+85
View File
@@ -0,0 +1,85 @@
#! /usr/bin/python3
# -*- coding: utf8 -*-
# load needed modules from luma
from luma.core.interface.serial import i2c, spi
from luma.core.render import canvas
from luma.oled.device import sh1106
from luma.core import lib
from luma.core.sprite_system import framerate_regulator
# load needed modules from RPi.GPIO
import RPi.GPIO as GPIO
# load needed modules from PIL
from PIL import ImageFont, ImageDraw, Image
# load more needed modules
import time
import sys
# load randommodules
from random import randint, gauss
#GPIO define pins
RST_PIN = 25 #Reset
CS_PIN = 8
DC_PIN = 24
serial = spi(device=0, port=0, bus_speed_hz = 8000000, transfer_size = 4096, gpio_DC = DC_PIN, gpio_RST = RST_PIN)
device_used = sh1106(serial, rotate=2) #sh1106
def matrix(device):
wrd_rgb = [
(154, 173, 154),
(0, 255, 0),
(0, 235, 0),
(0, 220, 0),
(0, 185, 0),
(0, 165, 0),
(0, 128, 0),
(0, 0, 0),
(154, 173, 154),
(0, 145, 0),
(0, 125, 0),
(0, 100, 0),
(0, 80, 0),
(0, 60, 0),
(0, 40, 0),
(0, 0, 0)
]
clock = 0
blue_pilled_population = []
max_population = device.width * 8
regulator = framerate_regulator(fps=10)
def increase_poppulation():
blue_pilled_population.append([randint(0, device.width), 0, gauss(1.2, 0.6)])
while True:
clock += 1
with regulator:
with canvas(device, dither=True) as draw:
for person in blue_pilled_population:
x, y, speed = person
for rgb in wrd_rgb:
if 0 <= y < device.height:
draw.point((x, y), fill=rgb)
y -= 1
person[1] += speed
if clock % 5 == 0 or clock % 3 == 0:
increase_poppulation()
while len(blue_pilled_population) > max_population:
blue_pilled_population.pop(0)
if __name__ == "__main__":
try:
matrix(device_used)
except KeyboardInterrupt:
pass
GPIO.cleanup()