def scroll(GD): # assets/4311669609_cdb83b6286_o.jpg # assets/4299180244_cd6099a2fd_o.jpg tile = Image.open("assets/4293136099_3bb98722c0_o.jpg").resize( (128, 128), Image.BILINEAR) GD.wrstr(gd.RAM_CHR, array.array('H', 256 * ([0xffff] + 7 * [0x300]))) GD.wrstr(gd.RAM_PAL, array.array('H', 256 * ([0, 0, 0, gd.RGB(255, 255, 255)]))) (dpic, dchr, dpal) = gdprep.encode(tile) # self.wrstr(gd.RAM_CHR, dchr.tostring()) # self.wrstr(gd.RAM_PAL, dpal.tostring()) pic = [(16 * (y & 15) + (x & 15)) for y in range(64) for x in range(64)] GD.wrstr(gd.RAM_PIC, array.array('B', pic)) for i in range(256): a = gd.RAM_PAL + 8 * i GD.wr16(a, gd.RGB(255, 0, 0)) GD.wait() GD.wr16(a, gd.RGB(0, 0, 0)) for i in range(256): GD.wrstr(gd.RAM_CHR + 16 * i, dchr[16 * i:16 * i + 16]) GD.wrstr(gd.RAM_PAL + 8 * i, dpal[4 * i:4 * i + 4]) GD.wait() GD.getbrush(tile) for x in range(0, 64, 16): for y in range(0, 64, 16): GD.paint(x, y) GD.sync_pic() if 0: if x == 0 and y == 0: GD.wait(60) else: GD.wait(8) coords = [(i, 0) for i in range(256)] coords.append((None, None)) coords += [(0, i) for i in range(256)] coords.append((None, None)) phi = 0 for f in range(480 * 2): t = min(f / 480., 1) pt = math.pow(t, 2) phi += pt * 0.01 r = 1024 + 1024 * t coords.append((r * math.sin(phi), r * math.cos(phi))) for (x, y) in coords: if x is None: GD.pause() else: GD.wrstr(gd.SCROLL_X, struct.pack("HH", int(x) & 511, int(y) & 511)) GD.wait() cp = GD.charpal() GD.fade(cp, 32, 0)
def fadechars(self, ch, t): rgb = [c16(h) for h in ch] def fc(v): return max(0, min(255, int(v * t))) rgb = [(fc(r), fc(g), fc(b)) for (r,g,b) in rgb] newpal = array.array('H', [gd.RGB(*c)|(h & 0x8000) for c,h in zip(rgb, ch)]).tostring() self.wrstr(gd.RAM_PAL, newpal[0:2048]) self.wrstr(gd.PALETTE16A, newpal[2048:2048+32])
def hue(self, ch, t): rgb = [c16(h) for h in ch] def f(r, g, b): (h,s,v) = colorsys.rgb_to_hsv(r / 255., g / 255., b / 255.) h += t (r, g, b) = colorsys.hsv_to_rgb(h, s, v) return tuple([max(0, min(255, int(c * 255))) for c in (r, g, b)]) rgb = [f(r,g,b) for (r,g,b) in rgb] newpal = array.array('H', [gd.RGB(*c) for c in rgb]).tostring() self.wrstr(gd.RAM_PAL, newpal[0:512])
def j1(GD): GD.wrstr( gd.RAM_PAL, array.array( 'H', 256 * ([ gd.RGB(0, 0, 0), gd.RGB(0x20, 0x20, 0x20), gd.RGB(0x40, 0x40, 0x40), gd.RGB(0xff, 0xff, 0xff) ]))) GD.microcode(random_code) GD.wr(gd.SPR_DISABLE, 0) s = "".join(["%02X" % c for c in random_code]) for c in ('16-bit, 50 MIPS', '256 bytes code', 'full access', 'random', s): slide.loadcaption(GD, c) slide.drawcaption(GD, (400 - 256) / 2, 180) GD.sync_spr() GD.pause() slide.loadcaption(GD, "") GD.wait(18)
def parade(GD, im): newpal = [] for c in gdprep.getpal(im): newpal += [c, 0, 0, 0] GD.fill(gd.RAM_PIC, 255, 64 * 38) GD.wrstr(gd.RAM_CHR, array.array('H', 256 * ([0xffff] + 7 * [0x300]))) GD.wrstr(gd.RAM_PAL, array.array('H', newpal)) GD.wr16(gd.BG_COLOR, gd.RGB(100, 200, 200)) up = range(30) dn = up[::-1] imstr = array.array('B', im.tostring()) for delay, dir in ((10, up), (3, dn), (1, up)): for j in dir: s = imstr[j * 1024:j * 1024 + 1024] for i in range(32): a = gd.RAM_PIC + 9 + 64 * (3 + i) GD.m[a:a + 32] = s[32 * i:32 * i + 32] # GD.wrstr(gd.RAM_PIC + 9 + 64 * (3+i), s[32*i:32*i+32]) GD.sync_pic() GD.wait(delay) cp = GD.charpal() GD.fade(cp, 32, 0) GD.cold() GD.pause()
def tiling(GD): slide(GD, "truchet") GD.cold() GD.wr16(gd.RAM_PAL + 255 * 8, gd.RGB(64, 64, 64)) GD.fill(gd.RAM_PIC, 255, 4096) GD.getbrush(Image.open("assets/truchet.png")) for i in range(4): GD.wr(64 * 17 + 10 + 10 * i, i) GD.pause() def tr0(x, y): return 0 def tr1(x, y): o = (x < 25) return (2 * o) + (1 & (x + y)) def tr2(x, y): return [0, 2, 3, 1][(x & 1) | (2 * (y & 1))] def tr2a(x, y): return [1, 2, 3, 0][(x & 1) | (2 * (y & 1))] def tr3(x, y): return [2, 3, 1, 0][(x & 1) | (2 * (y & 1))] def tr4(x, y): return random.randrange(4) for f in (tr0, tr1, tr2a, tr2, tr3, tr4): b = array.array('B', [f(x, y) for y in range(64) for x in range(64)]) GD.wrstr(gd.RAM_PIC, b) GD.pause() GD.cold() GD.getbrush(Image.open("assets/diamond03b.gif")) GD.paint(5, 2) GD.sync_pic() GD.pause() GD.wrstr(gd.RAM_CHR, array.array('H', 256 * ([0xffff] + 7 * [0x300]))) cs = Image.open("assets/c64_low.gif").crop((0, 0, 256, 32)) (dpic, dchr, dpal) = gdprep.encode(cs) GD.wrstr(gd.RAM_CHR, dchr) GD.fill(gd.RAM_CHR + 32 * 16, 0x55, 16) # space GD.fill(gd.RAM_CHR + 128 * 16, 0x00, 16) # all-white GD.fill(gd.RAM_PIC, 128, 38 * 64) xlat = [0 for i in range(128)] for i in range(32): xlat[0x60 + i] = i xlat[0x20 + i] = 32 + i xlat[0x40 + i] = 64 + i def str(x, y, s): GD.wrstr((7 + y) * 64 + (5 + x), array.array('B', [xlat[ord(c)] for c in s])) def cls(): for y in range(25): str(0, y, " " * 40) cls() pal = [gd.RGB(156, 156, 255), gd.RGB(66, 66, 222), 0, 0] GD.wrstr(gd.RAM_PAL, array.array('H', 256 * pal)) GD.wait(10) str(4, 1, "**** COMMODORE 64 BASIC V2 ****") str(1, 3, "64K RAM SYSTEM 38911 BASIC BYTES FREE") str(0, 5, "READY.") str(0, 6, "10 PRINT CHR$(205.5+RND(1)); : GOTO 10") GD.pause() cls() GD.wr(20 + 64 * 19, dpic[95]) GD.wr(30 + 64 * 19, dpic[105]) GD.pause() choice = [random.randrange(2) for i in range(4096)] t01 = [xlat[48], xlat[49]] tab = [dpic[95], dpic[105]] ta1 = [tab[0], t01[1]] for t in (t01, ta1, tab): print t GD.wrstr(0, array.array('B', [t[x] for x in choice])) GD.pause() cp = GD.charpal() GD.fade(cp, 32, 0) GD.wrstr(gd.RAM_CHR, array.array('H', 256 * ([0xffff] + 7 * [0x300]))) GD.wrstr(gd.RAM_PAL, array.array('H', 256 * ([0, 0, 0, gd.RGB(64, 64, 64)]))) GD.fill(gd.RAM_PIC, 255, 64 * 38) tile = Image.open("assets/4312221289_3ae3d8e306_o.jpg").resize( (128, 128), Image.BILINEAR) (dpic, dchr, dpal) = gdprep.encode(tile) GD.wrstr(gd.RAM_CHR, dchr) GD.wrstr(gd.RAM_PAL, dpal) def paint(x0, y0, i): sx = 4 * i for y in range(4): GD.wrstr(64 * (y0 + y) + x0, dpic[sx:sx + 4]) sx += 16 for i in range(4): paint(14 + 6 * i, 17, i) GD.pause() for x in range(0, 64, 4): for y in range(0, 64, 4): if ((x ^ y) & 4) == 0: ti = random.choice((0, 2)) else: ti = random.choice((1, 3)) paint(x, y, ti) cp = GD.charpal() x = 0 for i in range(960): y = 3 * i x = 50 * math.sin(i * 0.01) GD.wait() GD.scrollxy(x, y) if i > 200: GD.hue(cp, 0.002 * (i - 200))
def swap_bg(c): r, g, b = c16(c) return gd.RGB(r, b, g) | (c & 0x8000)
def swap_rg(c): r, g, b = c16(c) return gd.RGB(g, r, b) | (c & 0x8000)
def swap_rb(c): r, g, b = c16(c) return gd.RGB(b, g, r) | (c & 0x8000)
def mario(GD): # GD.getbrush(Image.open("20592.png")) # assert 0 GD.wrstr(gd.RAM_CHR, array.array('H', 256 * ([0xffff] + 7 * [0x300]))) GD.wrstr(gd.RAM_PAL, array.array('H', 256 * ([0, 0, 0, gd.RGB(64, 64, 64)]))) GD.fill(gd.RAM_PIC, 255, 64 * 38) cs = Image.open("assets/20592.png") (dpic, dchr, dpal) = gdprep.encode(cs) GD.wrstr(gd.RAM_CHR, dchr) GD.wrstr(gd.RAM_PAL, dpal) print 'mario used', len(dchr) / 16 if 1: nchr = len(dchr) / 16 for i in range(nchr): x = 10 + (i % 10) * 3 y = 2 + (i / 10) * 3 GD.wr(64 * y + x, i) GD.wait(2) GD.pause() GD.fill(gd.RAM_PIC, 255, 64 * 38) GD.pause() (w, h) = (cs.size[0] / 8, cs.size[1] / 8) def strip(x): da = x & 63 sa = x for y in range(h): GD.m[da] = dpic[sa] sa += w da += 64 for x in range(64): strip(x) GD.sync_pic() # GD.wait(1) pix = -1 scr = 0 slew = [1] * 72 + [2] * 72 span = (w - 50) * 8 part3 = span - 2 * sum(slew) vels = slew + ([3] * (part3 / 3)) + slew[::-1] r = 0 for v in vels: scr += v GD.wait(1) GD.scrollxy(scr, 0) ix = (scr / 8) if (pix != ix) and (ix + 60) < w: strip(ix + 60) # GD.sync_pic(h) pix = ix # Sync half of active pic on alternate frames bs = 64 * h / 2 a = r * bs GD.wrstr(a, GD.m[a:a + bs]) r ^= 1 GD.pause() # GD.fill(gd.RAM_CHR + 32 * 16, 0x55, 16) # space GD.fill(gd.RAM_CHR + 128 * 16, 0x00, 16) # all-white GD.fill(gd.RAM_PIC, 128, 38 * 64)