Tessalate a Neighborhood Homes
in
Programming Questions
•
6 months ago
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?
Thanks
Corina
/*
Neighboorhood
*/
void setup(){
size(1200, 800);
background(190);
smooth();
//tessalate(6,20)
//tessellate()
Neighboorhood
*/
void setup(){
size(1200, 800);
background(190);
smooth();
//tessalate(6,20)
//tessellate()
// 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);
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(6,20);
// tess1.drawTess(50, 100, 600, 50, 50);
//tess1.drawTess(150, 150, 150, 150, 150);
// tess1.drawTess(50, height-groundHeight, 50, 50, 50);
// tess1.drawTess(50, height-10, 10, 50, 50);
tessalate(1,10);
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 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(6,20);
// tess1.drawTess(50, 100, 600, 50, 50);
//tess1.drawTess(150, 150, 150, 150, 150);
// tess1.drawTess(50, height-groundHeight, 50, 50, 50);
// tess1.drawTess(50, height-10, 10, 50, 50);
tessalate(1,10);
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);
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);
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);
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;
}
//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);
void drawWindow(int x, int y){
int margin = 0;
int winHt = 0;
int winWdth = 0;
// tessalate(6,20);
if (hasSash) {
margin = w/15;
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
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){
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);
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);
//catch drawHouse method without boolean argument
void drawHouse(int x, int y) {
// recall with required 3rd argument
drawHouse(x, y, false);
}
}
}
// Tessalate program starts here
//void setup(){
// size(400, 400);
// smooth();
// tesselate(6, 20);
//}
// size(400, 400);
// smooth();
// tesselate(6, 20);
//}
void tessalate(int points, int radius){
int width=150;
int height=150;
//int radius = 0;
int height=150;
//int radius = 0;
if (points<=5){
points = 4;
}
else {
points = 4;
}
switch(points){
case 4:
for (int i=0, k=0; i<=width+radius; i+=radius*2, k++){
for (int j=0; j<=height+radius; j+=radius*2){
drawPoly(i-radius, j-radius, points, 0, radius);
drawPoly(i, j, points, 0, radius);
}
}
break;
case 4:
for (int i=0, k=0; i<=width+radius; i+=radius*2, k++){
for (int j=0; j<=height+radius; j+=radius*2){
drawPoly(i-radius, j-radius, points, 0, radius);
drawPoly(i, j, points, 0, radius);
}
}
break;
case 6:
for (float i=0, k=0; i<=width+radius; i+=radius*2, k++){
for (float j=0; j<=height+radius*2; j+=(cos(radians(30))*radius)*2){
if (k%2==0){
drawPoly(i, j-cos(radians(30))*radius, points, 0, radius);
//drawPoly(i, j-cos(radians(45))*radius, points, 0, radius);
}
else{
drawPoly(i, j, points, 0, radius);
}
}
}
break;
for (float i=0, k=0; i<=width+radius; i+=radius*2, k++){
for (float j=0; j<=height+radius*2; j+=(cos(radians(30))*radius)*2){
if (k%2==0){
drawPoly(i, j-cos(radians(30))*radius, points, 0, radius);
//drawPoly(i, j-cos(radians(45))*radius, points, 0, radius);
}
else{
drawPoly(i, j, points, 0, radius);
}
}
}
break;
}
}
void drawPoly(float x, float y, int pts, float initAngle, float rad) {
strokeWeight(2);
float px = 0, py = 0;
float angle = initAngle;
beginShape(TRIANGLE_FAN);
vertex(x, y);
for (int i= 0; i<=pts; i++){
fill(255/pts*i);
px = x+cos(radians(angle))*rad;
py = y+sin(radians(angle))*rad;
vertex(px, py);
angle+= 360/pts;
}
}
}
void drawPoly(float x, float y, int pts, float initAngle, float rad) {
strokeWeight(2);
float px = 0, py = 0;
float angle = initAngle;
beginShape(TRIANGLE_FAN);
vertex(x, y);
for (int i= 0; i<=pts; i++){
fill(255/pts*i);
px = x+cos(radians(angle))*rad;
py = y+sin(radians(angle))*rad;
vertex(px, py);
angle+= 360/pts;
}
}
1