Fenster bleibt schwarz

Hier werden alle anderen GUI-Toolkits sowie Spezial-Toolkits wie Spiele-Engines behandelt.
Antworten
Mr. Goldworthy
User
Beiträge: 1
Registriert: Sonntag 28. März 2021, 00:13

Ich habe ein Programm mit verschiedenen Sortieralgorithmen entwickelt. Den Grafikteil habe ich mit gPanel gemacht, doch jetzt will ich es auf einen Rasberry laden und muss es daher auf PyGame ändern. Doch obwohl ich (soweit ich weiss) alle nötigen Komponenten habe, bleibt der Screen schwarz. Kann jemand den Fehler erkennen?


screen = display.set_mode((1000, 800), SHOWN)
info = display.Info()
current_w = info.current_w
current_h = info.current_h
print(current_w, current_h)
font.init()
myfont = font.SysFont('Comic Sans MS', 30)
display.init()
x_spacing = 200
y_spacing = 100

def roundup(x):
if int(x) == x:
return x
return int(x + 1)

def mod(n, modul):
while n >= modul:
n -= modul
return n

...
...
...


def drawi(lists, reds, greens, names):
global x_spacing
global y_spacing
global t_spacing
ran = 0
for k in lists:
for f in k:
if f > ran:
ran = f
l = len(lists)
s = min((current_h - 3 * y_spacing) / 2, (current_w - 2 * x_spacing - x_spacing * (int(l / 2) - 1)) / int(l / 2))
ex = current_w / 2 - roundup(l / 2) / 2 * s - x_spacing * int(l / 2) / 2 - 1
ey = current_h - y_spacing - s
c = 0
draw.aaline(screen, [0, 0, 0], (0, (ey - 0.5 * y_spacing) / current_h),
((ex + s + 0.5 * x_spacing) / current_w, (ey - 0.5 * y_spacing) / current_h))
draw.aaline(screen, [0, 0, 0], ((ex + 2 * s + 1.5 * x_spacing) / current_w, (ey - 0.5 * y_spacing) / current_h),
(1, (ey - 0.5 * y_spacing) / current_h))
draw.aaline(screen, [0, 0, 0], ((ex + s + 0.5 * x_spacing) / current_w, 0),
((ex + s + 0.5 * x_spacing) / current_w, 1))
draw.aaline(screen, [0, 0, 0], ((ex + 2 * s + 1.5 * x_spacing) / current_w, 0),
((ex + 2 * s + 1.5 * x_spacing) / current_w, 1))
for k in range(len(lists)):
xsplit = len(lists[k]) * 2 - 1
numel = 0
basey = ey - mod(c, 2) * (s + y_spacing)
draw.rect(screen, [255, 255, 255], Rect(
(ex + int(c / 2) * (s + x_spacing)) / current_w, (basey - t_spacing - 5) / current_h,
(ex + int(c / 2) * (s + x_spacing) + 1.2 * s) / current_w, (basey) / current_h))
textsurface = myfont.render(names[k].split(":")[0], False, [0, 0, 0])
screen.blit(textsurface, (ex + int(c / 2) * (s + x_spacing) / current_w, (basey + s + t_spacing) / current_h))
textsurface = myfont.render(names[k].split(":")[1], False, [0, 0, 0])
screen.blit(textsurface, ((ex + int(c / 2) * (s + x_spacing)) / current_w, (basey - t_spacing) / current_h))

for el in lists[k]:
draw.rect(screen, [255, 255, 255], Rect(
(ex + int(c / 2) * (s + x_spacing) + numel * (s / xsplit) * 2) / current_w, (basey - 3) / current_h,
(ex + int(c / 2) * (s + x_spacing) + numel * (s / xsplit) * 2 + s / xsplit) / current_w,
(basey + s) / current_h))
Color = [0, 0, 0]
if numel == reds[k]:
Color = "red"
if numel == greens[k]:
Color = "green"
draw.rect(screen, Color, Rect(
(ex + int(c / 2) * (s + x_spacing) + numel * (s / xsplit) * 2) / current_w, (basey) / current_h,
(ex + int(c / 2) * (s + x_spacing) + numel * (s / xsplit) * 2 + s / xsplit) / current_w,
(basey + el / ran * s) / current_h))
numel += 1
c += 1
display.flip()


Vielen Dank im Vorhinein!
Grüsse Fabio
Benutzeravatar
__blackjack__
User
Beiträge: 13003
Registriert: Samstag 2. Juni 2018, 10:21
Wohnort: 127.0.0.1
Kontaktdaten:

@Mr. Goldworthy: Es ist nicht lauffähig, es gibt Code auf Modulebene der nicht nur Konstanten, Funktionen, und Klassen definiert, es wird ``global`` verwendet, ganz viele kurze kryptische Namen, Formatierung die es unnötig schwer macht zu sehen wo Anweisungen enden, ``for i in range(len(sequence))`` anti-pattern, oder kurz: Das mag ich nicht mal anfangen zu lesen.

`roundup()` scheint mir `math.ceil()` zu sein und `mod()` gibt es in Python als Operator ``%``.
“Most people find the concept of programming obvious, but the doing impossible.” — Alan J. Perlis
Antworten