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

2015/12/11

Create Stars and Create random stars are random colors

ThatGuy245 ThatGuy245

2015/12/11

#
My create random and create stars methods are making my stars random colors? any ideas would be awesome! :)
private void createStars(int number) 
    {
        GreenfootImage background = getBackground(); 

        // this method creates the stars seen in the world
        for(int i=0; i < number; i++) {            
            int x = Greenfoot.getRandomNumber( getWidth() );
            int y = Greenfoot.getRandomNumber( getHeight() );
            int color = 255;
            background.fillOval(x, y, 2, 2);
            background.setColorAt(x,y,new Color(color, color, color) );
        }
    }

    private void createChallengeStars(int number)
    {
        GreenfootImage background = getBackground(); 

        // this method creates the stars seen in the world, it also generates a random color for the stars
        for(int i=0; i < number; i++) 
        {            
            int x  = Greenfoot.getRandomNumber( getWidth() );
            int y  = Greenfoot.getRandomNumber( getHeight() );

            int starSize = (Greenfoot.getRandomNumber(3)*2)+10;
            background.setColor (new Color(Greenfoot.getRandomNumber(255 + 1), Greenfoot.getRandomNumber(255 + 1), Greenfoot.getRandomNumber(255 + 1)));
            background.fillOval(x, y, starSize, starSize);
        }   //end for  (int i= 0; i < number; i++)

    }

    private void createRandomStars(int number) 
    {
        GreenfootImage background = getBackground();         
        // this method creates the stars seen in the world, it also generates a random color for the stars
        for(int i=0; i < number; i++) {            
            int x = Greenfoot.getRandomNumber( getWidth() );
            int y = Greenfoot.getRandomNumber( getHeight() );
            int color = 255 - Greenfoot.getRandomNumber(230);
            background.fillOval(x, y, 2, 2);
            background.setColorAt(x,y,new Color(color, color, color));
        }

    }
danpost danpost

2015/12/11

#
The 'setColorAt' method only changes the color of one pixel of the image. Your 'createChallengeStars' method has code similar to what should be used in the other two methods.
You need to login to post a reply.