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 › GUarg!!! stupid syntax
Page Index Toggle Pages: 1
GUarg!!! stupid syntax (Read 432 times)
GUarg!!! stupid syntax
Aug 4th, 2009, 11:58am
 
I have many questions:
I have made this function invert, since random values tend to normalize in the middle so it's not very interesting as most of them turn out grey.
So what invert does is it'll try to polarize the values, by pushing it to the edge closer to 0 or 255.
But it won't compile, I kept getting
"unexpected token: float" on this line:
float invert (float in)

what's wrong?
full codes below, i know it's a silly silly bug...

======================
float invert (float in)
{
 if (in >= 128)
 {
   return 256 - (in - 128);
 }
 else
 {
   return in - 128;
 }
}
 
 size(500,500);
  for(int i=0; i<width*3; i++)
   {
     float r = random(width);
     float s = random(width);
     float t = random(width);
     float v = random(width);
     
     float rrr = random(255);
     float ggg = random(255);
     float bbb = random(255);
     fill(invert(rrr), invert(ggg), invert(bbb), 10);
     noStroke();
     rect(r,s,t,v);
   }

==========================



Another question: my setup() never work as well...
Now whenever I want to set a screen size i HAVE to do

size(500,500);
just by itself, and if I try to enclose it into setup() { //here }
the screen size will still change to 500,500, but nothing after setup() function can be executed Sad

HELP
Re: GUarg!!! stupid syntax
Reply #1 - Aug 4th, 2009, 2:00pm
 
running programms should have a setup(){} where you define the size etc. and a draw() where the rest happens

its explained here : http://processing.org/learning/gettingstarted/

so changing that and it seems to work:

Code:
void setup(){
size(500,500);
}

float invert (float in)
{
if (in >= 128)
{
  return 256 - (in - 128);
}
else
{
  return in - 128;
}
}

void draw(){

 for(int i=0; i<width*3; i++)
  {
    float r = random(width);
    float s = random(width);
    float t = random(width);
    float v = random(width);
   
    float rrr = random(255);
    float ggg = random(255);
    float bbb = random(255);
    fill(invert(rrr), invert(ggg), invert(bbb), 10);
    noStroke();
    rect(r,s,t,v);
  }}

Page Index Toggle Pages: 1