We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › growing ellipse with for loop
Page Index Toggle Pages: 1
growing ellipse with for loop (Read 563 times)
growing ellipse with for loop
May 30th, 2008, 1:01pm
 
Hi! thanks for having a look at this!

I wrote a simple programm where an ellipse grows from the center untill it is 300 pxl wide. then it starts again.

I want do do the same thing but with an for loop because it seems I just don´t understand for loops right and I´m keen on learning them.

float a =50f;

void setup(){
size(400,400);
frameRate(30);
}

void draw(){
background(0);


a = a+2f;
fill(0, a);
float yo = map(a,0,300,255,0);
stroke(yo);
strokeWeight(20);
ellipse(200,200,a,a);

if (a>300){
 a=50;
}
}

thank you for your help!
Re: growing ellipse with for loop
Reply #1 - May 30th, 2008, 1:45pm
 
Interesting effect.
I rewrote a bit the snippet: note I like to use constants, it is easier to change several parameters at once, maintaining consistency. It is just a good habit to take.
Code:
final float MIN = 50f;
final float MAX = 300f;
float a = MIN;

void setup(){
size(400,400);
frameRate(30);
}

void draw(){
background(0);

float alpha = int(map(a, MIN, MAX, 255, 0));
fill(#AABBCC, alpha);
stroke(alpha);
strokeWeight(20);
ellipse(width/2, height/2, a, a);
a = a+2f;
if (a > MAX){
a = MIN;
}
}

I discovered map (and norm) with your code, useful functions...

for loop: since draw() already loops, it isn't really necessary here.
But we can use one to duplicate the figure and parametrize it:
Code:
final float MIN = 50f;
final float MAX = 200f;
float a = MIN;
int center;

void setup(){
size(800,200);
frameRate(30);
}

void draw(){
background(0);

for (int i = 0; i < 4; i++)
{
float alpha = int(map(a, MIN, MAX, 255, 0));
fill(120, 180, i * 80, alpha);
stroke(alpha);
strokeWeight(6 * i);
ellipse((1 + 2 * i) * width/8, height/2, a, a);
a++;
if (a > MAX){
a = MIN;
}
}
//delay(50);
}
Re: growing ellipse with for loop
Reply #2 - Jun 2nd, 2008, 10:35pm
 
Hey Philo !
Thanks for your reply again!

Thats a good base to start with.
I´m doing a tangible music table sort of thing an
theese are my first visuals for the objects.
YEAH!



final float MIN = 0f;
final float MAX = 300f;
float a = MIN;
float b = MIN;
float c = MIN;
boolean circleAt100 = false;
boolean circleAt200 = false;

void setup(){
size(400,400);
frameRate(60);
}

void draw(){
background(0);  

float alpha = int(map(a, MIN, MAX, 255, 0));
fill(0, alpha);
stroke(alpha);
strokeWeight(20);
ellipse(width/2, height/2, a, a);
a = a+2f;
if (a > MAX){
 a = MIN;
}
if (a == 100){
circleAt100 = true;
}
if (circleAt100 == true){
 
float beta = int(map(b, MIN, MAX, 255, 0));
fill(0, beta);
stroke(beta);
strokeWeight(20);
ellipse(width/2, height/2, b, b);
b = b+2f;
if (b > MAX){
 b = MIN;
}
}

if (a == 200){
circleAt200 = true;
}
if (circleAt200 == true){
 
float gamma = int(map(c, MIN, MAX, 255, 0));
fill(0, gamma);
stroke(gamma);
strokeWeight(20);
ellipse(width/2, height/2, c, c);
c = c+2f;
if (c > MAX){
 c = MIN;
}
}

}
Page Index Toggle Pages: 1