incomplete Circle drawn with classes from PPP

107 views
Skip to first unread message

ken williams

unread,
Apr 21, 2021, 1:18:41 PM4/21/21
to PPP-public
I'm working through Programming Principles and Practice
and I'm stuck at drawing some Circles - which are drawn "fragmented".
Please see below.
1.0-0.jpeg2.20-20.jpeg3.30-30.jpeg4.50-50.jpeg5.100-100.jpeg

The Circle c1 below should have nothing to do with the Point x,
yet when I change the Point x from {0,0} to {20,20} , {30,30} , 
{50,50} or {100,100} I get these incomplete circles.

==========================

int main()
{
    const Point x{0, 0};
    Simple_window win{x, 600, 400, "Ch 13 Circle"};

    Circle c1{Point{100, 200}, 50};
    win.attach(c1);
    win.wait_for_button();
}


=================
Any idea what the problem is?
Thanks!

roscopik...@gmail.com

unread,
Apr 21, 2021, 5:01:16 PM4/21/21
to PPP-public
2021-04-21 (1).png2021-04-21.png

ive just recreated your code, and the codes fine. x is the point where the window is to display on the screen, have you looked at the Circle class?

roscopik...@gmail.com

unread,
Apr 21, 2021, 5:07:30 PM4/21/21
to PPP-public
with all three circles 2021-04-21 (3).png2021-04-21 (2).png

ken williams

unread,
Apr 22, 2021, 4:15:38 AM4/22/21
to PPP-public
Thanks!
What version of FLTK do you use?
(and from git or archive?)

I've checked the Circle class and it's just like in the book (2nd edition):


struct Circle : Shape
{
Circle(Point p, int rr) // center and radius
: r{rr}
{
add(Point{p.x - r, p.y - r}); // store top left corner
}

void draw_lines() const;

Point center() const // returns the actual center when you have a point stored in  (the top left corner)
{
return {point(0).x + r, point(0).y + r};
// return Point(point(0).x + r, point(0).y + r); // same results with this format

int radius() const { return r; } // access the private data member r

void set_radius(int rr) 
{
set_point(0, Point{center().x - rr, center().y - rr}); 
r = rr;
}
private:
int r;
};

void Circle::draw_lines() const
{
if (fill_color().visibility())
{ // fill
fl_color(fill_color().as_int());
fl_pie(point(0).x, point(0).y, r + r - 1, r + r - 1, 0, 360);
fl_color(color().as_int()); // reset color
}

if (color().visibility())
{
fl_color(color().as_int());
fl_arc(point(0).x, point(0).y, r + r, r + r, 0, 360);
}

Reply all
Reply to author
Forward
0 new messages