Your assignment is to create a sketch that defines a class


Assignment: The Trouble with Tribbles

Goal

The purpose of this assignment is to create oodles and oodles of Tribbles.

Assignment

Your assignment is to create a sketch that defines a class called "Tribble". A Tribble is a small fuzzy creature kept as a cute pet that breeds quickly. Your sketch should create hundreds of instances of Tribbles around the screen and show them doing their thing. Define methods and instance variables for the class Tribble as appropriate.

Tribbles look like small fuzzy blobs. You can start by drawing them as circles, but your final sketch should show your interpretation of what "fuzzy" means. Tribbles spend most of their time sleeping (not moving). Every five seconds they wake up and get excited and vibrate for two seconds (horizontally by 1 pixel each frame, randomly), then settle down and continue sleeping.

Each instance of Tribble should be on its own schedule of vibration and should start at a random location on the screen. Optional: give each Tribble a random color.

Timed Behavior

Each Tribble should have a boolean instance variable to indicate whether it is asleep or excited. It will also probably need some integer counts for timing so you know how long it has been asleep or excited.

Sequence

• Start with one Tribble. Define a simple class.
• Get simple drawing, random location, and setup done.
• Add the "excited" behavior (assume it is excited all the time).
• Add the sleep-wakeup timed behavior using your integer instance variables.
• Make the drawing better (fuzzier)
• Declare and initialize an array of 5 Tribbles
• Create all the instances to fill up your array (passing random locations and other values to the constructor)
• Update your draw() function to loop through and draw all the Tribbles and do any other calls needed
• Check that the sleeping-wakeup behavior is correct
• Check that all the tribbles are not synchronized (pass random integer counts to constructor to start them in different states)
• Increase the array size to 200

Submission

Submit your zipped pde file directly here to eCommons.

0.5 Did they submit a Processing sketch?
0.5 Does the sketch run?
0.5 Is the code organized and clean?
0.5 Does the code have proper comments?
1.5 200 tribbles are drawn using array.
1.0 Tribbles generate at random positions.
1.5 The tribbles are not synchronized (they start in different states).
1.5 Every five seconds tribbles wake up and get excited.
1.5 In excited state, tribbles vibrate for two seconds (horizontally by 1 pixel each frame, randomly) before settling down and continuing to sleep.
1.0 Tribbles are drawn with an interpretation of "fuzzy". They are not just drawn as circles.

Example

Zoog zoog;

void setup() {
size(200,200);
smooth();
zoog = new Zoog(100,125,60,60,16);
}
void draw() {
background(255);
// mouseX position determines speed factor
float factor = constrain(mouseX/10,0,5);
zoog.jiggle(factor);
zoog.display();
}
class Zoog {
// Zoog's variables
float x,y,w,h,eyeSize;
// Zoog constructor
Zoog(float tempX, float tempY, float tempW, float tempH, float tempEyeSize) {
x = tempX;
y = tempY;
w = tempW;
h = tempH;
eyeSize = tempEyeSize;
}

// Move Zoog
void jiggle(float speed) {
// Change the location of Zoog randomly
x = x + random(-1,1)*speed;
y = y + random(-1,1)*speed;
// Constrain Zoog to window
x = constrain(x,0,width);
y = constrain(y,0,height);
}
// Display Zoog
void display() {
// Set ellipses and rects to CENTER mode
ellipseMode(CENTER);
rectMode(CENTER);
// Draw Zoog's arms with a for loop
for (float i = y - h/3; i < y + h/2; i + = 10) {
stroke(0);
line(x-w/4,i,x + w/4,i);
}
// Draw Zoog's body
stroke(0);
fill(175);
rect(x,y,w/6,h);
// Draw Zoog's head
stroke(0);
fill(255);
ellipse(x,y-h,w,h);
// Draw Zoog's eyes
fill(0);
ellipse(x-w/3,y-h,eyeSize,eyeSize*2);
ellipse(x + w/3,y - h,eyeSize,eyeSize*2);
// Draw Zoog's legs
stroke(0);
line(x - w/12,y + h/2,x - w/4,y + h/2 + 10);
line(x + w/12,y + h/2,x + w/4,y + h/2 + 10);
}
}

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: Your assignment is to create a sketch that defines a class
Reference No:- TGS02309702

Expected delivery within 24 Hours