# Galactic Unicorn - Animated Pacman

**URL:** https://forums.pimoroni.com/t/galactic-unicorn-animated-pacman/20809
**Category:** Projects
**Created:** [November 26, 2022, 3:46pm UTC](https://forums.pimoroni.com/t/galactic-unicorn-animated-pacman/20809 "2022-11-26T15:46:51Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Tonygo2](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/tonygo2/32/7814_2.png) [@Tonygo2](https://forums.pimoroni.com/u/Tonygo2)
#### Post date: [November 26, 2022, 3:46pm UTC](https://forums.pimoroni.com/t/galactic-unicorn-animated-pacman/20809/1 "2022-11-26T15:46:51Z")

</div>

![DSCN4410](https://us1.discourse-cdn.com/flex016/uploads/pimoroni/original/2X/b/b341ceca924be8918c64e25793b917536145f8e1.jpeg)

Just a simple demo for a dark afternoon/evening. Can you add the yellow monster? Then make him give chase? (Must be more fun than all this football!)

```auto
# PacMan
# Tony Goodhew - TonyGo2 - 26th November 2022
# Pimoroni Galactic Unicorn

from galactic import GalacticUnicorn
from picographics import PicoGraphics, DISPLAY_GALACTIC_UNICORN
import time

# create a PicoGraphics framebuffer to draw into
graphics = PicoGraphics(display=DISPLAY_GALACTIC_UNICORN)

# create our GalacticUnicorn object
gu = GalacticUnicorn()

#Define some colours
BLACK = graphics.create_pen(0, 0, 0)
RED = graphics.create_pen(255, 0, 0)
RED2 = graphics.create_pen(128, 0, 0)
YELLOW = graphics.create_pen(255, 255, 0)
GREEN = graphics.create_pen(0, 255, 0)
GREEN2 = graphics.create_pen(0, 128, 0)
CYAN = graphics.create_pen(0, 255, 255)
BLUE = graphics.create_pen(0, 0, 255)
BLUE2 = graphics.create_pen(0, 0, 128)
MAGENTA = graphics.create_pen(255, 0, 255)
WHITE = graphics.create_pen(200, 200, 200)
GREY = graphics.create_pen(100, 100, 100)
DRKGRY = graphics.create_pen(20, 20, 20)
PINK = graphics.create_pen(40, 10, 0)

# PacMan
pman = [
    0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,
    0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,
    0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,
    0,1,1,1,2,2,1,1,1,1,2,2,1,1,1,0,
    1,1,1,2,2,2,2,1,1,2,2,2,2,1,1,1,
    1,1,1,2,2,2,2,1,1,2,2,2,2,1,1,1,
    1,1,1,1,2,2,1,1,1,1,2,2,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,0,1,1,1,1,0,1,1,1,1,1,
    0,1,1,1,0,0,0,1,1,0,0,0,1,1,1,0
    ]

def eye(xx,yy):
    graphics.set_pen(BLUE2)
    graphics.pixel(xx,yy)
    graphics.pixel(xx+1,yy)
    graphics.pixel(xx,yy+1)
    graphics.pixel(xx+1,yy+1)
        
def show_man(c,xx,yy,xoff,yoff):
    p = 0
    for row in range(11):
        for col in range(16):            
            v = pman[p]
            if v ==0:graphics.set_pen(BLACK)
            if v ==1:graphics.set_pen(c)
            if v ==2:graphics.set_pen(WHITE)
            graphics.pixel(xx+col,yy+row)
            p = p + 1
    eye(xx+4+xoff,yy++4+yoff)
    eye(xx+10+xoff,yy++4+yoff)

show_man(RED,5,0,0,0)
gu.update(graphics)
time.sleep(1)
show_man(GREEN,5,0,1,0)
gu.update(graphics)
time.sleep(1)
show_man(PINK,5,0,-1,0)
gu.update(graphics)
time.sleep(1)
show_man(GREY,5,0,0,-1)
gu.update(graphics)
time.sleep(1)
show_man(CYAN,5,0,0,1)
gu.update(graphics)
time.sleep(1)
show_man(DRKGRY,5,0,0,0)
gu.update(graphics)
time.sleep(2)
graphics.set_pen(BLACK)
graphics.clear()

for i in range(-16,54,1):
    show_man(RED2,i,0,1,0)
    gu.update(graphics)
    time.sleep(0.08)
    graphics.set_pen(BLACK)
    graphics.clear()
 
for i in range(54,-17,-1):
    show_man(RED2,i,0,-1,0)
    gu.update(graphics)
    time.sleep(0.08)
    graphics.set_pen(BLACK)
    graphics.clear()

```

---

<div class="post-metadata">

### Author: ![Tonygo2](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/tonygo2/32/7814_2.png) [@Tonygo2](https://forums.pimoroni.com/u/Tonygo2)
#### Post date: [November 27, 2022, 11:01am UTC](https://forums.pimoroni.com/t/galactic-unicorn-animated-pacman/20809/2 "2022-11-27T11:01:52Z")

</div>

![DSCN4421](https://us1.discourse-cdn.com/flex016/uploads/pimoroni/original/2X/3/30d31d46e636ca14a3feadb5952ace1928cc4ade.jpeg)

Managed to get the monster’s mouth working

```auto
# PacMan + Monster Muncher
# Tony Goodhew - TonyGo2 - 26th November 2022
# Pimoroni Galactic Unicorn

from galactic import GalacticUnicorn
from picographics import PicoGraphics, DISPLAY_GALACTIC_UNICORN
import time

# create a PicoGraphics framebuffer to draw into
graphics = PicoGraphics(display=DISPLAY_GALACTIC_UNICORN)

# create our GalacticUnicorn object
gu = GalacticUnicorn()

#Define some colours
BLACK = graphics.create_pen(0, 0, 0)
RED = graphics.create_pen(255, 0, 0)
RED2 = graphics.create_pen(128, 0, 0)
YELLOW = graphics.create_pen(255, 255, 0)
GREEN = graphics.create_pen(0, 255, 0)
GREEN2 = graphics.create_pen(0, 128, 0)
CYAN = graphics.create_pen(0, 255, 255)
BLUE = graphics.create_pen(0, 0, 255)
BLUE2 = graphics.create_pen(0, 0, 128)
MAGENTA = graphics.create_pen(255, 0, 255)
WHITE = graphics.create_pen(200, 200, 200)
GREY = graphics.create_pen(100, 100, 100)
DRKGRY = graphics.create_pen(20, 20, 20)
PINK = graphics.create_pen(40, 10, 0)

# PacMan
pman = [
    0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,
    0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,
    0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,
    0,1,1,1,2,2,1,1,1,1,2,2,1,1,1,0,
    1,1,1,2,2,2,2,1,1,2,2,2,2,1,1,1,
    1,1,1,2,2,2,2,1,1,2,2,2,2,1,1,1,
    1,1,1,1,2,2,1,1,1,1,2,2,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,0,1,1,1,1,0,1,1,1,1,1,
    0,1,1,1,0,0,0,1,1,0,0,0,1,1,1,0
    ]

def eye(xx,yy):
    graphics.set_pen(BLUE2)
    graphics.pixel(xx,yy)
    graphics.pixel(xx+1,yy)
    graphics.pixel(xx,yy+1)
    graphics.pixel(xx+1,yy+1)
        
def show_man(c,xx,yy,xoff,yoff):
    p = 0
    for row in range(11):
        for col in range(16):            
            v = pman[p]
            if v ==0:graphics.set_pen(BLACK)
            if v ==1:graphics.set_pen(c)
            if v ==2:graphics.set_pen(WHITE)
            graphics.pixel(xx+col,yy+row)
            p = p + 1
    eye(xx+4+xoff,yy++4+yoff)
    eye(xx+10+xoff,yy++4+yoff)

def munch0(xx):
    graphics.set_pen(BLACK)
    graphics.clear()
    graphics.set_pen(YELLOW)
    graphics.circle(xx,5,5)

def munch1(xx):
    munch0(xx)
    graphics.set_pen(BLACK)
    for x in range(xx,xx+6,1):
        graphics.pixel(x,5)        

def munch2(xx):
    munch1(xx)
    graphics.set_pen(BLACK)
    for x in range(xx+2,xx+6,1):
        graphics.pixel(x,4)
        graphics.pixel(x,6)
    
def munch3(xx):
    munch2(xx)
    graphics.set_pen(BLACK)
    for x in range(xx+4,xx+6,1):
        graphics.pixel(x,3)
        graphics.pixel(x,7)

d = 0.2
for z in range(-17,53+7,1):
    seq = z % 6
    if seq == 0: munch0(z)
    if seq == 1: munch1(z)
    if seq == 2: munch2(z)
    if seq == 3: munch3(z)
    if seq == 4: munch2(z)
    if seq == 5: munch1(z)
    show_man(RED2,z + 15,0,1,0)
    gu.update(graphics)
    time.sleep(d)

```

Video here: [PacMan - YouTube](https://youtu.be/73aL2VAV6KI)

---

<div class="post-metadata">

### Author: ![TigerClaw35](https://avatars.discourse-cdn.com/v4/letter/t/e0b2c6/32.png) [@TigerClaw35](https://forums.pimoroni.com/u/TigerClaw35)
#### Post date: [September 30, 2025, 3:30pm UTC](https://forums.pimoroni.com/t/galactic-unicorn-animated-pacman/20809/3 "2025-09-30T15:30:54Z")

</div>

Thanks for sharing your code. This looks amazing. Would like to use it for my picade max but as a loop together with the rainbow example. But I don’t know how to modify your code for a endless loop.

Best regards,

Mike

---

<div class="post-metadata">

### Author: ![Tonygo2](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/tonygo2/32/7814_2.png) [@Tonygo2](https://forums.pimoroni.com/u/Tonygo2)
#### Post date: [October 1, 2025, 8:37am UTC](https://forums.pimoroni.com/t/galactic-unicorn-animated-pacman/20809/4 "2025-10-01T08:37:28Z")

</div>

```auto
d = 0.2

while True:
    for z in range(-17,53+7,1):
        seq = z % 6
        if seq == 0: munch0(z)
        if seq == 1: munch1(z)
        if seq == 2: munch2(z)
        if seq == 3: munch3(z)
        if seq == 4: munch2(z)
        if seq == 5: munch1(z)
        show_man(RED2,z + 15,0,1,0)
        gu.update(graphics)
        time.sleep(d)

```

Glad you found it useful. Just change the end as shown above

---

<div class="post-metadata">

### Author: ![TigerClaw35](https://avatars.discourse-cdn.com/v4/letter/t/e0b2c6/32.png) [@TigerClaw35](https://forums.pimoroni.com/u/TigerClaw35)
#### Post date: [October 1, 2025, 12:06pm UTC](https://forums.pimoroni.com/t/galactic-unicorn-animated-pacman/20809/5 "2025-10-01T12:06:34Z")

</div>

Thank you. I tried to extend the code with help of ChatGPT for example to have more objects with different speed and moving from left to right and right to left. But the AI does not work and creates bad code which results in a crash.

---

<div class="post-metadata">

### Author: ![Tonygo2](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/tonygo2/32/7814_2.png) [@Tonygo2](https://forums.pimoroni.com/u/Tonygo2)
#### Post date: [October 1, 2025, 12:38pm UTC](https://forums.pimoroni.com/t/galactic-unicorn-animated-pacman/20809/6 "2025-10-01T12:38:09Z")

</div>

Please, learn to code yourself and do not rely on AI. There is plenty of online help to get you started.
