class Style( Enum ): # need to make it tuple: foo = ( lambda x: pass, ) # otherwise foo becomes a method ranges = (lambda x: Buffer.Ranges(mul=(x % 4 + 1)), ) shades = (lambda x: Buffer.SixtyFourShadesOfGrey(mul=(x % 4 + 1)), ) checks = (lambda x: Buffer.Checkers(black=(x % 2 * 0x80), white=((1 - x % 2) * 0x80)), ) grades = (lambda x: Buffer.Gradient( heading={ 0: Direction.north, 1: Direction.west, 2: Direction.south, 3: Direction.east }[x % 4]), )
def buffer(self, off=0.): ret = Buffer() phase0, phase1 = 0., 0. amp0, amp1 = 1., 1. self.freq0 = (self.timers[2].sin() * 4. + 4. + 1.) / 4. * PI self.freq1 = (self.timers[3].sin() * 4. + 4. + 1.) / 4. * PI phase0 = off + math.cos(self.timers[0].cycle()) phase1 = off + math.cos(self.timers[1].cycle()) fun0 = Fun(amp=amp0, freq=self.freq0, phase=phase0) fun1 = Fun(amp=amp1, freq=self.freq1, phase=phase1) for y in range(ret.h): for x in range(ret.w): val0 = fun0(float(x / ret.w)) if fun0 else 0.0 val1 = fun1(float(y / ret.h)) if fun1 else 0.0 val = val0 if self.op == Operation.add: val = val0 / 2. val += val1 / 2. elif self.op == Operation.sub: val = val0 / 2. val -= val1 / 2. ret[x, y] = self.palette[self.palette.idx(val)] return ret
def draw(self): buffer = Buffer() ret = self.plasma.buffer(Fun(), Fun()) ret.mask(self.life.board, light=0x0) # ret.add (self.life.buffer(0x10,0x00) ) # ret.mul( 4.*self.timer.sin0(1.) ) return ret
class Fire(): def __init__(self, size=DefaultSize): self.state = Buffer(size=size + Size(0, 4)) random.seed() for x in range(self.state.w): self.state[x, self.state.h - 1] = 1 + random.randrange(12) pass def step(self): # for y in range(1,self.state.h): # for x in range(self.state.w-1,1,-1): # sum = self.state[x-1,y-1] + self.state[x,y-1] + self.state[x+1,y-1] + self.state[x,y-2] # self.state[x,y] = int( sum/4 ) for x in range(self.state.w): # self.state[x,self.state.h-1] = random.randrange( 8 ) + random.randrange( 8 ) self.state[x, self.state.h - 1] = random.randrange( 16) # + random.randrange( 8 ) for y in range(0, self.state.h - 1): for x in range(self.state.w): sum = self.state[x - 1, y + 1] + self.state[ x, y + 1] + self.state[x + 1, y + 1] + self.state[x, y + 2] self.state[x, y] = int(sum / 4.1) def buffer(self, mask=None): tmp = self.state.buffer(pos=(0, 0)) ret = tmp.palette(Palette.Polynom(0)) return ret
def buffer( self, off=0, ): ret = Buffer() depth = 1. - self.timers[0].linear() freq0, freq1 = TAU, TAU phase0, phase1 = 0., 0. amp0, amp1 = 1., 1. freq0 = PI + 1. * self.timers[0].sin0() * PI phase0 = self.timers[1].cycle() center = Position(3.5, 3.5) center.x += self.timers[1].sin() * -3. center.y += self.timers[2].sin(phase=PI) * -3. # debug(str(palette)) for y in range(ret.h): for x in range(ret.w): deltaMax = Tunnel.d(ret.w - 1, ret.h - 1, ctr=(0, 0)) delta = Tunnel.d(x, y, ctr=(center.x, center.y)) idx = self.palette.idx(self.radius * (delta / deltaMax) + depth + off) ret[x, y] = self.palette[idx % self.palette.length] if False and x == y: debug( "{:2d}/{:2d} d{} ∂{:.1f} idx #{:5.1f}/{:d} col 0x{:02x}" .format(x, y, depth + off, delta, idx, palette.length, palette[idx])) return ret
def draw(self, **params): pal = Palette.Sine() # pal = Palette.Polynom().append( Palette.Polynom().reverse() ) ret = Buffer() for y in range(ret.h): for x in range(ret.w): idx = pal.idx(y * ret.w + x + self.timer.linear()) ret[x, y] = pal[idx % pal.length] # ret.tile(self.mask,light=0x0) return ret
def draw(self,**params): ret = Buffer() off = self.timer.count=1 * PI phase = self.timer.cycle() freq0,freq1 = PI,PI phase0,phase1 = 0.,0. amp0, amp1 = 0.9,0.9 phase0 = self.timers[0].cycle() phase1 = self.timers[1].cycle() if self.debug: freq0 = PI freq1 = PI phase0 = PI phase1 = PI fun0 = Fun( amp=1., freq=PI, phase=phase0+PI) fun1 = Fun( amp=1., freq=PI, phase=phase1) offset = PI fun2 = Fun( amp=1., freq=PI, phase=phase0+offset+PI) fun3 = Fun( amp=1., freq=PI, phase=phase1+offset) back = self.plasma.buffer(off=1.0) front = self.plasma.buffer() ret.add(front.addMask(self.mask)) ret.add(back.addMask(self.mask.inverse())) return ret
def draw(self, **params): buffer = Buffer() return buffer
def buffer(self, alive=ALIVE, dead=DEAD): ret = Buffer() ret.addMask(self, light=alive) return ret
def buffer(self, light=LIGHT, dark=DARK): ret = Buffer(size=Size(self.w, self.h)) ret.addMask(self.tile.mask, light=light, pos=Position(self.tile.x, self.tile.y)) return ret
def start(self, **params): log("start clear") self.buffer = Buffer() return False
def __init__(self, size=DefaultSize): self.state = Buffer(size=size + Size(0, 4)) random.seed() for x in range(self.state.w): self.state[x, self.state.h - 1] = 1 + random.randrange(12) pass