This is my project Interaction Defined
1. Start up by clearing the screen in a random basic color, then waiting for a keystroke. (5 points)
2. Wait for a keystroke (only from the list below), then continuously perform the action associated with that
keystroke until another key is pressed:
Keypress Action
c Pressing “c”, clear the screen to a “white” color. (5 pts)
r Pressing “r”, clears the screen to a random color. (5 pts)
1 Pressing “1” (the number one), will draw continuous randomly-placed points in random colors. (10 pts)
2 Pressing “2”, will draw continuous random-lengthed lines in random colors. (10 pts)
3 Pressing “3”, will draw continuous random-sized circles in random colors. (10 pts)
4 Pressing “4”, will draw continuous random-sized rectangles in random colors. (10 pts)
e Pressing “e”, will end all drawing until the next “1”, “2”, “3”, “4”, or “5” is pressed. (5 pts)
f Pressing “f”, will toggle the “fill-mode” of the circles and rectangles. So for example, if I press “3”,
random empty-circles will be drawn in random colors. If I then press “f”, then any new circles drawn
should be filled with the same random color. If I then press “f” again, then any new circles drawn will be
empty. The key “f” acts as a toggle (an on-off switch) for filling new shapes being drawn. (20 pts)
I am having trouble adding the color to my project.. here is my code
public class Canvas extends World
{
/**
* Constructor for objects of class Canvas.
*
*/
public Canvas()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
GreenfootImage background = getBackground();
background.fill();
}
private boolean oneCheck = false;
public void act(){
java.lang.String k = Greenfoot.getKey();
GreenfootImage background = this.getBackground();
if (Greenfoot.isKeyDown("c"))
{
background.fill(white);
}
if(Greenfoot.isKeyDown("r"))
{
}
if(Greenfoot.isKeyDown("1"))
{
}
if (Greenfoot.isKeyDown("2"))
{
}
if (Greenfoot.isKeyDown("3"))
{
}
if (Greenfoot.isKeyDown("4"))
{
}
if (Greenfoot.isKeyDown("5"))
{
}
}
}
Im stuck..