This site requires JavaScript, please enable it in your browser!
Greenfoot back
flash007
flash007 wrote ...

2016/5/26

Why wont this make a triangle?

flash007 flash007

2016/5/26

#
as per my instructions i need to use for loops in this i imported java.awt.* and greenfoot.* and my screen size is 600,400,1.
public void triangles() 
    {
        GreenfootImage bg = new GreenfootImage(getBackground());
        for (int x=0; x<20; x++)
        {
            for (int y=0; y<20-x; y++)
            {
                bg.setColorAt(x,y,Color.GREEN);
            }

        }
    }
TIA, flash
danpost danpost

2016/5/26

#
For one thing, once the method has completed its execution, the 'bg' variable is lost. By creating a new GreenfootImage object, you are not dealing with the image returned by the use of 'getBackground'. but making a copy of the background image.
You need to login to post a reply.