PAT 204/504: Creative Coding (Fall 2025)
Due at 11:59pm ET on September 29
Let’s build a sun-earth-moon system! You’re provided a template sketch below, which will render a simple sun-earth model:
Now, your task is to add the moon! The moon should rotate around the earth:
boolean saveFrames = false;
float theta = 0;
float radius = 120;
float speed = 0.02;
color c = #93E8FF;
float x, y;
void setup() {
// Create a 400x400 canvas
size(400, 400);
// Set a all-black background
background(0);
// Set the frame rate to 30 fps
frameRate(30);
}
void draw() {
// Fading effect
noStroke();
fill(0, 100);
rect(0, 0, height, width);
// Sun
fill(#FFCC00);
circle(200, 200, 20);
// Earth
theta -= speed;
x = cos(theta) * radius + 200;
y = sin(theta) * radius + 200;
fill(c);
circle(x, y, 10);
// Save the current for making a GIF
if (saveFrames) {
saveFrame("frames/###.png");
}
}
Let’s build a solar system! You’re provided a template sketch along with a template for the Star
class (“Star.pde”). Now, your task is to complete the template sketch and implement a solar system with 5+ planets.
Feel free to design your solar system with any color palette and speed/radius combination you like. Note that each planet must start from a random angle, which you should initialize in the constructor function of the Star
class.
boolean saveFrames = false;
Star[] stars = new Star[1];
void setup() {
// Create a 400x400 canvas
size(400, 400);
// Set a all-black background
background(#142034);
// Set the frame rate to 30 fps
frameRate(30);
// Initialize the stars
stars[0] = new Star(30, 0.18, #edafb8);
// YOUR CODE HERE
}
void draw() {
// Fading effect
noStroke();
fill(#142034, 50);
rect(0, 0, height, width);
// Sun
fill(#eebb00);
circle(200, 200, 10);
// Iterate over the stars
for (Star star: stars) {
// Update the star position
star.update();
// Show the star
star.show();
}
// Save the current for making a GIF
if (saveFrames) {
saveFrame("frames/###.png");
}
}
Star
Class// Star.pde
class Star {
float radius;
float speed;
color c;
float theta;
float x, y;
// Constructor
Star( /* YOUR CODE HERE */ ) {
// YOUR CODE HERE
}
// Show the star
void show() {
// YOUR CODE HERE
}
// Update the star position
void update() {
// YOUR CODE HERE
}
}