Skip to content

Instantly share code, notes, and snippets.

@augustoguerrero
Created August 31, 2016 22:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save augustoguerrero/abdd8f9821caab3a9530aabfe62aec65 to your computer and use it in GitHub Desktop.
Save augustoguerrero/abdd8f9821caab3a9530aabfe62aec65 to your computer and use it in GitHub Desktop.
Creación de circulos en processing
Circulo padre;
Circulo[] hijos1 = new Circulo[7];
Circulo[] hijos2 = new Circulo[4];
Circulo[] hijos3 = new Circulo[3];
void setup() {
size(600, 600);
noStroke();
smooth();
padre = new Circulo(200, #BBDEFB);
for ( int i = 0; i < 7; i++ ) {
hijos1[i] = new Circulo(#64B5F6);
for (int j = 0; j < 4; j++ ) {
hijos2 [j] = new Circulo (#0D47A1);
}
}
}
void draw() {
background(255);
padre.dibujar();
for ( int i = 0; i < 7; i++ ) {
hijos1[i].mover( padre.tam );
hijos1[i].dibujar();
for ( int j = 0; j < 4; j++ ) {
hijos2[j].mover( padre.tam );
hijos2[j].dibujar();
}
}
if (mousePressed) && (mouseX = hijos1.posicion()) && (mouseY = hijos1.posicion()) {
// Si el mouse es apretado, y el puntero esta justo ubicado
// en la misma posicion que uno de los circulos (cambiar hijos1 por el que se desea),
// entonces usar el metodo dibujar() para crear mas circulos
}
if (mousePressed) {
padre.crecer();
for ( int i = 0; i < 7; i++ ) {
hijos1[i].crecer();
for ( int j = 0; j < 4; j++ ) {
hijos2[j].crecer();
}
}
}
}
class Circulo {
float x, y;
float tam;
float dir, vel;
color c;
Circulo( color d_ ) {
x = y = random(150, 250);
tam = random(15, 30);
dir = random(TWO_PI);
vel = 0.5;
c = d_;
}
Circulo( float tam_, color c_ ) {
x = y = 200;
tam = tam_;
c = c_;
}
void mover( float zona ) {
if ( dist(200, 200, x, y) >= zona/2-tam/2 ) {
dir = random(TWO_PI);
}
float dx = vel * cos(dir);
float dy = vel * sin(dir);
x += dx;
y += dy;
}
void dibujar() {
fill (c);
ellipse(x, y, tam, tam);
}
void crecer() {
if ( dist(x, y, mouseX, mouseY) < tam/2 )
tam++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment