Mi idea es mostrar como desde una figura geometrica se puede llegar a lograr formas naturales, dandonos cuenta que todo nuestro entorno esta formado por estas figuras. Toda forma organica viene de otra forma geometrica.
class CircleMover
{
float diam;
float r;
float x,y;
float x0,y0;
float velocity; //its speed of travel in thetaDir
float thetaDir; // direction of velocity
color fillColor;
int trips = 0;
CircleMover(float xI, float yI) {
x = xI;
y = yI;
x0 = x;
y0 = y;
r = sqrt((x-x0)*(x-x0)+(y-y0)*(y-y0));
velocity = random(vmin,vmax);
thetaDir = random(0, TWO_PI);
fillColor = randomColor();
}
void move () {
if(maxTraverses==0 || trips < maxTraverses){
x += velocity*velocityScaling*cos(thetaDir);
y += velocity*velocityScaling*sin(thetaDir);
thetaDir += random(-dThetaScaling*maxdTheta, dThetaScaling*maxdTheta);
if(polar){
checkOutOfBoundsPolar();
calculateSizePolar();
}
else{
checkOutOfBoundsRect();
calculateSizeRect();
}
}
}
void checkOutOfBoundsPolar()
{
r = sqrt((x-x0)*(x-x0)+(y-y0)*(y-y0));
if(r > windowSize/2){
x = x0;
y = y0;
r = 0;
if(varyColors)
fillColor = randomColor();
velocity = random(vmin,vmax);
thetaDir = random(0, TWO_PI);
trips++;
}
}
void calculateSizePolar()
{
if(decreasingSize)
diam = diamInit*(1-r*2/windowSize);
else
diam = r*2/windowSize*diamInit;
}
void checkOutOfBoundsRect()
{
if(x > windowSize || x <0 || y>windowSize || y<0){
x = x0;
y = y0;
if(varyColors)
fillColor = randomColor();
velocity = random(vmin,vmax);
thetaDir = random(0, TWO_PI);
trips++;
}
}
void calculateSizeRect()
{
if(decreasingSize)
diam = diamInit*(1-max(abs(x-x0),abs(y-y0))*2/windowSize);
else
diam = max(abs(x-x0),abs(y-y0))*2/windowSize*diamInit;
}
void display() {
if(!outline)
noStroke();
else
stroke(0);
if(maxTraverses==0 || trips < maxTraverses){
fill(fillColor);
ellipse(x,y,diam,diam);
}
}
}
{
float diam;
float r;
float x,y;
float x0,y0;
float velocity; //its speed of travel in thetaDir
float thetaDir; // direction of velocity
color fillColor;
int trips = 0;
CircleMover(float xI, float yI) {
x = xI;
y = yI;
x0 = x;
y0 = y;
r = sqrt((x-x0)*(x-x0)+(y-y0)*(y-y0));
velocity = random(vmin,vmax);
thetaDir = random(0, TWO_PI);
fillColor = randomColor();
}
void move () {
if(maxTraverses==0 || trips < maxTraverses){
x += velocity*velocityScaling*cos(thetaDir);
y += velocity*velocityScaling*sin(thetaDir);
thetaDir += random(-dThetaScaling*maxdTheta, dThetaScaling*maxdTheta);
if(polar){
checkOutOfBoundsPolar();
calculateSizePolar();
}
else{
checkOutOfBoundsRect();
calculateSizeRect();
}
}
}
void checkOutOfBoundsPolar()
{
r = sqrt((x-x0)*(x-x0)+(y-y0)*(y-y0));
if(r > windowSize/2){
x = x0;
y = y0;
r = 0;
if(varyColors)
fillColor = randomColor();
velocity = random(vmin,vmax);
thetaDir = random(0, TWO_PI);
trips++;
}
}
void calculateSizePolar()
{
if(decreasingSize)
diam = diamInit*(1-r*2/windowSize);
else
diam = r*2/windowSize*diamInit;
}
void checkOutOfBoundsRect()
{
if(x > windowSize || x <0 || y>windowSize || y<0){
x = x0;
y = y0;
if(varyColors)
fillColor = randomColor();
velocity = random(vmin,vmax);
thetaDir = random(0, TWO_PI);
trips++;
}
}
void calculateSizeRect()
{
if(decreasingSize)
diam = diamInit*(1-max(abs(x-x0),abs(y-y0))*2/windowSize);
else
diam = max(abs(x-x0),abs(y-y0))*2/windowSize*diamInit;
}
void display() {
if(!outline)
noStroke();
else
stroke(0);
if(maxTraverses==0 || trips < maxTraverses){
fill(fillColor);
ellipse(x,y,diam,diam);
}
}
}
.......................................................................................................................................................
int windowSize = 500;
int xSize = windowSize;
int ySize = windowSize;
float maxdTheta = TWO_PI/30;
int nMovers = 5;
CircleMover[] movers;
float diamInit = 50;
float vmin = 2;
float vmax = 4;
int maxTraverses = 0; //number of trips each mover takes. for infinite, 0
boolean polar = true;
boolean decreasingSize = true;
boolean varyColors = false;
boolean transparency = false;
boolean outline = true;
float velocityScaling = 1;
float dThetaScaling = 1;
void setup()
{
smooth();
size(windowSize, windowSize);
background(255);
movers = new CircleMover[nMovers];
for(int i=0; i<movers.length; i++)
movers[i] = new CircleMover(windowSize/2,windowSize/2);
}
color randomColor()
{
float alpha = 255;
if(transparency)
alpha = random(0,50);
if(varyColors)
return color((int)random(0,255),(int)random(0,255),(int)random(0,255),alpha);
else
return color(255,255,255,alpha);
}
void draw()
{
// background(0);
for(int i=0; i<movers.length; i++){
movers[i].display();
movers[i].move();
}
}
.....................................................................................................................................................
int windowSize = 500;int xSize = windowSize;int ySize = windowSize;float maxdTheta = TWO_PI/30;int nMovers = 5;CircleMover[] movers;float diamInit = 50;float vmin = 2;float vmax = 4;int maxTraverses = 0; //number of trips each mover takes. for infinite, 0boolean polar = true;boolean decreasingSize = true;boolean varyColors = false;boolean transparency = false;boolean outline = true;float velocityScaling = 1;float dThetaScaling = 1;void setup(){smooth();size(windowSize, windowSize);background(255);movers = new CircleMover[nMovers];for(int i=0; i<movers.length; i++)movers[i] = new CircleMover(windowSize/2,windowSize/2);}color randomColor(){float alpha = 255;if(transparency)alpha = random(0,50);if(varyColors)return color((int)random(0,255),(int)random(0,255),(int)random(0,255),alpha);elsereturn color(255,255,255,alpha);}void draw(){// background(0);for(int i=0; i<movers.length; i++){movers[i].display();movers[i].move();}}
void keyTyped() {
if (key == 'c' || key == 'C') {
varyColors = !varyColors;
for(int i=0; i<movers.length; i++)
movers[i].fillColor = randomColor();
}
if (key == 'p' || key == 'P') {
polar = true;
}
if (key == 'r' || key == 'R') {
polar = false;
}
if (key == 'r' || key == 'R') {
polar = false;
}
if (key == 't' || key == 'T') {
transparency = !transparency;
if(transparency)
for(int i=0; i<movers.length; i++)
movers[i].fillColor = color(red(movers[i].fillColor),
green(movers[i].fillColor),
blue(movers[i].fillColor),
random(0,50));
else
for(int i=0; i<movers.length; i++)
movers[i].fillColor = randomColor();
}
if (key == 'o' || key == 'O') {
outline = !outline;
}
if (key == 's' || key == 'S') {
decreasingSize = !decreasingSize;
}
if (key == 'i' || key == 'I') {
if(maxTraverses == 0)
maxTraverses = 1;
else
maxTraverses = 0;
}
if (key == '-') {//turn less
dThetaScaling = dThetaScaling/1.2;
}
if (key == '_') {//turn more
dThetaScaling = dThetaScaling*1.2;
}
if (key == '+') {//faster
velocityScaling = velocityScaling*1.2;
}
if (key == '=') {//slower
velocityScaling = velocityScaling/1.2;
}
if (key == '[') {//smaller
diamInit = diamInit/1.2;
}
if (key == '{') {//bigger
diamInit = diamInit*1.2;
}
if (key == ']') {//less
nMovers--;
if(nMovers<1)
nMovers = 1;
movers = new CircleMover[nMovers];
for(int i=0; i<movers.length; i++)
movers[i] = new CircleMover(windowSize/2,windowSize/2);
}
if (key == '}') {//more
nMovers++;
movers = new CircleMover[nMovers];
for(int i=0; i<movers.length; i++)
movers[i] = new CircleMover(windowSize/2,windowSize/2);
}
if (key == 'b') {//clear
fill(255);
noStroke();
rect(0,0,windowSize,windowSize);
for(int i=0; i<movers.length; i++)
movers[i] = new CircleMover(windowSize/2,windowSize/2);
}
if (key == ' ') {//reset
fill(255);
noStroke();
rect(0,0,windowSize,windowSize);//blank screen
diamInit = 50;
maxTraverses = 0; //number of trips each mover takes. for infinite, 0
polar = true;
decreasingSize = true;
varyColors = false;
transparency = false;
outline = true;
velocityScaling = 1;
dThetaScaling = 1;
nMovers = 10;
movers = new CircleMover[nMovers];
for(int i=0; i<movers.length; i++)
movers[i] = new CircleMover(windowSize/2,windowSize/2);
}
}
void mouseClicked() {
fill(255);
noStroke();
rect(0,0,windowSize,windowSize);
for(int i=0; i<movers.length; i++)
movers[i] = new CircleMover(windowSize/2,windowSize/2);
}
No hay comentarios:
Publicar un comentario