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

2015/5/18

Exercise 8.32 in textbook

rgilmet rgilmet

2015/5/18

#
I am having trouble filling an image with dots. I either get no image printed or just the solid image. I am using the fillOval() method to place the dots in the image, but when I use setImage(image) I just get a solid color. Thanks for any help in advance.
danpost danpost

2015/5/18

#
It would be wise to show the actual code you were trying to use to create and set the image.
rgilmet rgilmet

2015/5/18

#
Here is the code: public ColorPatch() { GreenfootImage patch = new GreenfootImage(50, 50); patch.setColor(new Color(0, 0, 0)); patch.fill(); for (int loop = 0; loop < 100; loop++) { int dotX = Greenfoot.getRandomNumber(48) + 2; int dotY = Greenfoot.getRandomNumber(48) + 2; //patch.setColor(new Color(100, 100, 100)); patch.fillOval(dotX, dotY, 1, 1); } setImage(patch); }
danpost danpost

2015/5/18

#
The main problem is that there is little difference in color between the filled black color and the one hundred dark gray dots you are adding. The fact that the dots are pixel-sized (1, 1) does not help either. In other words, if you increase the size of the dots or brighten the color of them, they would be more visible.
rgilmet rgilmet

2015/5/20

#
Thanks so much for your help.
You need to login to post a reply.