I am trying to get my program to pick a new random fill color from an array after the mouse is clicked. The section of code I am trying to implement it in currently is in the display section of the class "Master".
Here is my code so far:
int c1 = (int)random(0, 4);
int c2 = (int)random(0, 4);
int c3 = (int)random(0, 4);
int c4 = (int)random(0, 4);
int c5 = (int)random(0, 4);
int R[] = {
0, 224, 255, 35
};
int G[] = {
173, 0, 240, 31
};
int B[] = {
239, 139, 0, 32
};
int scr = 0;
int a = 1;
int[] fillColor; //Declare array
color r1 = color(R[c1], G[c1], B[c1]);
color r2 = color(R[c2], G[c2], B[c2]);
color r3 = color(R[c3], G[c3], B[c3]);
color r4 = color(R[c4], G[c4], B[c4]);
color r5 = color(R[c5], G[c5], B[c5]);
color m1 = color(R[c1], G[c1], B[c1]);
color m2 = color(R[c2], G[c2], B[c2]);
color m3 = color(R[c3], G[c3], B[c3]);
color m4 = color(R[c4], G[c4], B[c4]);
color m5 = color(R[c5], G[c5], B[c5]);
color pixelColor1;
color masterColor1;
//color fill1;
Score1 scr1; //declare the object
Circle crcl;
Master mstr;
void setup() {
//frameRate(200);
size(500, 500);
crcl = new Circle(250, 350, 85);
mstr = new Master(250, 200, 85);
scr1= new Score1();
pixelColor1= get(mouseX, mouseY);
masterColor1= get(250, 200);
fillColor = new int[5];
fillColor[0] = m1;
fillColor[1] = m2;
fillColor[2] = m3;
fillColor[3] = m4;
fillColor[4] = m5;
}
void draw() {
background(255);
crcl.display();
mstr.display();
scr1.display();
}
void mousePressed() {
//scr.select();
if (mousePressed == true) {
pixelColor1 = get(mouseX, mouseY);
masterColor1 = get(250, 200);
println(pixelColor1); // get color test
println(masterColor1); // get color test
//delay(200);
if ((masterColor1 == pixelColor1) && (mouseY > 264)) {
scr++;
mstr.display();
}
else {
mstr.display();
}
}
}
String begin(int a) {
String Buffer;
Buffer=nf(a, 1);
return(Buffer);
}
class Circle {
float x, y, diameter;
//float diameter;
Circle(float xpos, float ypos, float dia ) {
x = xpos;
y = ypos;
diameter = dia;
}
void display() {
noStroke();
fill(r1);
ellipse(x, y, 85, 85);
fill(r2);
ellipse(x+85, y, 85, 85);
fill(r3);
ellipse(x-85, y, 85, 85);
fill(r4);
ellipse(x-42, y+75, 85, 85);
fill(r5);
ellipse(x+43, y+75, 85, 85);
}
}
class Master { //Circle w/ stroke == master circle
float x, y, diameter;
Master(float xpos, float ypos, float dia ) {
x = xpos;
y = ypos;
diameter = dia;
}
void display() {
strokeWeight(5);
stroke(0);
fill(fillColor[0]); //need to set this up to produce a random fill color from array "fillColor"
//fill(random(fillColor))
ellipse(x, y, 85, 85);
ellipse(x, y, 85, 85);
}
}
class Score1 {
Score1() {
}
void display() {
noStroke();
textAlign(CENTER);
textSize(50);
fill(237, 28, 36);
text (""+begin(scr), 250, 100);
}
}
/*
void select() {
if (mousePressed == true) {
pixelColor1 = get(mouseX, mouseY);
masterColor1 = get(250, 200);
println(pixelColor1); // get color test
println(masterColor1); // get color test
//delay(200);
if ((masterColor1 == pixelColor1) && (mouseY > 264)) {
I am trying to set up a program that will increase the players score if the circle clicked on matches the "master" circles color and will rotate the color if the color doesn't match. I am thinking to use getColor for this however I am new to processing and am not sure how to start setting this up. Also I am trying to get a score counter going to keep track of the matches made. I was wondering if anyone may know of a good wat to execute this. My code so far is below. Thanks
int c1 = (int)random(0, 4);
int c2 = (int)random(0, 4);
int c3 = (int)random(0, 4);
int c4 = (int)random(0, 4);
int c5 = (int)random(0, 4);
int R[] = {
0, 224, 255, 35
};
int G[] = {
173, 0, 240, 31
};
int B[] = {
239, 139, 0, 32
};
color r1 = color(R[c1], G[c1], B[c1]);
color r2 = color(R[c2], G[c2], B[c2]);
color r3 = color(R[c3], G[c3], B[c3]);
color r4 = color(R[c4], G[c4], B[c4]);
color r5 = color(R[c5], G[c5], B[c5]);
Circle crcl; //declare the object
Score scr;
Master mstr;
void setup() {
size(500, 500);
crcl = new Circle(250, 350, 85);
mstr = new Master(250, 200, 85);
scr= new Score(250, 100);
//crcl.diameter = 85;
}
void draw() {
background(255);
crcl.display();
scr.display();
mstr.display();
/*
//////////My ideas so far on how i want to go forward with the program///////
scr.run();
if (mousePressed == true) {
Color = get(mouseX, mouseY);
}
if (Color == masterColor) {
scr1++; // add one point to the score counter on top
} else {
r1++; // change the fill to the next random fill color. Also will need function to make to fill rotate back to r1 after r5 has been reached.
}
if (score > 30) {
textSize(150);
text("END", 250, 50);
}
}
*/
}
class Circle {
float x, y, diameter;
//float diameter;
Circle(float xpos, float ypos, float dia ) {
x = xpos;
y = ypos;
diameter = dia;
}
void display() {
noStroke();
fill(r1);
ellipse(x, y, 85, 85);
ellipse(x, y, 85, 85);
}
}
class Master { //Circle w/ stroke == master circle