Create Pacman with functions and parameters

Now that we’ve learned about variables and functions, we can start having more fun!

Your task today is to create and save your own version of Pacman, by changing the parameters on a pacman() function in the code below:

Use this code – you can copy it from here

//Can you change the appearance of pacman by changing the parameters on this function? 
float x; //this sets the centre of pacman in the x axis
float y; //this sets the centre of pacman in the y axis
color pink = color(255,134,241); //do you want to draw a pink pacman?
color yellow = color(0,125,125); //or a yellow one?
//set the radius variable for the pacman character
float radius = 55; //decide how big you want your pacman to be
//boolean variable to set the sex of the pacman character
Boolean female = true;
int direction = 0;

void setup()
//set initial values for the pacman coordinates
//set y position of pacman
} //this ends the setup() function

//the draw() function runs many times per second - useful for animations
void draw()
//draw background

//change the parameters in this function to draw your own pacman
//see what happens if you don't set one of the parameters
pacman(x, y, pink, true, radius, direction);
//Can you put in a couple of extra pacman() functions here, with different paramenters?
} //This ends the draw() function

//next we need the pacman() function - you can see that all the parameters are defined in the first line
//see what happens if you delete one of the functions
void pacman(float tempX, float tempY, color clr, Boolean tempFemale, float tempRadius, int tempDir)

if (tempDir==0)
//draw pacman facing right
arc(tempX, tempY, tempRadius,tempRadius, radians(45), radians(315));
//draw pacman facing left
arc(tempX, tempY, tempRadius,tempRadius, radians(225), radians(360+135));
//draw eyes
if (tempFemale == true)
//draw ribbon for ms pacman
fill(255, 0, 0, 200);


//this function saves your pacman image
void mousePressed()

5 thoughts on “Create Pacman with functions and parameters

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s