Nafis Sabir HW 10.2

CelestialBody class is at the bottom.

I was having a hard time trying to figure out how to break my program down into classes since I didn’t really use any objects in the program. I was thinking about a class for the seasons, but it wasn’t working out like I wanted. I decided to create a CelestialBody class, using a slightly modified bouncing ball code. I’ll use this to add a body for each of the seasons. Right now I only have a sun, but I was thinking about the moon, clouds, etc…
The program will only run in java, so I pasted the code below.

/*Nafis Sabir
Professor Calli Higgins
HW 10.2*
/
/* There’s a problem with parts of the code working in Javascript so some of the code is commented out. The main problem appears to be something with the images being used in the program. I’ll have to figure out why this problem is occurring.*/

//import ddf.minim.*;
////initialize audio
//Minim minim;
//AudioSample fireworks;
//AudioSample hallow;
//AudioSample leaves;
//AudioSample love;
//AudioSample snow2;
//AudioSample ocean;
//AudioSample olympic;
//AudioSample rain;
//AudioSample sleigh;
//AudioSample birds;
//AudioSample turkey;
//AudioSample snow;

PImage january, february, march, april, may, june, july, august;
PImage september, october, november, december;
int d, m, y, dateX, dateY, springc, winter, fall, summer, season;
float l, r, u, dn;
PFont myfont;
CelestialBody sunBody;// declare a CelestialBody object

void setup() {

size(640, 425);
sunBody = new CelestialBody();//initialize the CB object
l = width;
r = -600;
u = height;
dn = -425;
//loads audio
// minim = new Minim(this);//start sound engine
// //loads audio sample files
// fireworks = minim.loadSample(“fireworks.wav”, 2048);
// hallow = minim.loadSample(“hallow.mp3”, 256);
// leaves = minim.loadSample(“leaves.mp3”, 256);
// love = minim.loadSample(“love.mp3”, 256);
// snow2 = minim.loadSample(“snow2.wav”, 256);
// ocean = minim.loadSample(“ocean.mp3”, 256);
// olympic = minim.loadSample(“olympic.mp3”, 256);
// rain = minim.loadSample(“rain.mp3”, 256);
// sleigh = minim.loadSample(“sleigh.mp3”, 256);
// birds = minim.loadSample(“birds.mp3”, 256);
// turkey = minim.loadSample(“turkey.mp3”, 256);
// snow = minim.loadSample(“snow.mp3”, 256);
january = loadImage(“january.jpg”);
february = loadImage(“february.jpg”);
march = loadImage(“march.jpg”);
april = loadImage(“april.jpg”);
may = loadImage(“may.jpg”);
june = loadImage(“june.jpg”);
july = loadImage(“july.jpg”);
august = loadImage(“august.jpg”);
september = loadImage(“september.jpg”);
october = loadImage(“october.jpg”);
november = loadImage(“november.jpg”);
december = loadImage(“december.jpg”);

myfont = loadFont(“Dialog-70.vlw”);//temporary font for date
textFont(myfont, 70);
}

void draw() {
d = day(); // Values from 1 – 31
m = month(); // Values from 1 – 12
y = year(); // 2013, 2014, 2015, etc.
dateY = 60;//date y location
dateX = 20;//date x location
springc = #00CC00;//date fill for months spring
winter = #66A3D2;//date fill for months winter
fall = #FF6A00;//date fill for months fall
summer = #F7FE00;//date fill for months summer
//winter();
//spring();
//summer();
//fall();
println(m);

if (m <= 12) {//if month is january to december
randomSeed(d);
// background(255,0,0);
background(random(0, 255), random (0, 255), random (0, 255), 0);//background changes color depending on the date

if (m == 1) {//if month is january
january();
// for (int a=20; a < 20+(d*20); a=a+20) {//future place for image code
// image();
}
}

if (m == 2) {//if month is february
february();
// for (int a=20; a < 20+(d*20); a=a+20) {
// image();
}
// }

if (m == 3) {//if month is march
march();
// for (int a=20; a < 20+(d*20); a=a+20) {
//image();
//}
}

if (m == 4) {//if month is april
april();

// for (int a=20; a < 20+(d*20); a=a+20) {
// image();
}
// }

if (m == 5) {//if month is may
may();
// for (int a=20; a < 20+(d*20); a=a+20) {
// image();
// }
}

if (m == 6) {//if month is june
june();
// for (int a=20; a < 20+(d*20); a=a+20) {
// image();
// }
}

if (m == 7) {//if month is july
july();
//if (key == '7' )fireworks.trigger();
// for (int a=20; a < 20+(d*20); a=a+20) {
// image();
// }
}

if (m == 8) {//if month is august
august();
// for (int a=20; a < 20+(d*20); a=a+20) {
// image();
// }
}

if (m == 9) {//if month is september
september();
// for (int a=20; a < 20+(d*20); a=a+20) {
// image();
// }
}

if (m == 10) {//if month is october
october();
// for (int a=20; a < 20+(d*20); a=a+20) {
// image();
// }
}

if (m == 11) {//if month is november
november();
// for (int a=20; a < 20+(d*20); a=a+20) {
//image();
// }
}

if (m == 12) {//if month is december
//background(255);
december();
// for (int a=20; a =1) {
l -= 1;
}
}
void imageRight() {//moves image from left to right
if (r = 1) {
u -= 1;
}
}

void imageDown() {//moves image from top to bottom
if (dn = 12) || (m= 3) && (m= 6) && (m= 9) && (m<= 11)) {
season = fall;
println("It's Fall!");
}
}
//void keyPressed() {
// if (m==7 && key == '7' )fireworks.trigger();
// if (m == 10 && key == '0' )hallow.trigger();
// if (m == 9 && key == '9' )leaves.trigger();
// if (m == 2 && key == '2' )love.trigger();
// if (m == 3 && key == '3' )snow2.trigger();
// if (m == 6 && key == '6' )ocean.trigger();
// if (m == 8 && key == '8' )olympic.trigger();
// if (m == 4 && key == '4' )rain.trigger();
// if (m == 12 && key == 'd' )sleigh.trigger();
// if (m == 5 && key == '5' )birds.trigger();
// if (m == 11 && key == 'n' )turkey.trigger();
// if (m == 1 && key == '1' )snow.trigger();
//}

//at the bottom of the page

//void stop() {
// fireworks.close();
// hallow.close();
// leaves.close();
// love.close();
// snow2.close();
// ocean.close();
// olympic.close();
// rain.close();
// sleigh.close();
// birds.close();
// turkey.close();
// snow.close();
// minim.stop();
// super.stop();
//}

//CelestialBody class code
class CelestialBody {
//CB variables
color c;
int x;
int y;
int speed;

//Initialize data variables
CelestialBody() {
c = color(#FFF708);
x = 0;
y = 50;
speed = -1;

}

//CelestialBody functions
void fly() {//moves CB across the screen
x = x + speed; // Change the x location by speed
}

void orbit() {//function to make the CB return

if ((x > width) || (x < 0)) {//change direction when at the edge of the screen
speed = speed * -1;
}
}

// A function to display the CB
void display() {
stroke(0);
fill(c);
ellipse(x, y, 75, 75);
}

} //close CelestialBody class

This entry was posted in Uncategorized. Bookmark the permalink.

One Response to Nafis Sabir HW 10.2

  1. Hey Nafis- Can you post the code for your CelestialBody class?

Leave a Reply

Your email address will not be published. Required fields are marked *