Created
March 29, 2015 00:13
-
-
Save carlossaraiva/b180f48905c44b645938 to your computer and use it in GitHub Desktop.
Rhombus Tiling (Processing sketch)
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 Grid{ | |
ArrayList<ArrayList<Rhombus>> matrix; | |
int rows, cols; | |
float altura, largura; | |
Grid(ArrayList<ArrayList<Rhombus>> matrix) | |
{ | |
this.matrix = matrix; | |
this.altura = matrix.get(0).get(0).lado * 1.5 ; | |
this.largura = matrix.get(0).get(0).alt * 2; | |
} | |
void draw() | |
{ | |
float rowOffset = altura, colOffset = largura/2; | |
for(ArrayList<Rhombus> col : matrix) | |
{ | |
pushMatrix(); | |
for(Rhombus row : col) | |
{ | |
row.draw(); | |
translate(this.largura, 0 ); | |
} | |
popMatrix(); | |
translate(colOffset, rowOffset ); | |
colOffset = - colOffset; | |
} | |
} | |
} | |
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 Rhombus | |
{ | |
PShape up; | |
PShape left; | |
PShape right; | |
int lado; | |
float alt = (sqrt(3)/2)*lado; | |
float x, y; | |
color[] colors; | |
Rhombus(int lado, color[] colors) | |
{ | |
this.lado = lado; | |
this.alt = (sqrt(3)/2)*lado; | |
this.colors = colors; | |
init(); | |
} | |
void init() | |
{ | |
up = createShape(); | |
up.beginShape(); | |
color temp = colors[int(random(0,3))]; | |
up.fill (temp); | |
up.stroke(temp); | |
up.vertex (0, lado/2); | |
up.vertex (alt, 0); | |
up.vertex (alt*2, lado/2); | |
up.vertex (alt, lado); | |
up.endShape(); | |
right = createShape(); | |
right.beginShape(); | |
temp = colors[int(random(0,3))]; | |
right.fill (temp); | |
right.stroke(temp); | |
right.vertex(0, lado/2); | |
right.vertex(alt, lado); | |
right.vertex(alt, lado*2); | |
right.vertex(0, (lado+lado/2)); | |
right.endShape(); | |
left = createShape(); | |
left.beginShape(); | |
temp = colors[int(random(0,3))]; | |
left.fill (temp); | |
left.stroke(temp); | |
left.vertex (alt, lado); | |
left.vertex (alt*2, lado/2); | |
left.vertex (alt*2, (lado+lado/2)); | |
left.vertex (alt, lado*2); | |
left.endShape(); | |
} | |
void update() | |
{ | |
} | |
void draw() | |
{ | |
shape (up, 0, 0); | |
shape (right, 0, 0); | |
shape (left, 0, 0); | |
} | |
} |
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
Grid grid; | |
ArrayList<ArrayList<Rhombus>> rhombusMatrix = new ArrayList<ArrayList<Rhombus>>();; | |
color cores[] = {#A79C9C, #FAC50D, #FF0012}; | |
int linhas = 20; | |
int colunas = 20; | |
int tamanho = 50; | |
void setup(){ | |
size(1290, 720, P2D); | |
background(255); | |
generateMatrix(); | |
grid = new Grid(rhombusMatrix); | |
} | |
void draw(){ | |
grid.draw(); | |
} | |
void mouseClicked() | |
{ | |
rhombusMatrix.clear(); | |
generateMatrix(); | |
} | |
void generateMatrix() | |
{ | |
for(int i = 0; i < colunas; i++) | |
{ | |
ArrayList<Rhombus> temp = new ArrayList<Rhombus>(); | |
for(int j = 0; j < linhas; j++) | |
{ | |
temp.add(new Rhombus(tamanho, cores)); | |
} | |
rhombusMatrix.add(temp); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment