Pixelflut

Zeichne Pixel auf eine gemeinsame Zeichenfläche! Deine Pixel bleiben so lange stehen, bis jemand anderes etwas darüber zeichnet.

Die Zeichenfläche ist 256 Pixel breit und 144 Pixel hoch. Der Pixel links oben hat die Koordinaten (0, 0), der Pixel rechts unten hat die Koordinaten (255, 143). Verwende die Methode self.set_pixel(x, y, r, g, b), um einen Pixel zu setzen, wobei r, g und b jeweils die Intensität von rot, grün und blau im Bereich von 0 bis 255 angeben.

Du darfst natürlich auch die ganze Zeichenfläche überschreiben!

from pixelflut import Pixelflut
import math
import random

# 0 - no antialiasing
# 1 - 2x2 subpixels
# 2 - 4x4 subpixels
# 3 - 8x8 subpixels
# 4 - 16x16 subpixels 
# 5 - HERE BE DRAGONS
AA_LEVEL = 2
# 0 - no noise
# 16 - moderate noise
# 64 - terribly noisy noise
NOISE = 16

class Task(Pixelflut):
    def trace(self, x, y):
        fx = (x / 100.0)
        fy = (y / 100.0)
        fx += math.cos(fy) * 0.2
        fy += math.sin(fx) * 0.2
        f = 1.0
        if ((fx % 1.0) < 0.5) ^ ((fy % 1.0) < 0.5):
            f = 0.6
        return (x * f, (x + y) * f, y * f)
        
    def run(self):
        aa = 1 << AA_LEVEL
        for n in range(256*144):
            # calculate x and y from n
            x = n & 0xff
            y = n >> 8
            c = (0, 0, 0)
            
            # collect (2^AA_LEVEL)² subpixels
            for dy in range(aa):
                for dx in range(aa):
                    t = self.trace(x + dx / aa, y + dy / aa)
                    c = [c[i] + t[i] for i in range(3)]
                    
            # divide by (2^AA_LEVEL)²
            c = [c[i] / aa / aa for i in range(3)]
            
            # add some noise
            c = [c[i] + random.randint(0, NOISE) - (NOISE >> 1) for i in range(3)]
            self.set_pixel(x, y, *c)
Impressum und Datenschutz