18 Jul 2013

Creating rainbow using Processing programming language

Hello friends, meanwhile I was recalling back the days when I was learning processing language and suddenly thought of practicing a small experiment on it.  It was raining at my place and hence I thought of making an animated rainbow using processing programming language.

This is not-so-great program or project what so ever, but was fun doing it.

Animated Rainbow using Processing Language

Anybody interested may find the source code for the same below.



//processing program for creating an animated rainbow
//programmed by : Amit Biswal
//URL: http://amitbiswal.blogspot.com
int sunCenterX=650,sunCenterY=50;
int i=0,j=0;
void setup()
{
  size(700,500);
  background(255);
}
void draw()
{
  stroke(252,101,31);
  if(i<500 && j<500)
  {
    line(sunCenterX,sunCenterY,i-100,j+150);
    i+=10;
    j+=10;
  }
  else
  {
    i=0;j=0;
  }
  sun();
  rainbow(0,600);

}
void sun()
{
  noStroke();
  fill(255); //white
  ellipse(sunCenterX,sunCenterY,100,100);

  fill(252,101,31); //orange
  ellipse(sunCenterX,sunCenterY,95,95);
 }
void rainbow(int centerX,int centerY)
{
  fill(255); //white
  ellipse(centerX,centerY,860,860);

  fill(255,0,0); //red
  ellipse(centerX,centerY,850,850);

  fill(257,127,0); //orange
  ellipse(centerX,centerY,800,800);

  fill(255,255,0); //yellow
  ellipse(centerX,centerY,750,750);

  fill(0,255,0); //green
  ellipse(centerX,centerY,700,700);

  fill(0,0,255); //blue
  ellipse(centerX,centerY,650,650);

  fill(75,0,130); //indigo
  ellipse(centerX,centerY,600,600);

  fill(148,0,211); //violet
  ellipse(centerX,centerY,550,550);
  
  fill(255); //white
  ellipse(centerX,centerY,500,500);

}



The program is simple and self-explanatory. You can comment your queries below. If you can work over this and make some nice advanced version of this project then do share the code/link of your project. Thanks for reading.
Related Post :


0 comments:

Post a Comment

If you liked this blog then Join me at:
Facebook
Twitter
RSS