3

How can I draw a major pieslice in C, using the function pieslice()?

pieslice(X-centre,Y-centre,StrtAngle,EndAngle,Radius).

I am trying to draw a major sector or pieslice in C, using the pieslice function; I want the start angle to be 135 degrees and end angle to be 235 degrees, but at the same time it should be the major sector, not the minor sector.

I tried all the four combinations

pieslice(100,100,135,-135,20)
pieslice(200,200,225,135,30)
pieslice(300,300,225,360+135,30)
pieslice(400,400,135,225,20)

pieslice(50,50,0,135,30);
pieslice(50,50,225,0,30);

But all of them draw the corresponding minor sector not the major sector. Can someone please advise me how to do that?

Here is a screenshot of the output:


Thanks for your effort and time.

Now, I could not make the pieslice to work my way. However with the following tweak, I am able to get around the problem and get the desired output. I wrote a user defined function slice(int x-centre, int y-centre,int sangle, int eangle, int radius) similar to pieslice. I hope it is useful for those who get stuck in a similar kind of situation:

void slice(int x, int y, int sangle, int eangle, int rad)
{
 int i,j,color;
 if(sangle>eangle){
  color=getcolor();
  setcolor(getcolor()) ;
  setfillstyle(SOLID_FILL,color);
  circle(x,y,rad);
  floodfill(x,y,color);
  setcolor(getbkcolor());
  setfillstyle(SOLID_FILL,getbkcolor());
  pieslice(x,y,eangle,sangle,rad);
  setcolor(color);
 }
}
Glorfindel
  • 21,988
  • 13
  • 81
  • 109
TruckDriver
  • 1,383
  • 13
  • 28
  • @Timothy: What graphics library are you using? Borland? What error messages do you see? Can you show us how you are actually calling the function in your code? (Also: the second call to `pieslice` has a typo.) – Dave Jarvis Apr 16 '11 at 09:44
  • @Dave i am using turboc graphics library on windows platform – TruckDriver Apr 16 '11 at 09:45
  • @dave yeah tht was a typing mistake ; – TruckDriver Apr 16 '11 at 09:46
  • @thrustmaster : i am using turboc graphics library on windows platform. – TruckDriver Apr 16 '11 at 09:47
  • @Timothy: It has been over a decade, but I think if you hit CTRL-F1 with the cursor on the `pieslice` function, it will display a help screen showing how to call it. – Dave Jarvis Apr 16 '11 at 09:47
  • this is the sample code, however there are no errors, only thing is that i m getting minor slice instead of major slice #include #include #include #include void main() { int maxx,minx,bl_div,len; int maxval,minval,temp; int n,i,j,j1,k; int gd=DETECT,gm; char x1[10],y1[10]; clrscr(); initgraph(&gd,&gm,"d:\\tc\\"); setfillstyle(SOLID_FILL,YELLOW); pieslice(100,100,135,-135,20); pieslice(200,200,225,135,30); pieslice(300,300,225,360+135,30); pieslice(400,400,60,-240,20); getche(); } – TruckDriver Apr 16 '11 at 09:50
  • @Timothy: It is customary to update the question with new information. Code added to comments is hard to read. See Robin's answer for a solution. – Dave Jarvis Apr 16 '11 at 09:53
  • @dave : even robin's solution is not working :( – TruckDriver Apr 16 '11 at 10:15

2 Answers2

2

Draw two pie slices with the same centre and radius, one from 0 to 135 degrees, and one from 225 to 0 degrees. It seems that the function is forcing the pie slices to be always less than 180 degrees, so this should work around that.

See also: http://electrosofts.com/cgraphics/

Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
Robin Green
  • 32,079
  • 16
  • 104
  • 187
  • @Robin: Saved me from installing Turbo C. ;-) – Dave Jarvis Apr 16 '11 at 09:53
  • @ Robin and Dave : thanks a lot, i have tried that too, but even that does not solve the problem , i am getting a sector, but its not like that which starts at 135 and ends at 225,, its something different,, please look into it – TruckDriver Apr 16 '11 at 09:57
  • 1
    @Timothy: Provide some screen captures. Use http://imgur.com/. Post the links, don't try to inline the images; someone else will inline them for you. Edit to update your question. – Dave Jarvis Apr 16 '11 at 10:46
  • @dave :i have uploaded the screenshot of the output, the one slice that you see in the top most left corner is the one suggested by robin, http://postimage.org/image/1wytkbdic/ – TruckDriver Apr 16 '11 at 11:14
  • Are you sure you didn't enter 90 degrees by mistake instead of 135 degrees for the top-left one? – Robin Green Apr 16 '11 at 11:17
  • @robin no robin i am sure i did this pieslice(50,50,0,135,30); pieslice(50,50,225,0,30); – TruckDriver Apr 16 '11 at 11:25
0

here is my game loop using pieslice . pacman moves to and fro.

for (int dx = 10, dy = 0, dt = 100; c != 'q';) {
    if ((x + rx + dx) > getmaxx() || (x + rx + dx) < 0) {
    dx = -dx;
    rx = -rx;
    }
    if ((y + ry + dy) > getmaxy() || (y + ry + dy) < 0) {
    dy = -dy;
    ry = -ry;
    }
    delay(dt);
    cleardevice();
    //gotoxy(1,1);
    //cout << x+rx << " " << y+ry << " " << m;
    pieslice(x, y, (sa + m), (ea - m), RADIUS);
    //floodfill(x,y,getcolor());

    if (m + dm < 0 || m + dm > ea)
     dm = -dm;

    m += dm;

    x += dx;
    y += dy;
    if (kbhit())
     c = getch();
}
Robert
  • 5,278
  • 43
  • 65
  • 115