Skip to content

Instantly share code, notes, and snippets.

@pedesen
Last active August 15, 2020 23:07
Show Gist options
  • Save pedesen/ad3dc32d770918f379ca8e52ed82fcc2 to your computer and use it in GitHub Desktop.
Save pedesen/ad3dc32d770918f379ca8e52ed82fcc2 to your computer and use it in GitHub Desktop.
Espruino Pac Man ghost animation
// Espruino Pac man ghost animation
// check this for more info: https://www.espruino.com/Graphics
const ghost = [`
####
########
##########
# #### ###
## ##
## #### ##
### #### ###
## #### ####
##############
##############
##############
##############
## ### ### ##
# ## ## #
`,`
####
########
##########
############
## #### ##
# ## #
## ## ##
## ## ## ## ##
##############
##############
##############
##############
#### #### ####
## ## ##
`,`
####
########
##########
### #### #
## ##
## #### ##
### #### ###
#### #### ##
##############
##############
##############
##############
## ### ### ##
# ## ## #
`,`
####
########
##########
# ## ## ## #
# ## #
## ## ##
### #### ###
##############
##############
##############
##############
##############
#### #### ####
## ## ##
`];
let ghostId;
const startGhostAnimation = (x, y, interval) => {
const ghostFrames = ghost.map((frame) => Graphics.createImage(frame));
let currentFrame = 0;
ghostId = setInterval(() => {
g.clearRect(x, y, x+14, x+15);
g.drawImage(ghostFrames[currentFrame], x,y);
g.flip();
currentFrame = (currentFrame + 1) % ghost.length;
}, interval);
};
const stopGhostAnimation = () => {
clearInterval(ghostId);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment