^
05_hopehely_terhatas.py
<<
>>
Run
import pyxel import math import random pyxel.init(255,255) class Hopehely: def __init__(self): self.x = random.randint(0, 255) self.y = random.randint(0, 255) self.r = random.randint(2, 8) def draw(self): szin = 15 # fehér x = self.x y = self.y r = self.r s = math.sqrt(2) * r / 2 pyxel.line(x+r, y , x-r, y , szin) pyxel.line(x , y-r, x , y+r, szin) pyxel.line(round(x-s), round(y-s), round(x+s), round(y+s), szin) pyxel.line(round(x-s), round(y+s), round(x+s), round(y-s), szin) def update(self): # ***** Oldd meg, hogy a kisebb (távolabbi) hópelyhek látszólag # lassabban menjenek lefelé, ezzel egy térhatást állítva elő # (ez a "parallax") self.y = (self.y + 1) % 255 hopelyhek = [Hopehely() for i in range(30)] def update(): for h in hopelyhek: h.update() def draw(): pyxel.cls(1) # sötétkék for h in hopelyhek: h.draw() pyxel.run(update, draw)
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15