Ejemplo n.º 1
0
class PerlinScene(object):
	def __init__(self, lp, wave=False):
		self.wave = wave
		self.aa = Antialiaser(lp)

		random.seed(45)

		layers = [
			Layer((2 ** i) + 1, 0.5 / (2 ** i))
			for i in range(1, 6)
		]

		if wave:
			self.plasma = [
				[
					0.5 + sum([layer.sample_norm(x / 36.0, y / 18.0) for layer in layers])
					for x in range(0, 36)
				]
				for y in range(0, 18)
			]
		else:
			self.plasma = [
				[
					0.5 + sum([layer.sample_norm(x / 18.0, y / 18.0) for layer in layers])
					for x in range(0, 18)
				]
				for y in range(0, 18)
			]

	def section_tick(self, beat, red, green):
		for y in range(0, 18):
			for x in range(0, 18):
				if self.wave:
					xadj = x + 9 + 9 * math.sin(y * 0.2 + beat * 0.5)
				else:
					xadj = x

				val = (beat + 4) / 20 - self.plasma[y][int(xadj)]
				if 0 <= val < 1:
					intensity = math.cos(val * math.pi)
				else:
					intensity = 0
				self.aa.screen[y][x] = (intensity * red, intensity * green)

	def tick(self, pattern, beat):
		if beat < 16:
			self.section_tick(beat, 0, 1)
		elif beat < 32:
			self.section_tick(beat - 16, 1, 0)
		elif beat < 48:
			self.section_tick(beat - 32, 0.5, 1)
		else:
			self.section_tick(beat - 48, 1, 0.5)

		self.aa.render()
Ejemplo n.º 2
0
class CometScene(object):
	def __init__(self, lp):
		self.aa = Antialiaser(lp)

	def tick(self, pattern, beat):
		self.aa.clear()

		for x in range(2, 16):
			b = beat - x / 4
			head_y = max(2, 14 - (b / 4)) - 2 * math.sin(b * math.pi / 4)
			greenness = (16 - x) / 16.0
			draw.disc(self.aa.screen, x, head_y, greenness * 2, (1, greenness))

		self.aa.render()
Ejemplo n.º 3
0
class CometScene(object):
    def __init__(self, lp):
        self.aa = Antialiaser(lp)

    def tick(self, pattern, beat):
        self.aa.clear()

        for x in range(2, 16):
            b = beat - x / 4
            head_y = max(2, 14 - (b / 4)) - 2 * math.sin(b * math.pi / 4)
            greenness = (16 - x) / 16.0
            draw.disc(self.aa.screen, x, head_y, greenness * 2, (1, greenness))

        self.aa.render()
Ejemplo n.º 4
0
class RecedeScene(object):
	def __init__(self, lp):
		self.aa = Antialiaser(lp)

	def tick(self, pattern, beat):
		self.aa.clear()

		greenness = 0.5 - 0.5 * math.cos((beat - 2) * math.pi / 8.0)
		redness = min(1, beat / 2)
		size = 4 * (48 - beat) / 48.0

		if size > 0:
			draw.disc(self.aa.screen, 11, 6, size, (redness, greenness))

		self.aa.render()
Ejemplo n.º 5
0
class RecedeScene(object):
    def __init__(self, lp):
        self.aa = Antialiaser(lp)

    def tick(self, pattern, beat):
        self.aa.clear()

        greenness = 0.5 - 0.5 * math.cos((beat - 2) * math.pi / 8.0)
        redness = min(1, beat / 2)
        size = 4 * (48 - beat) / 48.0

        if size > 0:
            draw.disc(self.aa.screen, 11, 6, size, (redness, greenness))

        self.aa.render()
Ejemplo n.º 6
0
class PerlinScene(object):
    def __init__(self, lp, wave=False):
        self.wave = wave
        self.aa = Antialiaser(lp)

        random.seed(45)

        layers = [Layer((2**i) + 1, 0.5 / (2**i)) for i in range(1, 6)]

        if wave:
            self.plasma = [[
                0.5 + sum([
                    layer.sample_norm(x / 36.0, y / 18.0) for layer in layers
                ]) for x in range(0, 36)
            ] for y in range(0, 18)]
        else:
            self.plasma = [[
                0.5 + sum([
                    layer.sample_norm(x / 18.0, y / 18.0) for layer in layers
                ]) for x in range(0, 18)
            ] for y in range(0, 18)]

    def section_tick(self, beat, red, green):
        for y in range(0, 18):
            for x in range(0, 18):
                if self.wave:
                    xadj = x + 9 + 9 * math.sin(y * 0.2 + beat * 0.5)
                else:
                    xadj = x

                val = (beat + 4) / 20 - self.plasma[y][int(xadj)]
                if 0 <= val < 1:
                    intensity = math.cos(val * math.pi)
                else:
                    intensity = 0
                self.aa.screen[y][x] = (intensity * red, intensity * green)

    def tick(self, pattern, beat):
        if beat < 16:
            self.section_tick(beat, 0, 1)
        elif beat < 32:
            self.section_tick(beat - 16, 1, 0)
        elif beat < 48:
            self.section_tick(beat - 32, 0.5, 1)
        else:
            self.section_tick(beat - 48, 1, 0.5)

        self.aa.render()
Ejemplo n.º 7
0
class IrisScene(object):
    def __init__(self, lp):
        self.aa = Antialiaser(lp)

    def tick(self, pattern, beat):
        self.aa.clear()

        redr = (beat - 32) * 0.8

        draw.disc(self.aa.screen, 9, 9, redr, (1, 0))

        if beat > 48:
            blackr = max(0, (beat - 48) * 0.8)
            draw.disc(self.aa.screen, 9, 9, blackr, (0, 0))

        self.aa.render()
Ejemplo n.º 8
0
class DrumScene(object):
	def __init__(self, lp, background = False):
		self.lp = lp
		self.aa = Antialiaser(lp)
		self.background = background

	SEQ = [
		1,0,3,0,2,0,3,0,0,0,3,0,2,0,3,0,
		1,0,3,0,2,0,3,0,0,0,3,0,4,4,5,5,
	]

	def tick(self, pattern, beat):
		self.aa.clear()
		if self.background:
			r = -math.sin(math.pi * beat / 16.0) * 12

			for y in range(0, 18):
				for x in range(0, 18):
					if r > 0:
						dist = math.sqrt(x * x + (16 - y) * (16 - y))
						if dist < r:
							self.aa.screen[y][x] = (0, 1 - dist / r)
					elif r < 0:
						dist = math.sqrt((16 - x) * (16 - x) + y * y)
						if dist < -r:
							self.aa.screen[y][x] = (1 - dist / -r, 0)

		self.aa.render(commit=False)

		if pattern >= 0:
			ix = DrumScene.SEQ[int(beat) % 32]

			bright = beat % 1
			bright = int(bright * 4) ^ 3

			if ix == 1:
				self.lp.screen[5][2] = 0x01 * bright
			elif ix == 2:
				self.lp.screen[3][2] = 0x11 * bright
			elif ix == 3:
				self.lp.screen[3][5] = 0x10 * bright
			elif ix == 4:
				self.lp.screen[5][5] = 0x01 * bright
			elif ix == 5:
				self.lp.screen[6][6] = 0x01 * bright

		self.lp.commit()
Ejemplo n.º 9
0
class CircleCometScene(object):
	def __init__(self, lp):
		self.aa = Antialiaser(lp)

	def tick(self, pattern, beat):
		self.aa.clear()

		for i in range(16, 2, -1):
			b = beat - i * 0.8
			a = math.pi * b / 12
			r = 7 - (beat / 16)
			x = 9 + r * math.sin(a)
			y = 9 + r * math.cos(a)
			greenness = (16 - i) / 16.0
			draw.disc(self.aa.screen, x, y, greenness * 2, (1, greenness))

		self.aa.render()
Ejemplo n.º 10
0
class DivisionScene(object):
    def __init__(self, lp):
        self.aa = Antialiaser(lp)

        self.cells = [Cell(0.5, 1), Cell(1, 0.5), Cell(0.5, 1), Cell(1, 0.5)]

    def tick(self, pattern, beat):
        r1 = min(beat / 4, 4.5)

        if beat < 32:
            r2 = 0
        elif beat < 56:
            r2 = (beat - 32) / 4
        else:
            r2 = (beat - 32) / 4 + (beat - 56) * 0.6
            r1 += (beat - 56) * 0.6

        rota = math.pi * beat / 16

        c1x = 9 - r1 * math.sin(rota)
        c1y = 9 - r1 * math.cos(rota)
        c2x = 9 + r1 * math.sin(rota)
        c2y = 9 + r1 * math.cos(rota)

        dx = r2 * math.cos(rota)
        dy = r2 * math.sin(rota)

        self.cells[0].set_position(c1x - dx, c1y - dy)
        self.cells[1].set_position(c1x + dx, c1y + dy)

        self.cells[2].set_position(c2x - dx, c2y - dy)
        self.cells[3].set_position(c2x + dx, c2y + dy)

        if beat < 2:
            fadeyness = beat / 2  # APPROACHING DEADLINE BUFFYSPEAK SYNDROME
        else:
            fadeyness = 1

        for y in range(0, 18):
            for x in range(0, 18):
                r_out, g_out = reduce(
                    (lambda (r, g), (r1, g1): (r + r1, g + g1)),
                    [cell.colour_at(x, y) for cell in self.cells])
                self.aa.screen[y][x] = (r_out * fadeyness, g_out * fadeyness)

        self.aa.render()
Ejemplo n.º 11
0
class IrisScene(object):
	def __init__(self, lp):
		self.aa = Antialiaser(lp)

	def tick(self, pattern, beat):
		self.aa.clear()

		redr = (beat - 32) * 0.8


		draw.disc(self.aa.screen, 9, 9, redr, (1, 0))

		if beat > 48:
			blackr = max(0, (beat - 48) * 0.8)
			draw.disc(self.aa.screen, 9, 9, blackr, (0, 0))

		self.aa.render()
Ejemplo n.º 12
0
class CircleCometScene(object):
    def __init__(self, lp):
        self.aa = Antialiaser(lp)

    def tick(self, pattern, beat):
        self.aa.clear()

        for i in range(16, 2, -1):
            b = beat - i * 0.8
            a = math.pi * b / 12
            r = 7 - (beat / 16)
            x = 9 + r * math.sin(a)
            y = 9 + r * math.cos(a)
            greenness = (16 - i) / 16.0
            draw.disc(self.aa.screen, x, y, greenness * 2, (1, greenness))

        self.aa.render()
Ejemplo n.º 13
0
class MoleculeScene(object):
	def __init__(self, lp):
		self.aa = Antialiaser(lp)

	def tick(self, pattern, beat):
		self.aa.clear()

		s0 = SEQ[int(beat) % 16]
		s1 = SEQ[int(beat + 1) % 16]

		big_disc_size = (s0 * (1 - beat % 1) + s1 * (beat % 1)) * 0.6
		small_disc_dize = 2 * 0.6

		spin = beat * math.pi / 16
		x0 = 9 + 5 * math.sin(spin)
		y0 = 10 + 3 * math.cos(spin)

		x1 = 9 + 5 * math.sin(spin + math.pi)
		y1 = 10 + 3 * math.cos(spin + math.pi)

		x2 = 9
		y2 = 4


		draw.line(self.aa.screen, x0, y0, x2, y2, (0, 1.3))
		draw.line(self.aa.screen, x1, y1, x2, y2, (0, 1.3))

		section = (beat + 4) % 64
		if section < 16:
			draw.disc(self.aa.screen, x0, y0, big_disc_size, (1, 1))
			draw.disc(self.aa.screen, x1, y1, small_disc_dize, (1, 1))
			draw.disc(self.aa.screen, x2, y2, small_disc_dize, (1, 0))
		elif section < 32:
			draw.disc(self.aa.screen, x0, y0, small_disc_dize, (1, 1))
			draw.disc(self.aa.screen, x1, y1, big_disc_size, (1, 1))
			draw.disc(self.aa.screen, x2, y2, small_disc_dize, (1, 0))
		elif section < 48:
			draw.disc(self.aa.screen, x0, y0, small_disc_dize, (1, 1))
			draw.disc(self.aa.screen, x1, y1, small_disc_dize, (1, 1))
			draw.disc(self.aa.screen, x2, y2, big_disc_size, (1, 0))
		else:
			draw.disc(self.aa.screen, x0, y0, big_disc_size, (1, 1))
			draw.disc(self.aa.screen, x1, y1, big_disc_size, (1, 1))
			draw.disc(self.aa.screen, x2, y2, small_disc_dize, (1, 0))

		self.aa.render()
Ejemplo n.º 14
0
class MoleculeScene(object):
    def __init__(self, lp):
        self.aa = Antialiaser(lp)

    def tick(self, pattern, beat):
        self.aa.clear()

        s0 = SEQ[int(beat) % 16]
        s1 = SEQ[int(beat + 1) % 16]

        big_disc_size = (s0 * (1 - beat % 1) + s1 * (beat % 1)) * 0.6
        small_disc_dize = 2 * 0.6

        spin = beat * math.pi / 16
        x0 = 9 + 5 * math.sin(spin)
        y0 = 10 + 3 * math.cos(spin)

        x1 = 9 + 5 * math.sin(spin + math.pi)
        y1 = 10 + 3 * math.cos(spin + math.pi)

        x2 = 9
        y2 = 4

        draw.line(self.aa.screen, x0, y0, x2, y2, (0, 1.3))
        draw.line(self.aa.screen, x1, y1, x2, y2, (0, 1.3))

        section = (beat + 4) % 64
        if section < 16:
            draw.disc(self.aa.screen, x0, y0, big_disc_size, (1, 1))
            draw.disc(self.aa.screen, x1, y1, small_disc_dize, (1, 1))
            draw.disc(self.aa.screen, x2, y2, small_disc_dize, (1, 0))
        elif section < 32:
            draw.disc(self.aa.screen, x0, y0, small_disc_dize, (1, 1))
            draw.disc(self.aa.screen, x1, y1, big_disc_size, (1, 1))
            draw.disc(self.aa.screen, x2, y2, small_disc_dize, (1, 0))
        elif section < 48:
            draw.disc(self.aa.screen, x0, y0, small_disc_dize, (1, 1))
            draw.disc(self.aa.screen, x1, y1, small_disc_dize, (1, 1))
            draw.disc(self.aa.screen, x2, y2, big_disc_size, (1, 0))
        else:
            draw.disc(self.aa.screen, x0, y0, big_disc_size, (1, 1))
            draw.disc(self.aa.screen, x1, y1, big_disc_size, (1, 1))
            draw.disc(self.aa.screen, x2, y2, small_disc_dize, (1, 0))

        self.aa.render()
Ejemplo n.º 15
0
class DrumScene(object):
    def __init__(self, lp, background=False):
        self.lp = lp
        self.aa = Antialiaser(lp)
        self.background = background

    SEQ = [
        1,
        0,
        3,
        0,
        2,
        0,
        3,
        0,
        0,
        0,
        3,
        0,
        2,
        0,
        3,
        0,
        1,
        0,
        3,
        0,
        2,
        0,
        3,
        0,
        0,
        0,
        3,
        0,
        4,
        4,
        5,
        5,
    ]

    def tick(self, pattern, beat):
        self.aa.clear()
        if self.background:
            r = -math.sin(math.pi * beat / 16.0) * 12

            for y in range(0, 18):
                for x in range(0, 18):
                    if r > 0:
                        dist = math.sqrt(x * x + (16 - y) * (16 - y))
                        if dist < r:
                            self.aa.screen[y][x] = (0, 1 - dist / r)
                    elif r < 0:
                        dist = math.sqrt((16 - x) * (16 - x) + y * y)
                        if dist < -r:
                            self.aa.screen[y][x] = (1 - dist / -r, 0)

        self.aa.render(commit=False)

        if pattern >= 0:
            ix = DrumScene.SEQ[int(beat) % 32]

            bright = beat % 1
            bright = int(bright * 4) ^ 3

            if ix == 1:
                self.lp.screen[5][2] = 0x01 * bright
            elif ix == 2:
                self.lp.screen[3][2] = 0x11 * bright
            elif ix == 3:
                self.lp.screen[3][5] = 0x10 * bright
            elif ix == 4:
                self.lp.screen[5][5] = 0x01 * bright
            elif ix == 5:
                self.lp.screen[6][6] = 0x01 * bright

        self.lp.commit()
Ejemplo n.º 16
0
class DNAScene(object):
    def __init__(self, lp, breakup=False):
        self.aa = Antialiaser(lp)
        self.breakup = breakup

    def tick(self, pattern, beat):
        self.aa.clear()

        for y in range(0, 18):
            if self.breakup:
                radius = 8 + max(0, beat - y)
                twist = (math.pi * (beat + 2) / 8) - y / 4.0
                twist = min(twist, math.pi / 2)
            else:
                radius = 8
                twist = (math.pi * (beat + 2) / 8) - y / 4.0

            dx = math.sin(twist) * radius

            brightness1 = 0.8 + math.cos(twist) * 0.5
            brightness2 = 0.8 - math.cos(twist) * 0.5

            x1 = int(9 - dx)
            x2 = int(9 + dx)

            if self.breakup:
                break_radius = radius - 8
                break_dx = math.sin(twist) * break_radius
                x1_break = int(9 - break_dx)
                x2_break = int(9 + break_dx)

            draw_link = (y % 4 == 1)
            if draw_link:
                link_num = y / 4

                link_colour = LINK_COLOURS[link_num]

            if brightness1 > brightness2:
                # plot the dimmest (furthest) first
                self.aa.plot(x2, y, (0, brightness2))
                self.aa.plot(x2, y, (0, brightness2))

                if draw_link:
                    if self.breakup:
                        draw.line(self.aa.screen, x1, y, x1_break, y,
                                  link_colour)
                        draw.line(self.aa.screen, x2, y, x2_break, y,
                                  link_colour)
                    else:
                        draw.line(self.aa.screen, x1, y, x2, y, link_colour)

                self.aa.plot(x1, y, (0, brightness1))
                self.aa.plot(x1 - 1, y, (0, brightness1))
            else:
                self.aa.plot(x1, y, (0, brightness1))
                self.aa.plot(x1 - 1, y, (0, brightness1))

                if draw_link:
                    if self.breakup:
                        draw.line(self.aa.screen, x1, y, x1_break, y,
                                  link_colour)
                        draw.line(self.aa.screen, x2, y, x2_break, y,
                                  link_colour)
                    else:
                        draw.line(self.aa.screen, x1, y, x2, y, link_colour)

                self.aa.plot(x2, y, (0, brightness2))
                self.aa.plot(x2 + 1, y, (0, brightness2))

        self.aa.render()
Ejemplo n.º 17
0
class DNAScene(object):
	def __init__(self, lp, breakup=False):
		self.aa = Antialiaser(lp)
		self.breakup = breakup

	def tick(self, pattern, beat):
		self.aa.clear()

		for y in range(0, 18):
			if self.breakup:
				radius = 8 + max(0, beat - y)
				twist = (math.pi * (beat + 2) / 8) - y / 4.0
				twist = min(twist, math.pi / 2)
			else:
				radius = 8
				twist = (math.pi * (beat + 2) / 8) - y / 4.0

			dx = math.sin(twist) * radius

			brightness1 = 0.8 + math.cos(twist) * 0.5
			brightness2 = 0.8 - math.cos(twist) * 0.5

			x1 = int(9 - dx)
			x2 = int(9 + dx)

			if self.breakup:
				break_radius = radius - 8
				break_dx = math.sin(twist) * break_radius
				x1_break = int(9 - break_dx)
				x2_break = int(9 + break_dx)

			draw_link = (y % 4 == 1)
			if draw_link:
				link_num = y / 4

				link_colour = LINK_COLOURS[link_num]


			if brightness1 > brightness2:
				# plot the dimmest (furthest) first
				self.aa.plot(x2, y, (0, brightness2))
				self.aa.plot(x2, y, (0, brightness2))

				if draw_link:
					if self.breakup:
						draw.line(self.aa.screen, x1, y, x1_break, y, link_colour)
						draw.line(self.aa.screen, x2, y, x2_break, y, link_colour)
					else:
						draw.line(self.aa.screen, x1, y, x2, y, link_colour)

				self.aa.plot(x1, y, (0, brightness1))
				self.aa.plot(x1 - 1, y, (0, brightness1))
			else:
				self.aa.plot(x1, y, (0, brightness1))
				self.aa.plot(x1 - 1, y, (0, brightness1))

				if draw_link:
					if self.breakup:
						draw.line(self.aa.screen, x1, y, x1_break, y, link_colour)
						draw.line(self.aa.screen, x2, y, x2_break, y, link_colour)
					else:
						draw.line(self.aa.screen, x1, y, x2, y, link_colour)

				self.aa.plot(x2, y, (0, brightness2))
				self.aa.plot(x2 + 1, y, (0, brightness2))

		self.aa.render()