The Easiest Way to Save and Share Code Snippets on the web

atração1

processing

posted: Nov, 24th 2011 | jump to bottom

int calhas = int(random(0, 500)); //comprimento da lista de pontos
float[] pontosX = new float[calhas];  //lista de abcissas
float[] pontosY = new float[calhas];  //lista de ordenadas
int[] pontosWeight = new int [calhas]; // lista de pesos
float[] speeds = new float [calhas]; // lista de pesos
int transparencia = 50;
int cor =  color(255, transparencia);
int corBG = color(0, 100);
float distancia, speed, angulo;
boolean negativo = true;
 
void setup() {
  size(800, 600);
  colorMode(RGB, 100);
  for (int i = 0; i < calhas ; i++) {
    pontosX[i]= (random(0, width));
    pontosY[i]= (random(0, height));   
    pontosWeight[i]=int(random(1, 10));
    speeds[i]= random(-0.008, 0.008);
  };
  smooth();
  strokeCap(SQUARE);
  stroke(cor);
  noCursor();
  speed = 0;
}
 
void draw() {
 
  background(corBG);
 
  for (int i = 1; i < calhas; i++) {
    speed+= 10;
    strokeWeight(pontosWeight[i]);
    angulo= atan2(pontosY[i]-mouseY, pontosX[i]-mouseX);
    distancia = dist(mouseX, mouseY, pontosX[i], pontosY[i]);
    angulo+=speeds[i];
    pontosX[i]=cos(angulo)*distancia+mouseX;
    pontosY[i]=sin(angulo)*distancia+mouseY;
    line(pontosX[i], pontosY[i], mouseX, mouseY);
  };
 
  fill(255, 0, 0);  
  inverteCor();
}
 
void mouseReleased() {
 
  calhas = int(random(0, 500));
  pontosX = new float[calhas];  //lista de abcissas
  pontosY = new float[calhas];  //lista de ordenadas
  pontosWeight = new int [calhas]; // lista de pesos
  speeds = new float [calhas]; // lista de pesos
 
 
  for (int i = 0; i < calhas ; i++) {
    pontosX[i]= int(random(0, width));
    pontosY[i]= int(random(0, height));
    speeds[i]= random(-0.008, 0.008);
    pontosWeight[i]=int(random(1, 10));
  };
}
 
void inverteCor() {
  if (keyPressed) {
    if (key == 'i' || key == 'I') {
      if (negativo == true) {
        negativo = false;
        corBG = color(0,transparencia);
        cor = color(255,255,255,transparencia);
        stroke(cor);
      }
      else if (negativo == false) {
        negativo = true;
        corBG = color(255,255,255,transparencia);
        cor = color(0,0,0,transparencia);
        stroke(cor);
      };
    };
 
  };
 
  println (negativo);
}
 
51 views