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

2014/10/6

Can someone translate this alrgoritm for me?

Nnacheta56 Nnacheta56

2014/10/6

#
Make the screen 800 pixels wide by 600 pixels high, with 1 pixel per cell 2) Get the background and store it in a variable called background 3) Set the color to green 4) Fill the background with green 5) Using a loop put 25 red circles with a diameter of 10 and filled with red in different random positions all over the world
danpost danpost

2014/10/6

#
The first four steps seems pretty straight-forward (one statement per step). The last one will take several lines of code; however, everything is still pretty much given (loop, 25 red circles of diameter 10, random placed within the world). At least try something, and if you get stuck on a specific step, then show what you tried and ask for help on that step.
Nnacheta56 Nnacheta56

2014/10/6

#
mport greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot) import java.awt.Color; public class World extends World { static GreenfootImage background = null; /** * Create the world (the beach). Our world has a size * of 800x600 cells, where every cell is just 1 pixel. */ public World() { super(800, 600, 1); background = new GreenfootImage(getBackground()); image.setColor (0,128,0); image.fillWorld; (This is what i have so far, i just need some help with the last one) :)
Nnacheta56 Nnacheta56

2014/10/6

#
mport greenfoot.*;  // (World, Actor, GreenfootImage, and Greenfoot)
import java.awt.Color;
public class World extends World
{
    static GreenfootImage background = null;

    /**
     * Create the world (the beach). Our world has a size 
     * of 800x600 cells, where every cell is just 1 pixel.
     */
    public World()
    {
        super(800, 600, 1);
        background = new GreenfootImage(getBackground());
        image.setColor (0,128,0);
        image.fillWorld;
        
danpost danpost

2014/10/6

#
By creating a 'new GreenfootImage' of the background (see line 14), you loose the reference of the image actually being the world background. Just set 'background' to the background. On lines 15 and 16 you are calling 'setColor' and 'fillWorld' (which is no even a method call) on 'image', which is not defined. Your variable name was 'background', not 'image'. Refer to the GreenfootImage API for the proper way to fill an image will a given color.
Nnacheta56 Nnacheta56

2014/10/6

#
Alright I just wanted some assitance on the loops, i'm not familiar with them yet
danpost danpost

2014/10/6

#
You should check out The For Loop in the java tutorials.
Nnacheta56 Nnacheta56

2014/10/6

#
Alright thanks i figured it out but do you know What is it called when open { and close } braces surround and group together lines of code?
danpost danpost

2014/10/6

#
Nnacheta56 wrote...
do you know What is it called when open { and close } braces surround and group together lines of code?
That is called a block, or a block of code. A set is used to enclose the code for a class, others are used to enclose the code for methods and constructors, and still others are used to enclose the code for specific operations (such as 'if', 'while', 'do', 'for', 'switch', etc.).
You need to login to post a reply.