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

2015/7/10

Drawing 300 stars in random locations

spazonred1998 spazonred1998

2015/7/10

#
Hi, Can someone help. I've got this but it doesn't like the last line new Star /** * Draw stars in random locations in space */ private void makeStar() { { int x,y; x = Greenfoot.getRandomNumber(getWidth()); y = Greenfoot.getRandomNumber(getHeight()); GreenfootImage background = getBackground(); GreenfootImage image = new GreenfootImage(getWidth(),getHeight()); image.setColor(Color.WHITE); image.fillOval(2,2,x,y); setBackground(image); addObject(new Star(), x, y);
danpost danpost

2015/7/10

#
What are you doing? * Are you trying to draw the star on the background image of the world or add a Star actor object into the world? * Why are you creating an image the size of the world within the code? * Did you refer to the documentation on the 'fillOval' method before trying to use it? (your parameters are not what I think you wanted)
spazonred1998 spazonred1998

2015/7/11

#
This is the assignment. I all ready created random asteroids using a loop. Modify the constructor so that it paints 300 stars. Use a loop to achieve this. You can paint a star by painting a very small pixel on the background image. Study the existing code to see how to paint onto the background. Then consult the documentation for the greenfoot image class to find out how to paint a circle. you may like to start by initially drawing just one single star. Then extend your code to include a loop to paint all the stars. Make sure you write the star-painting code in a separate method, not in the constructor directly.
davmac davmac

2015/7/11

#
Use 'code' tags for your code, please. I was going to try and help, but it is too hard to copy/paste or refer to lines of your code.
You need to login to post a reply.