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 & HelpSyntax Questions › Help: making eyes swell
Page Index Toggle Pages: 1
Help: making eyes swell (Read 929 times)
Help: making eyes swell
Oct 23rd, 2009, 9:39am
 
I'm trying to make an animation of a pair of eyes' pupils swelling up. Eventually I want it to look like they're getting so surprised that they fill up the rest of the eye and fill the entire screen with black. first I want to be able to control the growth so it stops at a certain point. I can't make it work. I've gone back through the blue processing book and im beating my head against a wall. I have no idea why except that I can't use an integer and float...which doesn't make sense.

can someone explain what I'm screwing up, please?
thank you


void setup (){
 noStroke ();
 smooth();
 noLoop();
 size (400, 400);
 noStroke ();
 smooth();
 noLoop();
 int y = 140.0;
 int x = 210.0;
 int c = 60.0;
}
 
void draw(){

 frameRate (30);
 stroke (55);
 ellipse (200, 100, 100, 100);
 ellipse (130, 150, 100, 100);
 fill (#000000);
 ellipse (x, x-100, c, c);
 ellipse (y, y+20, c, c);
 if (x > 170){
   x -= 1;
   if (y > 90){
     y -= 1;
     if (c < 100){
       c += 1;
     }
   }
 }
}
Re: Help: making eyes swell
Reply #1 - Oct 23rd, 2009, 11:30am
 
Problem 1
Code:

int y = 140.0;
int x = 210.0;
int c = 60.0;

will not work because x,y and z are declared as int but 140.0 will be treated as a float because of the decimal point.

Also because they are declared in setup() they are cannot be used in the draw() method. They need to be declared as global i.e. before the
setup() method.

Finally the size() method should be the first statement in the setup() method.

The code now looks like
Code:
int x,y,c;

void setup (){
size (400, 400);
noStroke ();
smooth();
noLoop();
noStroke ();
smooth();
noLoop();
y = 140;
x = 210;
c = 60;
}

The draw method is unchanged.

Hope this helps. Smiley
Re: Help: making eyes swell
Reply #2 - Oct 23rd, 2009, 11:35am
 
Something like this ?

Code:
 int c = 60; 
int d = 1;

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

void draw()
{
stroke (55);
fill(255);
ellipse (200, 100, 100, 100);
 fill (0);
ellipse (200, 140-c/2, c, c);

fill (255);
ellipse (130, 150, 100, 100);
 fill (0);
ellipse (130, 190-c/2, c, c);

if(c < 30) d = 1;
else if(c > 90) d = -1;

c += d;

}
Re: Help: making eyes swell
Reply #3 - Oct 23rd, 2009, 12:10pm
 
Thank you posters!

so some immediate questions:
JR, why is the framerate under the setup instead of draw? all the examples i've read have gone under draw?
why did you use int instead of float? when does one use float instead of int?
could i use more than two int commands?

the syntax for programming is hard to get the hang of
Re: Help: making eyes swell
Reply #4 - Oct 23rd, 2009, 12:18pm
 
Dizzle wrote on Oct 23rd, 2009, 12:10pm:
all the examples i've read have gone under draw
Perhaps you looked at wrong examples I sampled a couple of Processing official examples and they set it in setup(). Which makes sense: the frame rate has rarely to change during a sketch, no need to set it repeatedly.
It is true for lot of settings that you don't plan to change during the sketch, like smooth(), textFont(), or even strokeWidth() (but you might have reasons to change the last two, just pointing out often sketches set it over and over without real need).

Quote:
why did you use int instead of float when does one use float instead of int
When you need a fractional quantity... In general, coordinates, loop number, number of objects, etc. are integer. Random numbers, some quantities, angles, etc. can be float.

Quote:
could i use more than two int commands
Commands Perhaps you mean declarations You can use as many as you want/need.
Re: Help: making eyes swell
Reply #5 - Oct 23rd, 2009, 1:50pm
 
Dizzle wrote on Oct 23rd, 2009, 12:10pm:
the syntax for programming is hard to get the hang of


Practice practice practice. It's all very logical, you'll get it in the end Smiley

Page Index Toggle Pages: 1