Esempio n. 1
0
def bgencode(dstdir, im, name, compress):
    def bgproblem(problem):
        nameSpace = {'problem': problem}
        ct = Template(open("bgerror.html").read(), searchList=[nameSpace])
        open("%s/index.html" % dstdir, "w").write(str(ct))

    badwidth = (im.size[0] % 8) != 0
    badheight = (im.size[1] % 8) != 0
    suggest = " -- resize to %d wide by %d high?" % ((im.size[0] + 7) & ~7,
                                                     (im.size[1] + 7) & ~7)
    if badwidth and badheight:
        return bgproblem(
            "The image width and height must be a multiples of 8" + suggest)
    if badwidth:
        return bgproblem("The image width must be a multiple of 8" + suggest)
    if badheight:
        return bgproblem("The image height must be a multiple of 8" + suggest)

    try:
        (picdata, chrdata, paldata) = gdprep.encode(im)
    except OverflowError:
        return bgproblem(
            "The source image uses more than 256 unique characters")

    im.save("%s/%s.png" % (dstdir, name))
    showbg(dstdir, im, (picdata, chrdata, paldata), name, compress)
Esempio n. 2
0
    def test_sprites(self):
        ir = gdprep.ImageRAM(StringIO.StringIO())
        (rock0, rock1) = gdprep.palettize(
            [Image.open("rock0r.png"),
             Image.open("rock1r.png")], 16)
        ir.addsprites("rock0", (16, 16),
                      rock0,
                      gdprep.PALETTE16A,
                      center=(8, 8))
        ir.addsprites("rock1", (32, 32),
                      rock1,
                      gdprep.PALETTE16A,
                      center=(16, 16))
        gd.wr16(gameduino.RAM_PAL, gameduino.RGB(0, 255, 0))
        gd.wrstr(gameduino.RAM_SPRIMG, ir.used())
        gd.wrstr(gameduino.PALETTE16A, gdprep.getpal(rock0))

        for i in range(128):
            gd.sprite(i, 200 + 20 * (i & 7), 20 * (i / 8), i / 2,
                      gdprep.PALETTE16A[i & 1], 0)

        (pic, chr, pal) = gdprep.encode(Image.open("platformer.png"))
        gd.wrstr(gameduino.RAM_CHR, chr)
        gd.wrstr(gameduino.RAM_PAL, pal)
        for y in range(32):
            gd.wrstr(gameduino.RAM_PIC + 64 * y, pic[16 * y:16 * y + 16])
Esempio n. 3
0
 def getbrush(self, im):
     (dpic, dchr, dpal) = gdprep.encode(im)
     self.wrstr(gd.RAM_CHR, dchr.tostring())
     print 'used', len(dchr) / 16
     self.wrstr(gd.RAM_PAL, dpal.tostring())
     self.dpic = dpic
     self.w = im.size[0] / 8
     self.h = im.size[1] / 8
Esempio n. 4
0
 def test_prep_sim(self):
     im = self.bg.convert("RGB")
     (pic,chr,pal) = gdprep.encode(im)
     gd = gdsim.Gameduino()
     gd.wrstr(gameduino.RAM_PIC, pic)
     gd.wrstr(gameduino.RAM_CHR, chr)
     gd.wrstr(gameduino.RAM_PAL, pal)
     gd.im().save("preview.png")
Esempio n. 5
0
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)
Esempio n. 6
0
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)
Esempio n. 7
0
                    help='Name of output header file.')
parser.add_argument('--variable-name',
                    default='background',
                    dest='varname',
                    help='Name of the arrays that will be generated')
## update name and replace in call to Image.open() and the check for sheet, update help message
parser.add_argument(dest='sheet', help='')

args = parser.parse_args()

## check if output is a .h file
check_header = args.output.split('.')
if (len(check_header) != 2 or check_header[1] != 'h'):
    raise TypeError('Supply a .h file! You supplied %s.' % args.output)

## check if sheet is a .png file
check_sheet = args.sheet.split('.')
if (len(check_sheet) != 2 or check_sheet[1] != 'png'):
    raise TypeError('Supply a .png file! You supplied %s.' % args.sheet)

(dpic, dchr, dpal) = gdprep.encode(Image.open(args.sheet))
header = open(args.output, "w")

name_pic = args.varname + '_pic'
name_chr = args.varname + '_chr'
name_pal = args.varname + '_pal'

gdprep.dump(header, name_pic, dpic)
gdprep.dump(header, name_chr, dchr)
gdprep.dump(header, name_pal, dpal)
Esempio n. 8
0
 def test_encode(self):
     im = self.bg.convert("RGB")
     w,h = im.size
     (pic,chr,pal) = gdprep.encode(im)
     self.assertEqual(len(chr.tostring()) / 16, len(pal.tostring()) / 8)
     self.assertEqual(len(pic), (w / 8) * (h / 8))
Esempio n. 9
0
def bgencode(dstdir, im, name, compress):
    (picdata, chrdata, paldata) = gdprep.encode(im)
    im.save("%s/%s.png" % (dstdir, name))
    # tilecode: mapping from tilecoords to code
    tilecode = {}
    stride = im.size[0] / 8
    for i in range(im.size[0] / 8):
        for j in range(im.size[1] / 8):
            tilecode["%s,%s" % (i, j)] = picdata[i + (j * stride)]

    # codetiles: mapping from code to all tiles w that code
    codetiles = [[] for i in range(256)]
    for i in range(im.size[0] / 8):
        for j in range(im.size[1] / 8):
            code = picdata[i + (j * stride)]
            codetiles[code].append((i, j))

    fullscreen = (im.size == (512, 512))

    nbytes = len(chrdata) / 16

    hh = StringIO.StringIO()
    if compress:
        cc = Codec(b_off=9, b_len=3)
        if fullscreen:
            picdata = cc.toarray(picdata.tostring())
        chrdata = cc.toarray(chrdata.tostring())
        paldata = cc.toarray(paldata.tostring())

    gdprep.dump(hh, "%s_pic" % name, picdata)
    gdprep.dump(hh, "%s_chr" % name, chrdata)
    gdprep.dump(hh, "%s_pal" % name, paldata)

    tmpl = common
    if fullscreen and compress:
        tmpl += "  GD.uncompress(RAM_PIC, ${name}_pic);\n"
    else:
        tmpl += """  for (byte y = 0; y < %d; y++)
    GD.copy(RAM_PIC + y * 64, ${name}_pic + y * %d, %d);
""" % (im.size[1] / 8, im.size[0] / 8, im.size[0] / 8)
    if compress:
        tmpl += "  GD.uncompress(RAM_CHR, ${name}_chr);\n"
        tmpl += "  GD.uncompress(RAM_PAL, ${name}_pal);\n"
    else:
        tmpl += "  GD.copy(RAM_CHR, ${name}_chr, sizeof(${name}_chr));\n"
        tmpl += "  GD.copy(RAM_PAL, ${name}_pal, sizeof(${name}_pal));\n"

    tmpl += """}

void loop()
{
}"""

    ploader = string.Template(tmpl).substitute({'name': name})

    nameSpace = {
        'name': name,
        'width': im.size[0],
        'height': im.size[1],
        'nchars': nbytes,
        'nbytes': len(picdata) + len(chrdata) + len(paldata),
        'tilecode': json.dumps(tilecode),
        'codetiles': json.dumps(codetiles),
        'pagecode': open("bgcomplete.js").read(),
        'pde': cgi.escape(ploader),
        'h': hh.getvalue(),
    }
    ct = Template(open("bgcomplete.html").read(), searchList=[nameSpace])
    open("%s/index.html" % dstdir, "w").write(str(ct))

    z = zipfile.ZipFile(dstdir + "/" + name + ".zip", "w")
    z.writestr("%s/%s.pde" % (name, name), ploader)
    z.writestr("%s/%s.h" % (name, name), hh.getvalue())
    z.close()
Esempio n. 10
0
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))
Esempio n. 11
0
#!/usr/bin/python

import Image
import gameduino.prep as gdprep

(dpic, dchr, dpal) = gdprep.encode(Image.open("window.png"))
hdr = open("gfx.h", "w")
gdprep.dump(hdr, "windowChars", dchr)
gdprep.dump(hdr, "windowPal", dpal)

(dpic, dchr, dpal) = gdprep.encode(Image.open("button.png"))
gdprep.dump(hdr, "buttonChars", dchr)
gdprep.dump(hdr, "buttonPal", dpal)

(dpic, dchr, dpal) = gdprep.encode(Image.open("appicon.png"))
gdprep.dump(hdr, "appIconPic", dpic)
gdprep.dump(hdr, "appIconChars", dchr)
gdprep.dump(hdr, "appIconPal", dpal)

ir = gdprep.ImageRAM(hdr)
arrow = gdprep.palettize(Image.open("mouse-arrow.png"), 4)
gdprep.dump(hdr, "mouseArrowPal", gdprep.getpal(arrow))
ir.addsprites("mouseArrow", (16, 16), arrow, gdprep.PALETTE4A, center=(8, 8))
gdprep.dump(hdr, "mouseArrowImg", ir.used())
Esempio n. 12
0
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)
Esempio n. 13
0
#!/usr/bin/python

import Image
import gameduino.prep as gdprep
 
(dpic, dchr, dpal) = gdprep.encode(Image.open("lines.png"))
hdr = open("gfx.h", "w")
#gdprep.dump(hdr, "lines_pic", dpic)
gdprep.dump(hdr, "lines_chr", dchr)
gdprep.dump(hdr, "lines_pal", dpal)

ir = gdprep.ImageRAM(hdr)
players = gdprep.palettize(Image.open("players.png"), 4)
gdprep.dump(hdr, "players_pal", gdprep.getpal(players))
ir.addsprites("players", (16, 16), players, gdprep.PALETTE4A, center = (8, 8))
gdprep.dump(hdr, "players_img", ir.used())
Esempio n. 14
0
    def wait(self, n=1):
        if n == 1:
            self.waitpending = 1
        else:
            for i in range(n):
                self.sector("." + chr(2))
            self.fake = 0

    def pause(self):
        self.sector("," + chr(2))


if 0:
    cs = Image.open("assets/sonic.png")
    (dpic, dchr, dpal) = gdprep.encode(cs)
    print 'sonic used', len(dchr) / 16
    sys.exit(0)

from phony import Gameduino

s = Sequencer()
GD = Gameduino(s)

from slide import slide
from playback import playback
from scroll import scroll
from tiling import tiling
from dna import dna
from blocks import blocks
from mario import mario
Esempio n. 15
0
    def wait(self, n=1):
        if n == 1:
            self.waitpending = 1
        else:
            for i in range(n):
                self.sector("." + chr(2))
            self.fake = 0

    def pause(self):
        self.sector("," + chr(2))


if 0:
    cs = Image.open("assets/sonic.png")
    (dpic, dchr, dpal) = gdprep.encode(cs)
    print "sonic used", len(dchr) / 16
    sys.exit(0)

from phony import Gameduino

s = Sequencer()
GD = Gameduino(s)

from slide import slide
from playback import playback
from scroll import scroll
from tiling import tiling
from dna import dna
from blocks import blocks
from mario import mario
Esempio n. 16
0
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))
Esempio n. 17
0
def dna(GD):

    if 0:
        ramp = Image.open("assets/ramp.png")
        (dpic, dchr, dpal) = gdprep.encode(ramp)
        w = ramp.size[0] / 8
        h = ramp.size[1] / 8
        for y in range(h):
            for x in range(0, 50, w):
                GD.m[64 * y + x:64 * y + x + w] = dpic[w * y:w * y + w]
        GD.sync_pic()
        GD.wrstr(gd.RAM_CHR, dchr.tostring())
        GD.wrstr(gd.RAM_PAL, dpal.tostring())
    else:
        GD.getbrush(Image.open("originals/atparty.png"))
        GD.paint(0, 0)
        GD.sync_pic()
    cp = GD.charpal()
    GD.fade(cp, 32, 8)

    im = Image.new("RGBA", (64 * 16, 16))
    for i in range(64):
        im.paste(Image.open("assets/lighting%02d.png" % i), (16 * i, 0))
    im = gdprep.palettize(im, 16)
    im.save("out.png")
    hh = open("../../dna.h", "w")
    ir = gdprep.ImageRAM(hh)
    # ir.addsprites("sphere", (16,16), im, gdprep.PALETTE16A, (8,8))
    locs = loadspr(ir, im, (16, 16))
    print len(ir.used())
    GD.wrstr(gd.RAM_SPRIMG, ir.used())
    sprpal = gdprep.getpal(im)
    GD.wrstr(gd.PALETTE16A, sprpal)
    GD.wrstr(gd.PALETTE16B, array.array('H', [swap_rb(c) for c in sprpal]))
    GD.wrstr(gd.RAM_SPRPAL + 0,
             array.array('H', [swap_rg(sprpal[i & 15]) for i in range(256)]))
    GD.wrstr(gd.RAM_SPRPAL + 512,
             array.array('H', [swap_rg(sprpal[i >> 4]) for i in range(256)]))
    GD.wrstr(gd.RAM_SPRPAL + 1024,
             array.array('H', [swap_bg(sprpal[i & 15]) for i in range(256)]))
    GD.wrstr(gd.RAM_SPRPAL + 1536,
             array.array('H', [swap_bg(sprpal[i >> 4]) for i in range(256)]))
    """ for i in range(256):
    // palette 0 decodes low nibble, hence (i & 15)
    GD.wr16(RAM_SPRPAL + (i << 1), SWAP_RG(rdpal(i & 15)));
    // palette 1 decodes nigh nibble, hence (i >> 4)
    GD.wr16(RAM_SPRPAL + 512 + (i << 1), SWAP_RG(rdpal(i >> 4)));
   """
    def draw_sphere(slot, x, y, frame, c):
        palix = locs[frame][1] & 1
        pals = {
            0: gdprep.PALETTE16A,
            1: gdprep.PALETTE16B,
            2: (0, 1),
            3: (2, 3)
        }[c]
        GD.sprite(i, x, y, locs[frame][0], pals[palix])

    GD.hide()

    if 1:
        GD.wrstr(gd.PALETTE16A + 15 * 2, "aa")
        for i in range(64):
            draw_sphere(i, 64 + 17 * (i & 0xf), 116 + 17 * (i / 16), i, 0)
            GD.sync_spr()
            GD.wait()
        GD.pause()
        GD.wrstr(gd.PALETTE16A, sprpal)
        GD.pause()

        for ii in range(10):
            cols = [random.randrange(4) for i in range(64)]
            for i in range(64):
                draw_sphere(i, 64 + 17 * (i & 0xf), 116 + 17 * (i / 16), i,
                            cols[i])
            GD.sync_spr()
            GD.wait(20)
        GD.pause()

    for i in range(256):
        x = i % 16
        y = i / 16
        draw_sphere(i, 64 + 18 * x, 6 + 18 * y, i & 63, i >> 6)
    GD.sync_spr()
    GD.pause()

    mcloud = [Ball() for i in range(256)]
    for ii in range(480):
        for i, b in enumerate(mcloud):
            draw_sphere(i, b.x, b.y, i & 63, i >> 6)
        if ii < 320:
            [b.move() for b in mcloud]
        else:
            [b.fall() for b in mcloud]
        GD.sync_spr()
        GD.wait(1)

    GD.hide()
    GD.sync_spr()
    GD.pause()

    phi = 1.0
    for ii in range(60 * 20):
        rotation(phi, *norm(math.sin(ii / 77.), 1, 1))
        phi += 0.027
        prj = [project(*p) for p in cloud]
        prj = sorted(prj, key=lambda p: -p[2])
        for i, p in enumerate(prj):
            x, y, z, c = p
            frame = max(0, min(63, int(32 + z / 500)))
            draw_sphere(i, x, y, frame, c)
            if ii == 0 and (i & 1):
                GD.sync_spr()
                GD.wait()
        GD.sync_spr()
        GD.wait()
    GD.pause()
Esempio n. 18
0
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)
Esempio n. 19
0
#!/usr/bin/python

import Image
import gameduino.prep as gdprep
 
(dpic, dchr, dpal) = gdprep.encode(Image.open("window.png"))
hdr = open("gfx.h", "w")
gdprep.dump(hdr, "windowChars", dchr)
gdprep.dump(hdr, "windowPal", dpal)

(dpic, dchr, dpal) = gdprep.encode(Image.open("button.png"))
gdprep.dump(hdr, "buttonChars", dchr)
gdprep.dump(hdr, "buttonPal", dpal)

(dpic, dchr, dpal) = gdprep.encode(Image.open("appicon.png"))
gdprep.dump(hdr, "appIconPic", dpic)
gdprep.dump(hdr, "appIconChars", dchr)
gdprep.dump(hdr, "appIconPal", dpal)

ir = gdprep.ImageRAM(hdr)
arrow = gdprep.palettize(Image.open("mouse-arrow.png"), 4)
gdprep.dump(hdr, "mouseArrowPal", gdprep.getpal(arrow))
ir.addsprites("mouseArrow", (16, 16), arrow, gdprep.PALETTE4A, center = (8, 8))
gdprep.dump(hdr, "mouseArrowImg", ir.used())
Esempio n. 20
0
def dna(GD):

    if 0:
        ramp = Image.open("assets/ramp.png")
        (dpic, dchr, dpal) = gdprep.encode(ramp)
        w = ramp.size[0] / 8
        h = ramp.size[1] / 8
        for y in range(h):
            for x in range(0, 50, w):
                GD.m[64 * y + x:64 * y + x + w] = dpic[w*y:w*y+w]
        GD.sync_pic()
        GD.wrstr(gd.RAM_CHR, dchr.tostring())
        GD.wrstr(gd.RAM_PAL, dpal.tostring())
    else:
        GD.getbrush(Image.open("originals/atparty.png"))
        GD.paint(0,0)
        GD.sync_pic()
    cp = GD.charpal()
    GD.fade(cp, 32, 8)

    im = Image.new("RGBA", (64 * 16, 16))
    for i in range(64):
      im.paste(Image.open("assets/lighting%02d.png" % i), (16*i,0))
    im = gdprep.palettize(im, 16)
    im.save("out.png")
    hh = open("../../dna.h", "w")
    ir = gdprep.ImageRAM(hh)
    # ir.addsprites("sphere", (16,16), im, gdprep.PALETTE16A, (8,8))
    locs = loadspr(ir, im, (16, 16))
    print len(ir.used())
    GD.wrstr(gd.RAM_SPRIMG, ir.used())
    sprpal = gdprep.getpal(im)
    GD.wrstr(gd.PALETTE16A, sprpal)
    GD.wrstr(gd.PALETTE16B, array.array('H', [swap_rb(c) for c in sprpal]))
    GD.wrstr(gd.RAM_SPRPAL +    0, array.array('H', [swap_rg(sprpal[i & 15]) for i in range(256)]))
    GD.wrstr(gd.RAM_SPRPAL +  512, array.array('H', [swap_rg(sprpal[i >> 4]) for i in range(256)]))
    GD.wrstr(gd.RAM_SPRPAL + 1024, array.array('H', [swap_bg(sprpal[i & 15]) for i in range(256)]))
    GD.wrstr(gd.RAM_SPRPAL + 1536, array.array('H', [swap_bg(sprpal[i >> 4]) for i in range(256)]))
    """ for i in range(256):
    // palette 0 decodes low nibble, hence (i & 15)
    GD.wr16(RAM_SPRPAL + (i << 1), SWAP_RG(rdpal(i & 15)));
    // palette 1 decodes nigh nibble, hence (i >> 4)
    GD.wr16(RAM_SPRPAL + 512 + (i << 1), SWAP_RG(rdpal(i >> 4)));
   """
    def draw_sphere(slot, x, y, frame, c):
        palix = locs[frame][1] & 1
        pals = {
            0: gdprep.PALETTE16A,
            1: gdprep.PALETTE16B,
            2: (0, 1),
            3: (2, 3)}[c]
        GD.sprite(i, x, y, locs[frame][0], pals[palix])

    GD.hide()

    if 1:
        GD.wrstr(gd.PALETTE16A + 15*2, "aa")
        for i in range(64):
            draw_sphere(i, 64 + 17 * (i & 0xf),
                           116 + 17 * (i / 16), i, 0)
            GD.sync_spr()
            GD.wait()
        GD.pause()
        GD.wrstr(gd.PALETTE16A, sprpal)
        GD.pause()

        for ii in range(10):
            cols = [random.randrange(4) for i in range(64)]
            for i in range(64):
                draw_sphere(i, 64 + 17 * (i & 0xf),
                               116 + 17 * (i / 16), i, cols[i])
            GD.sync_spr()
            GD.wait(20)
        GD.pause()

    for i in range(256):
        x = i % 16
        y = i / 16
        draw_sphere(i,
                    64 + 18 * x,
                     6 + 18 * y,
                    i & 63,
                    i >> 6)
    GD.sync_spr()
    GD.pause()

    mcloud = [Ball() for i in range(256)]
    for ii in range(480):
        for i,b in enumerate(mcloud):
            draw_sphere(i, b.x, b.y, i & 63, i >> 6)
        if ii < 320:
            [b.move() for b in mcloud]
        else:
            [b.fall() for b in mcloud]
        GD.sync_spr()
        GD.wait(1)

    GD.hide()
    GD.sync_spr()
    GD.pause()

    phi = 1.0
    for ii in range(60 * 20):
        rotation(phi, *norm(math.sin(ii / 77.), 1, 1))
        phi += 0.027
        prj = [project(*p) for p in cloud]
        prj = sorted(prj, key=lambda p:-p[2])
        for i,p in enumerate(prj):
            x,y,z,c = p
            frame = max(0, min(63, int(32 + z / 500)))
            draw_sphere(i, x, y, frame, c)
            if ii == 0 and (i & 1):
                GD.sync_spr()
                GD.wait()
        GD.sync_spr()
        GD.wait()
    GD.pause()
Esempio n. 21
0
parser = argparse.ArgumentParser(description='......something relevant.',
                                 epilog='Arguments can be called using --[first letter]. For example --output can be used by typing --o.')
parser.add_argument('--output', default='background.h', help='Name of output header file.')
parser.add_argument('--variable-name', default='background', dest='varname', 
                    help='Name of the arrays that will be generated')
## update name and replace in call to Image.open() and the check for sheet, update help message
parser.add_argument(dest='sheet', help='')

args = parser.parse_args()

## check if output is a .h file
check_header = args.output.split('.')
if (len(check_header) != 2 or check_header[1] != 'h'):
    raise TypeError('Supply a .h file! You supplied %s.' % args.output)

## check if sheet is a .png file
check_sheet = args.sheet.split('.')
if (len(check_sheet) != 2 or check_sheet[1] != 'png'):
    raise TypeError('Supply a .png file! You supplied %s.' %args.sheet)

(dpic, dchr, dpal) = gdprep.encode(Image.open(args.sheet))
header = open(args.output, "w")

name_pic = args.varname + '_pic'
name_chr = args.varname + '_chr'
name_pal = args.varname + '_pal'

gdprep.dump(header, name_pic, dpic)
gdprep.dump(header, name_chr, dchr)
gdprep.dump(header, name_pal, dpal)