I have this program that draws a daytime picture with trees and sun. When one clicks the mouse, the same trees display at night time with moon, clouds and FireFly. What I can't seem to program is the clouds should be moving slowly across the screen and FireFly should be moving after the mouse. It's been a week that I'm working on those two movements but can't seem to get it working. Any suggestions? Here is the program.
Thank you.
Corina
/*
Interactive object oriented programing
*/
void setup(){
background(59, 226, 255);
size(800, 800);
smooth();
noStroke();
int ground = 20;
color grass = #1EFF00;
fill(color(grass));
rect(0, height-ground, width, ground); // sets up grass ground
Tree tree1 = new Tree(Tree.TLL); // draws the different trees and shapes
tree1.drawTree(width-600, 530, 50, 250);
Tree tree2 = new Tree(Tree.SHRT);
tree2.drawTree(width-400, 685, 50, 100);
Tree tree3 = new Tree(Tree.TLL);
tree3.drawTree(width-200, 530, 50, 250 );
Tree tree4 = new Tree(Tree.SHRT);
tree4.drawTree(width-100, 685, 50, 100);
Rock rock1 = new Rock(Rock.STONE);
rock1.drawRock(width-500, 755, 100, 50);
Rock rock2 = new Rock(Rock.STONE);
rock2.drawRock(width-280, 770, 100, 25);
}
void draw(){ // Draws these when mouse is pressed
if(mousePressed){
background(41, 51, 50);
noStroke();
//ck Cloud cloud1 = new Cloud(Cloud.FLF);
//ck cloud1.drawCloud(200, 100, 300, 100);
Cloud cloud1 = new Cloud(Cloud.FLF);
cloud1.drawCloud(200, 100, 300, 100, 0, 10, 3);
cloud1.drive();
cloud1.display();
Firefly Firefly1 = new Firefly();
Firefly1.update();
Firefly1.display();
for(int i = 0; i<10; i++){
int ground = 20;
//color grass = (30, 255, );
fill(30*1.5, 255/2, 0);
rect(0, height-ground, width, ground);
Tree tree1 = new Tree(Tree.TLL);
tree1.drawTree(width-600, 530, 50, 250);
Tree tree2 = new Tree(Tree.SHRT);
tree2.drawTree(width-400, 685, 50, 100);
Tree tree3 = new Tree(Tree.TLL);
tree3.drawTree(width-200, 530, 50, 250 );
Tree tree4 = new Tree(Tree.SHRT);
tree4.drawTree(width-100, 685, 50, 100);
Rock rock1 = new Rock(Rock.STONE);
rock1.drawRock(width-500, 755, 100, 50);
Rock rock2 = new Rock(Rock.STONE);
rock2.drawRock(width-280, 770, 100, 25);
}
}else{ // redraws everything when mouse is released
background(59, 226, 255);
int ground = 20;
color grass = #1EFF00;
fill(color(grass));
rect(0, height-ground, width, ground);
Sun sun1 = new Sun(20,20, 300, 300);
sun1.drawSun(20, 20, 300, 300, 150, 25, 300, 20, 125, 100, 400, 150, 80, 150, 220, 300);
noStroke();
Tree tree1 = new Tree(Tree.TLL);
tree1.drawTree(width-600, 530, 50, 250);
Tree tree2 = new Tree(Tree.SHRT);
tree2.drawTree(width-400, 685, 50, 100);
Tree tree3 = new Tree(Tree.TLL);
tree3.drawTree(width-200, 530, 50, 250 );
Tree tree4 = new Tree(Tree.SHRT);
tree4.drawTree(width-100, 685, 50, 100);
Rock rock1 = new Rock(Rock.STONE);
rock1.drawRock(width-500, 755, 100, 50);
Rock rock2 = new Rock(Rock.STONE);
rock2.drawRock(width-280, 770, 100, 25);
}
}
class Tree{ // class for tree
int x;
int y;
int w;
int h;
int style = 0;
color leaves = #018A02;
color bark = #542300;
final static int TLL = 0;
final static int SHRT = 1;
//Tree(){
//}
Tree(int style){
this.style = style;
}
void drawTree( int x, int y, int w, int h){
switch(style){ // different styles
case 0:
fill(color(bark));
rect(x, y, w, h);
fill(color(leaves));
ellipse(x+25, y-w, w+25, h-100);
fill(color(leaves));
ellipse(x+25, y-w, w+50, h);
break;
class Rock{ // Rock class
int x;
int y;
int w;
int h;
int style = 0;
color stone = #878582;
final static int STONE = 0;
Rock(int style){
this.style = style;
}
void drawRock(int x, int y, int w, int h) {
switch(style){ // sets style
case 0:
fill(color(stone));
ellipse(x, y, w, h);
break;
}
}
void setStyle(int style) {
this.style = style;
}
}
class Cloud{ //cloud class
int x;
int y;
int w;
int h;
int style = 0;
// int Xspeed = 2;
float Xpos;
float Ypos;
float Xspeed;
//float xpos = tempXpos;
//float ypos = tempYpos;
//float xspeed =tempXSpeed;
final static int FLF = 0;
Cloud(int style) {
this.style = style;
//int Xspeed = Xspeed;
}
//ck void drawCloud(int x, int y, int w, int h, float xpos, float ypos, float xspeed)
void drawCloud(int x, int y, int w, int h, float tempXpos, float tempYpos, float tempXspeed)
{
switch(style){
case 0:
fill(255);
rect(x, y, w, h, 20);
break;
void setStyle(int style){
this.style = style;
}
}
class Moon{ // moon class
int x;
int y;
int w;
int h;
Moon(int x, int y, int w, int h){
this.x = x;
this.y= y;
this.w = w;
this.h = h;
}
void drawMoon(int x, int y, int w, int h){
}
}
class Sun{
int x;
int y;
int w;
int h;
int x1;
int x2;
int x3;
int x4;
int x5;
int x6;
int y1;
int y2;
int y3;
int y4;
int y5;
int y6;
Sun(int x, int y, int w, int h){
this.x = x;
this.y = y;
this.w = w;
this.h = h;
}
void drawSun( int x, int y, int w, int h, int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, int x5, int y5, int x6, int y6){
fill(#FF9F18);
ellipse(x, y, w, h);
stroke(#FF9F18);
line(x1, y1, x2, y2);
line(x3, y3, x4, y4);
line(x5, y5, x6, y6);
}
}
class Firefly{
int x;
int y;
int w;
int h;
Firefly(int x, int y){
this.x = x;
this.y = y;
}
// The Firefly tracks location, velocity, and acceleration
PVector location;
PVector velocity;
PVector acceleration;
// The Fireflies's maximum speed
float topspeed;
Firefly() {
// Start in the center
location = new PVector(width/2,height/2);
velocity = new PVector(0,0);
topspeed = 5;
}
void update() {
// Compute a vector that points from location to mouse
PVector mouse = new PVector(mouseX,mouseY);
PVector acceleration = PVector.sub(mouse, location);
// Set magnitude of acceleration
acceleration.setMag(.2);
// Velocity changes according to acceleration
velocity.add(acceleration);
// Limit the velocity by topspeed
velocity.limit(topspeed);
// Location changes by velocity
location.add(velocity);
}
// Creates all the houses, to create them it calls the classes below
int groundHeight = 10;
fill(900);
rect(0, height-groundHeight, width, groundHeight);
fill(255);
//Houses
Door door1 = new Door(40, 80, 255);
Window window1 = new Window(100, 125, false, Window.DOUBLE);
Roof roof1 = new Roof(Roof.DOME);
//Tess tess1 = new Tess(10,12,500,50,50);
Tess tess1 = new Tess(100,125,10);
tess1.drawTess(1, 100, 600, 1, 1);
//tess1.drawTess(150, 150, 150, 150, 150);
// tess1.drawTess(50, height-groundHeight, 50, 50, 50);
// tess1.drawTess(50, height-10, 10, 50, 50);
House house1 = new House(150, 150, door1, window1, roof1, House.MIDDLE_DOOR);
house1.drawHouse(50, height-groundHeight-house1.h, true);
// tess1.drawTess(500, 20, 4, 500, 500);
// tess1.drawTess(x-axis, y-axis, 100, 100, size);
Door door2 = new Door(40, 80, 255);
Window window2 = new Window(100, 125, true, Window.QUAD);
Roof roof2 = new Roof(Roof.GAMBREL);
House house2 = new House(200, 120, door2, window2, roof2, House.LEFT_DOOR);
house2.drawHouse(50+house1.w, height-groundHeight-house2.h, true);
Door door3 = new Door(40, 80, 255);
door3.setKnob(Door.RT);
Window window3 = new Window(125, 125, true, Window.SINGLE);
Roof roof3 = new Roof(Roof.CATHEDRAL);
House house3 = new House(150, 200, door3, window3, roof3, House.RIGHT_DOOR);
house3.drawHouse(house2.x+house2.w, height - groundHeight-house3.h,true);
Door door4 = new Door(40, 80, 255);
Window window4 = new Window(100, 125, true, Window.DOUBLE);
Roof roof4 = new Roof(Roof.GAMBREL);
House house4 = new House(200, 120, door4, window4, roof4, House.MIDDLE_DOOR);
house4.drawHouse(400+house3.w, height-groundHeight-house4.h, true);
Door door5 = new Door(40, 80, 255);
door5.setKnob(Door.LFT);
Window window5 = new Window(125, 125, true, Window.QUAD);
Roof roof5 = new Roof(Roof.DOME);
House house5 = new House(200, 200, door5, window5, roof5,House.RIGHT_DOOR);
house5.drawHouse(house4.x+house4.w, height - groundHeight-house5.h,true);
}
class Door{ // Door class called by each hous
//door properties
int x;
int y;
int w;
int h;
int c;
//for knob
int knobLoc = 1;
final static int RT = 0;
final static int LFT = 1;
// constructor
Door(int w, int h, int c){
this.w = w;
this.h = h;
this.c = c;
}
void drawDoor(int x, int y) {
fill(c);
rect(x, y, w, h);
int knobsize = w/10;
if (knobLoc == 0){
ellipse(x+w-knobsize, y+h/2, knobsize, knobsize);
}
else {
ellipse(x+knobsize, y+h/2, knobsize, knobsize);
}
}
void setKnob(int knobLoc){
this.knobLoc = knobLoc;
}
}
class Window{ // creates 3 kinds of windows that the houses can have
//window properties
int x;
int y;
int w;
int h;
// customized features
boolean hasSash = false;
//single, double, quad pane
int style = 0;
//constraints
final static int SINGLE = 0;
final static int DOUBLE = 1;
final static int QUAD = 2;
//constructor 1
Window(int w, int h) {
this.w = w;
this.h = h;
}
//constructor 2
Window(int w, int h, int style) {
this.w = w;
this.h = h;
this.style = style;
}
//constructor 3
Window(int w, int h, boolean hasSash, int style) {
this.w = w;
this.h = h;
this.hasSash = hasSash;
this.style = style;
}
//drawing window
void drawWindow(int x, int y){
int margin = 0;
int winHt = 0;
int winWdth = 0;
if (hasSash) {
margin = w/15;
}
switch(style) {
case 0:
//outer window
rect(x, y, w, h);
//inner window
rect(x+margin, y+margin, w-margin*2, h-margin*2);
break;
case 1:
winHt = (h-margin*3)/2;
//outer window
rect(x, y, w, h);
//inner window top
rect(x+margin, y+margin, w-margin*2, winHt);
//inner window bottom
rect(x+margin, y+winHt+margin*2, w-margin*2, winHt);
break;
case 2:
winWdth = (w-margin*3)/2;
winHt = (h-margin*3)/2;
//outer window
rect(x, y, w, h);
//inner window top left
rect(x+margin, y+margin, winWdth, winHt);
//inner top right
rect(x+winWdth+margin*2, y+margin, winWdth, winHt);
//inner bottom left
rect(x+margin, y+winHt+margin*2, winWdth, winHt);
//inner bottom right
rect(x+winWdth+margin*2, y+winHt+margin*2, winWdth, winHt);
break;
}
}
// set window style
void setStyle(int style){
this.style = style;
}
}
class Roof{ // 3 kinds of roofs for the houses that they call
//roof properties
int x;
int y;
int w;
int h;
//roof style
int style =0;
//constants
final static int CATHEDRAL = 0;
final static int GAMBREL = 1;
final static int DOME = 2;
//default constructor
Roof(){
}
//constructor 2
Roof(int style){
this.style = style;
}
//drawing the roof
void drawRoof(int x, int y, int w, int h) {
switch(style) {
case 0:
beginShape();
vertex(x, y);
vertex(x+w/2, y-h/3);
vertex(x+w, y);
endShape(CLOSE);
break;
case 1:
beginShape();
vertex(x,y);
vertex(x+w/7, y-h/5);
vertex(x+w/2, y-h/2.75);
vertex(x+(w-w/7), y-h/5);
vertex(x+w, y);
endShape(CLOSE);
break;
case 2:
ellipseMode(CORNER);
arc(x, y-h/2, w, h, PI, TWO_PI);
line(x, y, x+w, y);
break;
}
}
// set roof style
void setStyle(int style){
this.style = style;
}
}
class House{ // draws the house block, adds the other classes to it
//house props
int x;
int y;
int w;
int h;
int j;
//component refrence variables
Door door;
Window window;
Roof roof;
Tess tess;
//optional autosize variable
boolean AutoSizeComponents = false;
//door placement
int doorLoc = 0;
//constants
final static int MIDDLE_DOOR = 0;
final static int LEFT_DOOR = 1;
final static int RIGHT_DOOR = 2;
//constructor
House(int w, int h, Door door, Window window, Roof roof, int doorLoc) {
this.w = w;
this.h = h;
this.door = door;
this.window = window;
this.roof = roof;
this.tess = tess;
this.doorLoc = doorLoc;
}
void drawHouse(int x, int y, boolean AutoSizeComponents) {
this.x = x;
this.y = y;
this.AutoSizeComponents = AutoSizeComponents;
//automatically sizes doors and windows
if(AutoSizeComponents) {
//autosize door
door.h = h/4;
door.w = door.h/2;
//autosize windows
window.h = h/3;
window.w = window.h/2;
}
//draw bldg block
rect(x, y, w, h);
//tess.drawTess(10,10,10,10,10);
//draw door
switch(doorLoc){
case 0:
door.drawDoor(x+w/2-door.w, y+h-door.h);
break;
case 1:
door.drawDoor(x+w/8, y+h-door.h);
break;
case 2:
door.drawDoor(x+w-w/8-door.w, y+h-door.h);
break;
}
//draw windows
int windowMargin = (w-window.w*2)/3;
window.drawWindow(x+windowMargin, y+h/6);
window.drawWindow(x+windowMargin*2+window.w, y+h/6);
//draw roof
roof.drawRoof(x, y, w, h);
// tess.drawTess(x, y, w, h, j)
}
//catch drawHouse method without boolean argument
void drawHouse(int x, int y) {
// recall with required 3rd argument
drawHouse(x, y, false);
}
}
class Tess{
/* int points;
int radius;
int case1;
int width1;
int height1;
int style = 0;*/
int x;
int y;
int w;
int h;
int points = 1000;
int radius =100;
int width=150;
int height=150;
//final static int FourSingle=4;
//final static int SixSingle=6;
//constructor 1
/*Tess(int points, int radius, int case1, int width1, int height1) {
this.points = points;
this.radius = radius;
this.case1 = case1;
this.width1 = width1;
this.height1 =height1;}*/
Tess(int w, int h, int points) {
this.w = w;
this.h = h;
this.points=points;}
// void drawTess(int points, int radius,int case1, int width1, int height1 ){
void drawTess(int x, int y){
size(w, w+h);
//smooth();
New and need help: I have a program that creates a patttern called tessalate() listed towards the end of the program below that worked fine on its own. I also have another program that uses classes that creates homes with windows, doors and roofs (the first 3/4 of progam below). How do I add the tessalate() to the the Neighborhood program to add a pattern to a home, or a door? We tried converting tessalate() to a class but could not be called within the program, also tried to call tessalate() as a function. It's been about a week research and work but could not figure it out. Any suggestions?
// Creates all the houses, to create them it calls the classes below
int groundHeight = 10;
fill(900);
rect(0, height-groundHeight, width, groundHeight);
fill(255);
Door door2 = new Door(40, 80, 255);
Window window2 = new Window(100, 125, true, Window.QUAD);
Roof roof2 = new Roof(Roof.GAMBREL);
House house2 = new House(200, 120, door2, window2, roof2, House.LEFT_DOOR);
house2.drawHouse(50+house1.w, height-groundHeight-house2.h, true);
Door door3 = new Door(40, 80, 255);
door3.setKnob(Door.RT);
Window window3 = new Window(125, 125, true, Window.SINGLE);
Roof roof3 = new Roof(Roof.CATHEDRAL);
House house3 = new House(150, 200, door3, window3, roof3, House.RIGHT_DOOR);
house3.drawHouse(house2.x+house2.w, height - groundHeight-house3.h,true);
Door door4 = new Door(40, 80, 255);
Window window4 = new Window(100, 125, true, Window.DOUBLE);
Roof roof4 = new Roof(Roof.GAMBREL);
House house4 = new House(200, 120, door4, window4, roof4, House.MIDDLE_DOOR);
house4.drawHouse(400+house3.w, height-groundHeight-house4.h, true);
Door door5 = new Door(40, 80, 255);
door5.setKnob(Door.LFT);
Window window5 = new Window(125, 125, true, Window.QUAD);
Roof roof5 = new Roof(Roof.DOME);
House house5 = new House(200, 200, door5, window5, roof5, House.RIGHT_DOOR);
house5.drawHouse(house4.x+house4.w, height - groundHeight-house5.h,true);
}
class Door{ // Door class called by each hous
//door properties
int x;
int y;
int w;
int h;
int c;
//for knob
int knobLoc = 1;
final static int RT = 0;
final static int LFT = 1;
// constructor
Door(int w, int h, int c){
this.w = w;
this.h = h;
this.c = c;
}
void drawDoor(int x, int y) {
fill(c);
rect(x, y, w, h);
int knobsize = w/10;
if (knobLoc == 0){
ellipse(x+w-knobsize, y+h/2, knobsize, knobsize);
}
else {
ellipse(x+knobsize, y+h/2, knobsize, knobsize);
}
}
void setKnob(int knobLoc){
this.knobLoc = knobLoc;
}
}
class Window{ // creates 3 kinds of windows that the houses can have
//window properties
int x;
int y;
int w;
int h;
// customized features
boolean hasSash = false;
//single, double, quad pane
int style = 0;
//constraints
final static int SINGLE = 0;
final static int DOUBLE = 1;
final static int QUAD = 2;
//constructor 1
Window(int w, int h) {
this.w = w;
this.h = h;
}
//constructor 2
Window(int w, int h, int style) {
this.w = w;
this.h = h;
this.style = style;
}
//constructor 3
Window(int w, int h, boolean hasSash, int style) {
this.w = w;
this.h = h;
this.hasSash = hasSash;
this.style = style;
}
//drawing window
void drawWindow(int x, int y){
int margin = 0;
int winHt = 0;
int winWdth = 0;
// tessalate(6,20);
if (hasSash) {
margin = w/15;
}
switch(style) {
case 0:
//outer window
rect(x, y, w, h);
//inner window
rect(x+margin, y+margin, w-margin*2, h-margin*2);
break;
case 1:
winHt = (h-margin*3)/2;
//outer window
rect(x, y, w, h);
//inner window top
rect(x+margin, y+margin, w-margin*2, winHt);
//inner window bottom
rect(x+margin, y+winHt+margin*2, w-margin*2, winHt);
break;
case 2:
winWdth = (w-margin*3)/2;
winHt = (h-margin*3)/2;
//outer window
rect(x, y, w, h);
//inner window top left
rect(x+margin, y+margin, winWdth, winHt);
//inner top right
rect(x+winWdth+margin*2, y+margin, winWdth, winHt);
//inner bottom left
rect(x+margin, y+winHt+margin*2, winWdth, winHt);
//inner bottom right
rect(x+winWdth+margin*2, y+winHt+margin*2, winWdth, winHt);
break;
}
}
// set window style
void setStyle(int style){
this.style = style;
}
}
class Roof{ // 3 kinds of roofs for the houses that they call
//roof properties
int x;
int y;
int w;
int h;
//roof style
int style =0;
//constants
final static int CATHEDRAL = 0;
final static int GAMBREL = 1;
final static int DOME = 2;
//default constructor
Roof(){
}
//constructor 2
Roof(int style){
this.style = style;
}
//drawing the roof
void drawRoof(int x, int y, int w, int h) {
switch(style) {
case 0:
beginShape();
vertex(x, y);
vertex(x+w/2, y-h/3);
vertex(x+w, y);
endShape(CLOSE);
break;
case 1:
beginShape();
vertex(x,y);
vertex(x+w/7, y-h/5);
vertex(x+w/2, y-h/2.75);
vertex(x+(w-w/7), y-h/5);
vertex(x+w, y);
endShape(CLOSE);
break;
case 2:
ellipseMode(CORNER);
arc(x, y-h/2, w, h, PI, TWO_PI);
line(x, y, x+w, y);
break;
}
}
// set roof style
void setStyle(int style){
this.style = style;
}
}
class House{ // draws the house block, adds the other classes to it
//house props
int x;
int y;
int w;
int h;
//int j;
//component refrence variables
Door door;
Window window;
Roof roof;
// Tess tess;
//optional autosize variable
boolean AutoSizeComponents = false;
//door placement
int doorLoc = 0;
//constants
final static int MIDDLE_DOOR = 0;
final static int LEFT_DOOR = 1;
final static int RIGHT_DOOR = 2;
//constructor
House(int w, int h, Door door, Window window, Roof roof, int doorLoc) {
this.w = w;
this.h = h;
this.door = door;
this.window = window;
this.roof = roof;
this.doorLoc = doorLoc;
}
void drawHouse(int x, int y, boolean AutoSizeComponents) {
this.x = x;
this.y = y;
this.AutoSizeComponents = AutoSizeComponents;
//automatically sizes doors and windows
if(AutoSizeComponents) {
//autosize door
door.h = h/4;
door.w = door.h/2;
//autosize windows
window.h = h/3;
window.w = window.h/2;
}
//draw bldg block
rect(x, y, w, h);
//draw door
switch(doorLoc){
case 0:
door.drawDoor(x+w/2-door.w, y+h-door.h);
break;
case 1:
door.drawDoor(x+w/8, y+h-door.h);
break;
case 2:
door.drawDoor(x+w-w/8-door.w, y+h-door.h);
break;
}
//draw windows
int windowMargin = (w-window.w*2)/3;
window.drawWindow(x+windowMargin, y+h/6);
window.drawWindow(x+windowMargin*2+window.w, y+h/6);
//draw roof
roof.drawRoof(x, y, w, h);
// tess.drawTess(x, y, w, h, j)
//tessalate(6,20);
}
//catch drawHouse method without boolean argument
void drawHouse(int x, int y) {
// recall with required 3rd argument
drawHouse(x, y, false);