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

2019/3/3

displayImage.drawOval won't draw a completely full circle

Abwatts Abwatts

2019/3/3

#
Hey, I'm not sure why but for some reason when I am trying to draw a circle using this code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void updateImage()
    {
        //Create an image of the set size using built in greenfoot commands
        GreenfootImage displayImage=new GreenfootImage(size,size);
 
        //Draw Circle
        displayImage.setColor(ballColor); //Set color to ballColor
        displayImage.drawOval(0, 0, this.getSize(), this.getSize()); //Is the problem here?
 
        //Display the number inside circle
        Font displayFont = new Font( (int)(size*0.75) );
        displayImage.setColor(ballColor.BLACK) //Set color to Black
        displayImage.setFont(displayFont);
        displayImage.drawString(Integer.toString(size),(int)(size*0.1),(int)(size*0.8));
        //Add the image as the new image for this object
        super.setImage(displayImage);
 
    }
That's how the circle looks: Is there a way that I can make it a full circle? Thanks a lot!
danpost danpost

2019/3/3

#
Abwatts wrote...
Is the problem here?
Yes. Subtract one from both dimensions.
Abwatts Abwatts

2019/3/3

#
danpost wrote...
Abwatts wrote...
Is the problem here?
Yes. Subtract one from both dimensions.
It worked like a charm, thanks! Would you mind explaining why you did so, please?
danpost danpost

2019/3/3

#
Abwatts wrote...
It worked like a charm, thanks! Would you mind explaining why you did so, please?
When drawing a shape, using the rectangle given, (int x, int y, int width, int height), the shape will be (width+1, height+1) in size. When filling, it will be of size (width, height) -- (just the way it is).
You need to login to post a reply.