Tessalate() as a Class
in
Programming Questions
•
6 months ago
Could Tessalate() pattern be added to backgroun in homes or doors or roofs, but in a class format?
Thanks to all who reply.
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(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 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);
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;
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 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){
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);
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;*/
}
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;
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;
//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 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;}
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();
void drawTess(int x, int y){
size(w, w+h);
//smooth();
// this.points = points;
// this.radius = radius;
// this.case1 = case1;
// this.width1 = width1;
// this.heigh1 = heigh1;
// this.radius = radius;
// this.case1 = case1;
// this.width1 = width1;
// this.heigh1 = heigh1;
if (points<=5){
points= 4;
}
else {
points = 6;
}
//case1=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){
drawTess(i-radius, j-radius, points, 0, radius);
drawTess(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){
drawTess(i-radius, j-radius, points, 0, radius);
drawTess(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){
drawTess(i, j-cos(radians(30))*radius, points, 0, radius);
//drawPoly(i, j-cos(radians(45))*radius, points, 0, radius);
}
else{
drawTess(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){
drawTess(i, j-cos(radians(30))*radius, points, 0, radius);
//drawPoly(i, j-cos(radians(45))*radius, points, 0, radius);
}
else{
drawTess(i, j, points, 0, radius);
}
}
}
break;
}
}
void drawTess(float x, float y, int pts, float initAngle, float rad) {
strokeWeight(1.5);
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 drawTess(float x, float y, int pts, float initAngle, float rad) {
strokeWeight(1.5);
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