Coding- Processing task- Java

Today i had to create an array of colours and randomly fill a square with one of the colours from your array when the mouse is clicked.

The code i used 
//size of the canvas
//setup
void setup (){
size (600,300);
}

// choice of colours using colour chart
int rColor = int(random(0,7));
color[] myColors ={#B77EC9,#863A7C,#3DE06A,#ED5B22,#EDE322,#FF0527,#05FFFD,#FFF705};
//draw, size and colour of my shape

void draw () {
fill(myColors[rColor]);
size (200,200);
rect(80,80, 80,80);
}
//what happens(colour changes) when mouse is clicked
void mouseClicked (){
rColor= int(random(0,7));

}

If you add more colours you must make sure you change the number in the section mouse clicked to make sure the colours get picked up.

Screen Shot 2014-10-16 at 16.13.08

Advertisements