drawing on screen after region clicked processing - processing

I'm trying to make it so that when the user clicks the pencil icon in the program they are allowed to draw until the pencil has been clicked again. ive not added in a toggle yet but my current problem is that i get the desired behaviour in the mouse region which i specified but nowhere else on the screen, also please excuse my code its devolved a lot while playing with it, however by running it in its currrent state you should see what bug im talking about.
thanks
PImage[] img = new PImage[3];
boolean drawPencil = false;
boolean draw = false;
void setup() {
size(960, 720);
for (int i = 0; i < img.length; i++)
img[i] = loadImage("image"+i+".png");
//an array of images that sorts and load them into our program
image(img[0],0,0);
img[0].resize(width, height);
// set the desired image to screen size
}
void mousePressed() {
if (mouseX > 772 && mouseX < 864 && mouseY > 1 && mouseY < 74) {
drawPencil = true;
draw = true;
// if the user clicks the pencil icon they will begin to draw
}
}
void mouseReleased()
{
draw = false;
}
void draw() {
if (draw) {
stroke(255);
line(mouseX, mouseY, pmouseX, pmouseY);
}
if (key == 'w'||key == 'W') {
image(img[0],0,0);
img[0].resize(width, height);
println(drawPencil);
}
}

Way better post than the last. I think I now get what you want. I coded you a short example so you can get the hang of it. Here's what it will do:
PImage img;
boolean canDraw;
void setup() {
size(960, 720);
background(255);
img = loadImage("pencil.png");
}
void draw() {
if (canDraw) {
fill(color(0, 128, 0));
} else {
fill(color(128, 0, 0));
}
rect(800, 1, 100, 100);
image(img, 800, 1, 100, 100);
if (canDraw && mousePressed) {
stroke(0);
line(mouseX, mouseY, pmouseX, pmouseY);
}
}
void mouseClicked() {
if (mouseX > 800 && mouseX < 800+img.width && mouseY > 1 && mouseY < 1+img.height) {
canDraw = !canDraw;
}
}
I'll hang around in case you want to ask questions about this. Have fun!

Related

Trying to use multiple instances of Mouse pressed

I’m trying to add a feature where you can click on different parts of the sketch and have an image randomly generated. It worked for the first time, but when I add another if mouse pressed function, it triggers all the mouse pressed code and all of the sets of images go off at the same time. I’m not sure how to isolate it so that just one goes off if it’s in the right spot.
Here is my code for the last attempt, I tried to isolate the mouse pressed function with a push and pop Matrix, which didn’t work.
PImage stage;
PImage model;
PImage [] hat = new PImage [5];
PImage [] pants = new PImage [4];
PImage [] shirt = new PImage [5];
int choice = 0;
int page = 0;
void setup() {
size (800, 800);
stage = loadImage("background.png");
background(255);
image(stage, 0, 0);
hat[0] = loadImage ("hat1.png");
hat[1] = loadImage ("hat2.png");
hat[2] = loadImage ("hat3.png");
hat[3] = loadImage ("hat4.png");
pants[0] = loadImage ("pant1.png");
pants[1] = loadImage ("pant2.png");
pants[2] = loadImage ("pant3.png");
pants[3] = loadImage ("pant4.png");
}
void draw() {
println(mouseX, mouseY); //398, 237 for hats.
image(stage, 0, 0);
pushMatrix();
if (dist(398, 237, mouseX, mouseY) <90 && mousePressed) choice = floor(random(4));
image(hat[choice], 349, 98);
popMatrix();
pushMatrix();
if (dist(404, 363, mouseX, mouseY) <90 && mousePressed) choice = floor(random(4));
image(pants[choice], 228, 263);
popMatrix();
}
The issue is that you're using the same variable for all the clothing items. So when you click on the hat button, it sets choice to a random number (let's say 2). Then you display hat[choice] and then you also display pants[choice]. One way around this is to have multiple different choice variables, hatChoice and pantsChoice. When you click on the hat button, it randomizes hatChoice, and when you click on the pants button, it randomizes pantsChoice. Something like this:
if (dist(398, 237, mouseX, mouseY) <90 && mousePressed) hatChoice = floor(random(4));
image(hat[hatChoice], 349, 98);
if (dist(404, 363, mouseX, mouseY) <90 && mousePressed) pantsChoice = floor(random(4));
image(pants[pantsChoice], 228, 263);
I also second #rjw1428's recommendation of using mouseClicked() instead of if (mousePressed). You can do something like this:
//your global variables...
int hatChoice = 0;
int pantsChoice = 0;
void setup() {
//your setup stuff...
}
void draw() {
image(stage, 0, 0);
image(hat[hatChoice], 349, 98);
image(pants[pantsChoice], 228, 263);
}
void mouseClicked() {
if (dist(mouseX, mouseY, 398, 237) < 90) {
hatChoice = floor(random(4));
}
if (dist(mouseX, mouseY, 404, 363) < 90) {
pantsChoice = floor(random(4));
}
}
This isn't a perfect solution, but to implement what you're trying to do, i might do this
PImage stage;
PImage model;
PImage [] hat = new PImage [5];
PImage [] pants = new PImage [4];
PImage [] shirt = new PImage [5];
int selectedHat = -1;
int selectedPants = -1;
int selectedShirt = -1;
int choice = 0;
int page = 0;
void setup(){
size (800,800);
stage = loadImage("background.png");
background(255);
image(stage,0,0);
initializeImages()
}
void draw(){
println(mouseX, mouseY); //398, 237 for hats.
image(stage,0,0);
if (selectedHat > 0) {
image(hat[selectedHat], 349,98);
}
if (selectedPants > 0) {
image(pants[choice], 228,263);
}
}
void mouseClicked() {
if(dist(404,363, mouseX, mouseY) <90 && mousePressed) {
selectedPants = floor(random(4));
}
if(dist(398,237, mouseX, mouseY) <90 && mousePressed) {
selectedHat = floor(random(4));
}
}
void initializeImages() {
hat[0] = loadImage ("hat1.png");
hat[1] = loadImage ("hat2.png");
hat[2] = loadImage ("hat3.png");
hat[3] = loadImage ("hat4.png");
pants[0] = loadImage ("pant1.png");
pants[1] = loadImage ("pant2.png");
pants[2] = loadImage ("pant3.png");
pants[3] = loadImage ("pant4.png");
}
Then if you wanted to clear, have an IF check for the location (button) that you want to select to clear, and your function could return all the 'selected' values back to -1

How to use mousePressed() for 2 different events in processing?

I am working on my university project and came across an issue. I am creating a visualization for some data and want to use mousePressed() for different events, but when I try to add another event to mousePressed() it will not run as the code does not know which event to run (when the mouse is pressed it fires both events).
I made an event that allows the user to click the main menu buttons and want to make another event when the user is in the pieChartPage(), they are able to click on the PS_Button (which is a PlayStation Logo) to display a description. Right now the user is able to hover over the PS_Button and the description appears but I want the user to click on the PS_Button so that the description stays on the screen. I created a class 'ImageButton' for the description formatting and I am not sure how, if possible, to add the mousePressed() code into that class and still work with the rest of the code.
Here is my code:
In the setup() draw() page: mousePressed() - line 180, pieChartPage() - line 244
https://drive.google.com/drive/folders/1d5y2Ksq-y05J8tLiyK-1P2uwLjBhm-iH?usp=sharing
The link contains the code and the data used within the code.
Any help would be very appreciated, thank you.
setup() draw():
PieChart pieChart; //pie chart
PImage PS_Button, XBOX_Button, NINTENDO_Button; //creating variables for the images to be used
ImageButton psImageDscpt, xboxImageDscpt, nintendoImageDscpt;
void setup() {
size(1200, 800);
//functions to make the render of the program Apple Retina displays and Windows High-DPI displays look smoother and less pixelated
pixelDensity(2);
smooth();
loadData();
//Pie Chart
//pie chart for pie chart page
pieChart = new PieChart();
psImageDscpt = new ImageButton("Sony", 800, 480, 300, 200);
xboxImageDscpt = new ImageButton("Microsoft", 20, 425, 250, 200);
nintendoImageDscpt = new ImageButton("Nintendo", 925, 75, 200, 300);
}
void draw() {
switch(state) {
case 2:
// pie chart
pieChartPage();
drawMenuButton();
break;
case 3:
bubbleChartPage();
drawMenuButton();
// pie chart
break;
case 4:
scatterGraphPage();
drawMenuButton();
// pie chart
break;
default:
// menu
// the default case means "everything else" and in our case it will be the menu so you cannot have an impossible case
drawMenu();
drawMenuButton();
}
}
Current mousePressed() and commented is the code I want to add:
void mousePressed() {
switch(state) {
case 2: // pie chart page
ClickedMenuButton();
println("Going back to state home from PC");
//state = 1;
break;
case 3: // bubble chart page
ClickedMenuButton();
println("Going back to state home from BG");
break;
case 4: // scatter graph page
ClickedMenuButton();
println("Going back to state home from SG");
break;
default:
// menu
ClickMenu();
}
}
//void mousePressed() {
// if ( mouseX > psImgX && mouseX < (psImgX + PS_Button.width) && mouseY > psImgY && mouseY < (psImgY + PS_Button.height)) {
// psImageDscpt.drawPieChartDscpt();
// }
//}
void pieChartPage() in setup() draw() page:
//page for pie chart visualisation
void pieChartPage() {
background(10);
//psImgX = 100;
//psImgY = 50;
//xboxImgX = 200;
//xboxImgY = 50;
//nintendoImgX = 300;
//nintendoImgY = 50;
PS_Button = loadImage("ps_logo.png"); //loading images from program folder
psLegend = loadImage("ps_logo.png");
XBOX_Button = loadImage("xbox_logo.png");
xboxLegend = loadImage("xbox_logo.png");
NINTENDO_Button = loadImage("nintendo_logo.png");
nintendoLegend = loadImage("nintendo_logo.png");
//int psImgX, psImgY, xboxImgX, xboxImgY, nintendoImgX, nintendoImgY;
PS_Button.resize(100, 0); //size of the button, all are the same
XBOX_Button.resize(100, 0);
NINTENDO_Button.resize(100, 0);
psLegend.resize(75, 0);
xboxLegend.resize(75, 0);
nintendoLegend.resize(125, 0);
tint(225);// set tint of buttons to be zero
image(PS_Button, psImgX, psImgY); //drawing image to the screen
image(XBOX_Button, xboxImgX, xboxImgY);
image(NINTENDO_Button, nintendoImgX, nintendoImgY);
//drawing legend and tints represent the company's colour respectively
tint(pieChartColours[1]);
image(psLegend, 65, 75);
tint(pieChartColours[2]);
image(xboxLegend, 65, 175);
tint(pieChartColours[0]);
image(nintendoLegend, 45, 285);
pieChart.pieChart(width/2, height/2, 400, values_PieChart, pieChartColours); //draws the pie chart into the window
textSize(12);
if (mouseX > psImgX && mouseX < (psImgX + PS_Button.width) && mouseY > psImgY && mouseY < (psImgY + PS_Button.height)) {
psImageDscpt.drawPieChartDscpt();
} else if (mouseX > xboxImgX && mouseX < (xboxImgX + XBOX_Button.width) && mouseY > xboxImgY && mouseY < (xboxImgY + XBOX_Button.height)) {
xboxImageDscpt.drawPieChartDscpt();
} else if (mouseX > nintendoImgX && mouseX < (nintendoImgX + NINTENDO_Button.width) && mouseY > nintendoImgY && mouseY < (nintendoImgY + NINTENDO_Button.height)) {
nintendoImageDscpt.drawPieChartDscpt();
} else {
psImageDscpt.drawPieChartDscpt();
xboxImageDscpt.drawPieChartDscpt();
nintendoImageDscpt.drawPieChartDscpt();
}
//legend text
fill(225);
text("Sony / PlayStation", 55, 150);
text("Microsoft / XBOX", 52.5, 260);
text("Nintendo", 80, 340);
textSize(40);
fill(pieChartColours[0]);
text("/50", 230, 330);
fill(pieChartColours[1]);
text("/50", 215, 130);
fill(pieChartColours[2]);
text("/50", 185, 230);
fill(150,0,0);
textSize(60);
text("64%", 590, 350);
fill(0,150,0);
textSize(20);
text("7%", 460, 465);
fill(0,0,150);
textSize(40);
text("11%", 565, 525);
homeButtonBar.Draw();
}
ImageButton class:
class ImageButton {
String pieDscptLabel;
int xPos1, yPos1, xPos2, yPos2;
float wDiam1, hDiam1;
ImageButton (String pieDscptLabel, int xPos1, int yPos1, float wDiam1, float hDiam1) {
this.pieDscptLabel=pieDscptLabel;
this.xPos1=xPos1;
this.yPos1=yPos1;
this.wDiam1=wDiam1;
this.hDiam1=hDiam1;
}
void drawPieChartDscpt() { //draws the bubbles description
noFill();
stroke(225);
rect(xPos1, yPos1, wDiam1, hDiam1, 20);
textAlign(LEFT, BASELINE);
fill(200);
text(pieDscptLabel, xPos1+10, yPos1+20);
}
void mousePressed() {
if ( mouseX > psImgX && mouseX < (psImgX + PS_Button.width) && mouseY > psImgY && mouseY < (psImgY + PS_Button.height)) {
psImageDscpt.drawPieChartDscpt();
println("it works");
}
}
}
you don't need to write two mousePressed() method, just test the cases inside the method to differentiate which case you are working on, after some reading I figured your state variable equals 2 when the user is on pieChartPage() So I moved your code inside the first mousePressed() and added the test, the method call to draw description works fine but you will have to change it to switch between visible/invisible instead of drawing when the user click, here is the updated code:
void mousePressed() {
if(state == 2)
{
if ( mouseX > psImgX && mouseX < (psImgX + PS_Button.width) && mouseY > psImgY && mouseY < (psImgY + PS_Button.height))
{
psImageDscpt.drawPieChartDscpt();
}
}
switch(state) {
case 2: // pie chart page
ClickedMenuButton();
println("Going back to state home from PC");
//state = 1;
break;
case 3: // bubble chart page
ClickedMenuButton();
println("Going back to state home from BG");
break;
case 4: // scatter graph page
ClickedMenuButton();
println("Going back to state home from SG");
break;
default:
// menu
ClickMenu();
}
}
Edit:
to keep the description on the screen you have 3 changes to do: first, you declare a boolean global variable on top and set it to false by default :
//boolean to hold the info whether we draw description or not
boolean show_ps_description=false;
Secondly, you change the Click on Playstation image event to inverse the previous boolean image instead of calling that draw method :
void mousePressed() {
if(state == 2)
{
if ( mouseX > psImgX && mouseX < (psImgX + PS_Button.width) && mouseY > psImgY && mouseY < (psImgY + PS_Button.height))
{
//inverte the boolean
show_ps_description=!show_ps_description;
}
}
...
}
Lastly you call your drawing method (drawPieChartDscpt()) in your draw loop after checking if our boolean is true:
void draw() {
switch(state) {
case 2:
// pie chart
pieChartPage();
drawMenuButton();
if(show_ps_description)
psImageDscpt.drawPieChartDscpt();
break;
...
}

Drawing a line in processing after a region of the screen has been pressed and the mouse is being clicked

when i click the region it continually draws instead of when im holding the mouse. also ill figure out how to toggle the pencil when clicked later on. i am very new.
void mousePressed() {
if (mouseX > 772 && mouseX < 864 && mouseY > 1 && mouseY < 74) {
//button 1 was just clicked, show button 2 instead
drawPencil = true;
}
}
}
void draw() {
if (drawPencil) {
stroke(255);
line(mouseX, mouseY, pmouseX, pmouseY);
}
}
I've written a small program which should give you an idea
boolean drawPencil;
void mousePressed() {
drawPencil = true;
}
void mouseReleased()
{
drawPencil = false;
}
void setup(){
size(800,800);
}
void draw() {
if (drawPencil) {
stroke(255);
line(mouseX, mouseY, pmouseX, pmouseY);
}
}
That's not how you do this. Here's a code snippet for you to experiment with. It'll react as follow:
float lastX, lastY;
void setup() {
size(800, 600);
}
void draw() {
background(0);
if (mousePressed) { // is true whenever a mouse button is held down
stroke(255);
line(mouseX, mouseY, lastX, lastY);
}
}
void mousePressed() { // run once every click
lastX = mouseX;
lastY = mouseY;
}
Have fun!

Making particles move around the object smoother

i was able to make particles go around the ellipse I created which was my previous question. Now I have another one, flow of the particles are not as smooth as i want, there is this diagonal looking shape they follow and when you move the mouse (the ellipse) you can see my lines of my "force" variable. Again I want particles to move like water floating around a rock in a river.
Link for the previous question I asked about same project
int NUM_PARTICLES = 9000;
ParticleSystem p;
Rock r;
void setup()
{
smooth();
size(700,700,P2D);
p = new ParticleSystem();
r = new Rock();
}
void draw()
{
background(0);
p.update();
p.render();
r.rock();
}
float speed = 2;
float rad = 100;
class Particle
{
PVector position, velocity;
float initialPosY;
Particle()
{
position = new PVector(random(width), random(height));
initialPosY = position.y;
velocity = new PVector();
}
void update()
{
velocity.x = speed;
velocity.y = 0;
float d = dist (position.x, position.y, mouseX, mouseY);
if (d < rad) {
float force = map(d, 0, rad, speed, 0);
if (position.x < mouseX) {
if (position.y < mouseY) {
velocity.y = -force;
} else {
velocity.y = force;
}
} else {
if (position.y < mouseY) {
velocity.y = force;
} else {
velocity.y = -force;
}
}
position.add(velocity);
} else {
position = new PVector(position.x+speed, initialPosY);
}
if (position.x<0)position.x+=width;
if (position.x>width)position.x-=width;
if (position.y<0)position.y+=height;
if (position.y>height)position.y-=height;
}
void render()
{
stroke(255, 255, 255, 80);
point(position.x, position.y);
}
}
class ParticleSystem
{
Particle[] particles;
ParticleSystem()
{
particles = new Particle[NUM_PARTICLES];
for (int i = 0; i < NUM_PARTICLES; i++)
{
particles[i]= new Particle();
}
}
void update()
{
for (int i = 0; i < NUM_PARTICLES; i++)
{
particles[i].update();
}
}
void render()
{
for (int i = 0; i < NUM_PARTICLES; i++)
{
particles[i].render();
}
}
}
class Rock{
void rock()
{
noFill();
stroke(255);
strokeWeight(4);
ellipse(mouseX,mouseY,50,50);
}
}
It'll be a lot easier if you try to narrow your problem down to a smaller MCVE, like I did in the answer to your first question:
PVector position;
PVector speed;
void setup() {
size(500, 500);
position = new PVector(250, 0);
speed = new PVector(0, 1);
}
void draw() {
background(0);
if (dist(position.x, position.y, mouseX, mouseY) < 100) {
fill(255, 0, 0);
if (position.x < mouseX) {
position.x--;
} else {
position.x++;
}
} else {
fill(0, 255, 0);
}
ellipse(mouseX, mouseY, 100, 100);
fill(0, 0, 255);
ellipse(position.x, position.y, 20, 20);
position.add(speed);
if (position.y > height) {
position.y = 0;
}
if (position.x < 0) {
position.x = width;
} else if (position.x > width) {
position.x = 0;
}
}
Now that we have that, we can talk about how we might improve it.
Right now, our logic for having the particles avoid our obstacle is here:
if (dist(position.x, position.y, mouseX, mouseY) < 100) {
if (position.x < mouseX) {
position.x--;
} else {
position.x++;
}
}
Notice that we're always moving the particle by 1 pixel, which is why it looks blocky. What we need to do is smooth our transition out by moving the pixel only a little bit at first, and then moving it more as it gets closer to the obstacle.
You might user the lerp() or map() function for this, but for this simple example, we can simply use the dist() function.
Here is a super simple approach you might take:
float distance = dist(position.x, position.y, mouseX, mouseY);
if (position.x < mouseX) {
position.x -= 1000/(distance*distance);
} else {
position.x += 1000/(distance*distance);
}
Notice that by squaring the distance, I'm setting up a polynomical interpolation. In other words, the particle moves faster the closer it gets to the center of the boundary.
Again, you're going to have to play with this to get the exact effect you're looking for, but the basic idea is there: what you're looking for is an interpolation (how fast the particle moves) that scales with the distance from the boundary. You can use squaring to exaggerate the effect.
You could also use basic trig to make the particle follow a circular path.

Traffic Light sequence in Processing

I am trying to get this bit of code I have got and add another traffic light and car but going from right to left not from bottom to top. The car only moves when the light is amber or green and stops when red. I have tried copying the code and changing the names of the values but it just will not work. I have tried naming them all different names but it won't even show the other image I tried to put in for the other car. Can someone please tell/show me how I could add another traffic light and car but they move at different times?
TrafficLight light1 = new TrafficLight(100, 40);
int onTime = 2000;
int startTime = millis();
PImage car;
int carX, carY;
void setup() {
size(800, 600);
light1.changeColour("red");
light1.display();
car = loadImage("Car.png");
carX = 150;
carY = 300;
}
void draw() {
background(255);
if (millis() - startTime > onTime && light1.lightOn == "red") {
light1.changeColour("amber");
startTime = millis();
}
if (millis() - startTime > onTime && light1.lightOn == "amber") {
light1.changeColour("green");
startTime = millis();
}
if (millis() - startTime > onTime && light1.lightOn == "green") {
light1.changeColour("red");
startTime = millis();
}
light1.display();
image(car, carX, carY);
if (light1.lightOn == "green") {
carY -= 2;
}
{
}
if (light1.lightOn == "red") {
carY -= 0;
}
{
}
if (light1.lightOn == "amber") {
carY -= 1;
}
{
}
if (carY <= -200) {
carY = 500;
}
}
class TrafficLight {
int xpos;
int ypos;
String lightOn = "red";
TrafficLight(int x, int y) {
xpos = x;
ypos = y;
}
void changeColour(String lightColour) {
lightOn = lightColour;
}
void display() {
String lightColour = lightOn;
fill(0, 0, 0);
rect(xpos, ypos, 100, 220);//back panel
if (lightColour == "red") {
fill(255, 0, 0);
lightOn = "red";
} else {
fill(100, 0, 0);
}
ellipse(xpos + 50, ypos + 40, 60, 60);//red
if (lightColour == "amber") {
fill(255, 255, 0);
lightOn = "amber";
} else {
fill(100, 100, 0);
}
ellipse(xpos + 50, ypos + 110, 60, 60);//amber
if (lightColour == "green") {
fill(0, 255, 0);
lightOn = "green";
} else {
fill(0, 100, 0);
}
ellipse(xpos + 50, ypos + 180, 60, 60);//green
}
}
The code you've posted only contains one car, which makes this question hard to answer. Stack Overflow isn't really designed for general "how do I do this" type questions. It's more designed for specific "I tried X, expected Y, but got Z instead" type questions. That being said, I'll try to answer in a general sense:
Here's the short answer: you need to create a state for a second car, and then work with that state exactly how you work with the state of the first car. This might be easier if you encapsulate that state into a class, and then use two instances of that class.
Let's start out with a simpler example of a circle that moves vertically, and stops when we press the mouse:
MovingCircle verticalCircle;
void setup() {
size(600, 600);
verticalCircle = new MovingCircle(250, 250, 0, 5);
}
void mousePressed() {
verticalCircle.moving = !verticalCircle.moving;
}
void draw() {
background(0);
verticalCircle.step();
}
class MovingCircle {
float x;
float y;
float xSpeed;
float ySpeed;
boolean moving = true;
public MovingCircle(float x, float y, float xSpeed, float ySpeed) {
this.x = x;
this.y = y;
this.xSpeed = xSpeed;
this.ySpeed = ySpeed;
}
void step() {
if (moving) {
x+=xSpeed;
y+=ySpeed;
if (x > width) {
x = 0;
}
if (y > height) {
y = 0;
}
}
ellipse(x, y, 25, 25);
}
}
This program creates a circle that moves down the screen, and stops and starts when you click the mouse. Notice that I've encapsulated all of the information I need inside the MovingCircle class, so now if I want to add another one, I can just create another instance of that class and interact with it however I want.
Here's how I would add a horizontally moving circle:
MovingCircle verticalCircle;
MovingCircle horizontalCircle;
void setup() {
size(600, 600);
verticalCircle = new MovingCircle(250, 250, 0, 5);
horizontalCircle = new MovingCircle(250, 250, 5, 0);
}
void mousePressed() {
verticalCircle.moving = !verticalCircle.moving;
}
void keyPressed() {
horizontalCircle.moving = !horizontalCircle.moving;
}
void draw() {
background(0);
verticalCircle.step();
horizontalCircle.step();
}
This is just an example, but the principle is the same in your code: you need to encapsulate your state into a class, and then you can work with two instances of that class in order to have two moving cars.
Also, you should never use == to compare String values! Use the .equals() function instead!
if(lightColour.equals("red")){

Resources