Created
January 21, 2015 01:40
-
-
Save carlossaraiva/3ab334a1b98d914f447d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int tamanho = 30; | |
int deslocamento = tamanho; | |
Triangulo[][] triangulo; | |
color[] cores = new color[3]; | |
boolean invert = true; | |
int count = 0; | |
void setup() { | |
size(600, 600, P2D); | |
triangulo = new Triangulo[100][100]; | |
cores[0] = color(200, 100, 0); | |
cores[1] = color(255); | |
cores[2] = color(100); | |
for(int i = 0; i < triangulo.length; i++){ | |
for(int j = 0; j < triangulo[i].length; j++){ | |
triangulo[i][j] = new Triangulo(30); | |
//triangulo[i][j].update(cores[(int)random(0, 3)]); | |
println(triangulo[i][j]); | |
} | |
} | |
} | |
void draw() { | |
background(255); | |
translate(0, 0); | |
pushMatrix(); | |
for(int i = 0; i < triangulo.length; i++){ | |
pushMatrix(); | |
for(int j = 0; j < triangulo[i].length; j++){ | |
triangulo[i][j].put(); | |
translate(tamanho, 0); | |
triangulo[i][j].drawInv(); | |
translate(tamanho, 0); | |
} | |
popMatrix(); | |
//pushMatrix(); | |
translate(deslocamento, tamanho/2); | |
deslocamento = -deslocamento; | |
} | |
popMatrix(); | |
} | |
void mouseClicked(){ | |
for(int i = 0; i < triangulo.length; i+=2){ | |
for(int j = 0; j < triangulo[i].length; j+=2){ | |
color cor = cores[(int)random(0, 3)]; | |
if(i%2 == 0 && j+1 < triangulo[i].length){ | |
triangulo[i][j].update(cor); | |
triangulo[i][j+1].update(cor); | |
} | |
else{ | |
triangulo[i][j].update(cor); | |
triangulo[i][j+1].update(cor); | |
} | |
// triangulo[i][j+1].update(cor); | |
// triangulo[i+1][j].update(cor); | |
// triangulo[i+1][j].update(cor); | |
// println("AQUI"); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Triangulo{ | |
int tamanho; | |
color traco; | |
color preenchimento; | |
Triangulo(int tamanho){ | |
this.tamanho = tamanho; | |
this.traco = color(0); | |
this.preenchimento = color(255); | |
} | |
void update(color cor){ | |
this.traco = traco; | |
this.preenchimento = cor; | |
} | |
void put(){ | |
fill(this.preenchimento); | |
stroke(this.traco); | |
beginShape(); | |
vertex(0, tamanho/2);//top | |
vertex(tamanho, 0); | |
vertex(tamanho, tamanho); | |
vertex(0, tamanho/2); | |
endShape(); | |
} | |
void drawInv(){ | |
fill(this.preenchimento); | |
stroke(this.traco); | |
beginShape(); | |
vertex(0, 0);//top | |
vertex(tamanho, tamanho/2); | |
vertex(0, tamanho); | |
vertex(0, 0); | |
endShape(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment