Draw Polygon

May 28, 2014 at 7:17pm
Solved
Last edited on May 30, 2014 at 8:50am
May 28, 2014 at 9:15pm
drawpoly() takes a number n of points, and an array of 2n integers that specify the coordinates. E.g., 3 points are specified as [x1, y1, x2, y2, x3, y3]. So if you want up to 10 points, then your points array should be:
int points[2*10];
Your current code inputs just one number after each prompt. You need to input 2 and you need a little math to get the right positions for them. Try:
1
2
cout<<"X"<<i<<" Y"<<i;
cin >> points[2*i] >> points[2*i+1];
May 28, 2014 at 9:46pm
Thank u very much dear I understand now. One more thing, how can I fix output to appear within limits of output screen.
Last edited on May 28, 2014 at 10:02pm
May 29, 2014 at 11:57am
I'm not that familiary with drawpoly(), but I suspect that if you draw to a coordinate outside the bounds of the screen (or window) then it will clip the result. In other words it will "do the right thing" by drawing the pixels that are on the screen and not drawing what is off screen.

If you mean that you want to see the shape, even if the coordinates are off screen then you'll need to multiply all the coordinate numbers by a constant scale factor. The way to think about this is that you have "real" coordinates that represent your original numbers and "screen" or "window" coordinates that are pixels on the screen. Hope this makes sense.
Topic archived. No new replies allowed.