FAQ
 
 
Cover  \ Exhibition  \ Learning  \ Reference  \ Download  \ Discourse   
    Examples \ Tutorials \ Courses & Workshops
 
   
 
 
Examples for Processing (BETA) version 91+. If you have a previous version, use the examples included with your software. If you see any errors or have comments, please let us know.



Simple Curves
by REAS <http://reas.com>

Simple curves are drawn with simple equations. By using numbers with values between 0 and 1 in the equations, a series of elegant curves are created. The numbers are then scaled to fill the screen.

Updated 15 September 2002

   
// Simple Curves 
// by REAS <http://reas.com> 

 
void setup() { 
  size(200, 200); 
  colorMode(RGB, 100); 
  background(0); 
  noLoop(); 
} 
 
void draw() { 
  stroke(40); 
  beginShape(LINE_STRIP); 
  for(int i=0; i<width; i++) { 
   vertex(i, singraph((float)i/width)*height); 
  } 
  endShape(); 
  
  stroke(55); 
  beginShape(LINE_STRIP); 
  for(int i=0; i<width; i++) { 
   vertex(i, quad((float)i/width)*height); 
  } 
  endShape(); 
  
  stroke(70); 
  beginShape(LINE_STRIP); 
  for(int i=0; i<width; i++) { 
   vertex(i, quadHump((float)i/width)*height); 
  } 
  endShape(); 
  
  stroke(85); 
  beginShape(LINE_STRIP); 
  for(int i=0; i<width; i++) { 
   vertex(i, hump((float)i/width)*height); 
  } 
  endShape(); 
  
  stroke(100); 
  beginShape(LINE_STRIP); 
  for(int i=0; i<width; i++) { 
   vertex(i, squared((float)i/width)*height); 
  } 
  endShape(); 
} 
 
float singraph(float sa) { 
  sa = (sa - 0.5) * 1.0; //scale from -1 to 1 
  sa = sin(sa*PI)/2 + 0.5; 
  return sa; 
} 
 
float quad(float sa) { 
  return sa*sa*sa*sa; 
} 
 
float quadHump(float sa) { 
  sa = (sa - 0.5); //scale from -2 to 2 
  sa = sa*sa*sa*sa * 16; 
  return sa; 
} 
 
float hump(float sa) { 
  sa = (sa - 0.5) * 2; //scale from -2 to 2 
  sa = sa*sa; 
  if(sa > 1) { sa = 1; } 
  return 1-sa; 
} 
 
float squared(float sa) { 
  sa = sa*sa; 
  return sa; 
} 
 







   
  Processing is an open project initiated by Ben Fry and Casey Reas  
  © Info