Aug-17-2020, 02:26 AM
(This post was last modified: Aug-17-2020, 02:26 AM by kalihotname.)
I try to draw the vertical line on the screen here is my code
From the code I import the picture and I scrolling the picture and I want to create the vertical line on the middle of the screen but this line must stay still at the middle of the screen not scrolling with the picture (my screen size 128*128). Any advice ? Thank You
import time
import random
import os.path
import socket
import sys
from demo_opts import get_device
from luma.core.virtual import viewport
from luma.core.render import canvas
from PIL import Image
from PIL import ImageDraw
UDP_IP = "0.0.0.0"
UDP_PORT = 7015
sock = socket.socket(socket.AF_INET, #INTERNET
socket.SOCK_DGRAM) #UDP
sock.bind((UDP_IP, UDP_PORT))
print ("Start")
def scroll_right(virtual, pos):
x, y = pos
if virtual.width > device.width:
while x < virtual.width - device.width:
(data, addr) = sock.recvfrom(1024) # buffer size
d = int(data.decode('utf-8'))
print("message:", d)
virtual.set_position((x, y))
x = d * 2.2
return (x, y)
def main():
while True:
img_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
'images', 'test.png'))
pixel_art = Image.open(img_path).convert(device.mode)
draw = ImageDraw.ImageDraw(pixel_art)
w, h = pixel_art.size
shape = [(40, 30), (w - 64, h - 64)]
virtual = viewport(device, width=w, height=h)
draw.line(shape , fill="white", width = 0)
virtual.display(pixel_art)
pos = (1100, 0)
pos = scroll_right(virtual, pos)
if __name__ == "__main__":
try:
device = get_device()
main()
except KeyboardInterrupt:
passFrom the code I import the picture and I scrolling the picture and I want to create the vertical line on the middle of the screen but this line must stay still at the middle of the screen not scrolling with the picture (my screen size 128*128). Any advice ? Thank You
