Last active
August 29, 2015 14:03
-
-
Save carlossaraiva/5c319db4884c8a0672bd to your computer and use it in GitHub Desktop.
linhas
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
/*O ideal seria separar a classe Line em um arquivo diferente para ficar mais legivel. Mas processing é sobre bagunça. o/ | |
Pressionando o botao esquerdo do monuse e arrastando para baixo cria linhas (max 30 linnhas/harcoded). | |
Arrastando para cima apaga a linha ate ficar a tela em branco. */ | |
class Line{ | |
private float y, len; | |
Line(float x, float y, int len){ | |
this.y = y; | |
this.len = len; | |
} | |
public float getY(){ | |
return this.y; | |
} | |
public float[] getPosition(){ | |
return new float[] {this.y}; | |
} | |
public void update(float y){ | |
this.y = y; | |
} | |
void draw(){ | |
line(0, this.y, len, this.y); | |
} | |
} | |
int size = 30; | |
Line[] reta = new Line[size]; | |
int state = 1; | |
void setup(){ | |
size(400, 300); | |
for(int i = 0; i < reta.length; i++){ | |
reta[i] = new Line(0, 0, 400); | |
} | |
} | |
void update(){ | |
for(int i = 0; i < reta.length; i++){ | |
reta[i].update(random(400)); | |
} | |
} | |
void draw(){ | |
update(); | |
background(255, 255, 255); | |
for(int i = 0; i < size; i++){ | |
reta[i].draw(); | |
} | |
} | |
void mouseDragged(){ | |
println(size); | |
if(pmouseY < mouseY){ | |
size--; | |
println(size); | |
if(size < 0){ | |
size = 0; | |
} | |
} | |
else{ | |
size++; | |
if(size >30){ | |
size = 30; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment