Merah Putih – Source code

Below is processing code for program in my previous post. A lot of explanation already given in this post. To run it, you can paste the source code into online processing sketch. Feel free to experiment with various color and flower size😀.

//Screen size
final int SCREEN_HEIGHT = 400;
final int SCREEN_WIDTH = 400;

//Flower parameter
final int MIN_DIAMETER = 1;
final int MAX_DIAMETER = 10;

//RGBA value range : 0 - 255
int min_red, min_blue, min_green, min_alpha;
int max_red, max_blue, max_green, max_alpha;

int x, y;

void setup()
{
   size(SCREEN_WIDTH, SCREEN_HEIGHT);
   noStroke();
   background(0);
   smooth();        //Enable anti-aliasing

   min_red = 220;
   max_red = 255;
   min_green = 0;
   max_green = 0;
   min_blue = 0;
   max_blue = 0;
   min_alpha = 10;
   max_alpha = 150;

   x = 0;
   y = 0;
}

void draw()
{
   int r, g, b, a; //Flower color
   int d;          //Flower diameter

   //Bangkitkan satu nilai acak
   r = (int)random(min_red, max_red);
   g = (int)random(min_green, max_green);
   b = (int)random(min_blue, max_blue);
   a = (int)random(min_alpha, max_alpha);
   d = (int)random(MIN_DIAMETER, MAX_DIAMETER);

   fill(r, g, b, a);
   drawFlower(x, y, d);

   x = x + 10;
   if (x > width) {  //Newline
      x = 0;
      y = y + 10;
   }
   if (y > height/2) { //Change colour
      max_green = max_blue = 255;
      min_green = min_blue = 240;
   }
}

void drawFlower(int x, int y, int d){
   ellipse(x, y, d, d);
   ellipse(x + d/2, y - d/2, d, d);
   ellipse(x + d/2, y + d/2, d, d);
   ellipse(x - d/2, y + d/2, d, d);
   ellipse(x - d/2, y - d/2, d, d);
}

One thought on “Merah Putih – Source code

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s