0 Members and 1 Guest are viewing this topic.
program uses pure2d,keysetfunction DRAW_SECTOR(cx, cy, inner_rad, outer_rad, start_deg, sector_deg, fill, r, g, b): boolean var increment: real steps: integer degrees: real x, y, i: integer x1, y1, x2, y2: integer colour: integerbegin colour = ToRGBA(r, g, b) //DRAW OUTER CURVE increment = toreal(sector_deg / (outer_rad * Pi *2)) steps = sector_deg / increment degrees = start_deg for i = 0 to steps+1 x = cx - outer_rad * Cos(degrees) y = cy - outer_rad * Sin(degrees) Pixel(x, y, colour) degrees = degrees + increment next //DRAW INNER CURVE increment = toreal(sector_deg /(inner_rad * Pi * 2)) steps = sector_deg / increment degrees = start_deg for i = 0 to steps+1 x = cx - inner_rad * Cos(degrees) y = cy - inner_rad * Sin(degrees) Pixel(x, y, colour) degrees = degrees + increment next //DRAW LINES x1 = (cx - inner_rad * Cos(start_deg)) y1 = (cy - inner_rad * sin(start_deg)) x2 = (cx - outer_rad * Cos(start_deg)) y2 = (cy - outer_rad * sin(start_deg)) Line (x1, y1, x2, y2, colour) x1 = (cx - inner_rad * Cos(start_deg + sector_deg)) y1 = (cy - inner_rad * sin(start_deg + sector_deg)) x2 = (cx - outer_rad * Cos(start_deg + sector_deg)) y2 = (cy - outer_rad * sin(start_deg + sector_deg)) Line (x1, y1, x2, y2, colour) if fill = 1 x = (cx - ((inner_rad + outer_rad) / 2 )* Cos((start_deg + sector_deg) / 2)) y = (cy - ((inner_rad + outer_rad) / 2 )* sin((start_deg + sector_deg) / 2)) FloodFill(x, y, colour, colour, TRUE) endif end//EXAMPLE PROGRAM var i:integer a, b: integerbegin openscreen a=2 b=1 while not KeyDown(vk_escape) cls DRAW_SECTOR(200, 200, 60, 100, i, 270, 1, 150, 0, 0) DRAW_SECTOR(200, 200, 20, 50, -i, 270, 1, 100, 0, 0) DRAW_SECTOR(500, 200, 1+a, 60+a, i+240, 60, 0, 255, 255, 255) DRAW_SECTOR(500, 200, 1+a, 60+a, i+120, 60, 0, 255, 255, 255) DRAW_SECTOR(500, 200, 1+a, 60+a, i, 60, 0, 255, 255, 255) a=a+b if a > 100 then b = -b if a < 2 then b =-b i=i+1 if i = 360 then i = 0 flip wendend
program uses pure2d,keysetfunction DRAW_SECTOR(cx, cy, inner_rad, outer_rad, start_deg, sector_deg, fill, r, g, b): boolean var increment: real steps: integer degrees: real x, y, i: integer x1, y1, x2, y2: integer colour: integer lx1,ly1,lx2,ly2:realbegin colour = ToRGBA(r, g, b) //DRAW OUTER CURVE increment = toreal(sector_deg / (outer_rad * Pi *2)) steps = sector_deg / increment degrees = start_deg for i = 0 to steps+1 x = cx - outer_rad * Cos(degrees) y = cy - outer_rad * Sin(degrees) Pixel(x, y, colour) degrees = degrees + increment next // using floating point, there will be a level of rounding error, so to make sure we draw to the same place as last // Pixel (ie, no gaps) we record the final x,y value plotted to use when drawing last Line between the two parts - GAK lx1 = x ly1 = y //DRAW INNER CURVE increment = toreal(sector_deg /(inner_rad * Pi * 2)) steps = sector_deg / increment degrees = start_deg for i = 0 to steps+1 x = cx - inner_rad * Cos(degrees) y = cy - inner_rad * Sin(degrees) Pixel(x, y, colour) degrees = degrees + increment next // using floating point, there will be a level of rounding error, so to make sure we draw to the same place as last // Pixel (ie, no gaps) we record the final x,y value plotted to use when drawing last Line between the two parts - GAK lx2 = x ly2 = y //DRAW LINES x1 = (cx - inner_rad * Cos(start_deg)) y1 = (cy - inner_rad * sin(start_deg)) x2 = (cx - outer_rad * Cos(start_deg)) y2 = (cy - outer_rad * sin(start_deg)) Line (x1, y1, x2, y2, colour) (* don't need these anymore - GAK x1 = (cx - inner_rad * Cos(start_deg + sector_deg)) y1 = (cy - inner_rad * sin(start_deg + sector_deg)) x2 = (cx - outer_rad * Cos(start_deg + sector_deg)) y2 = (cy - outer_rad * sin(start_deg + sector_deg))*)// last Line is drawn between the final pixels plotted on inner and outer arc - GAK Line (lx1, ly1, lx2, ly2, colour) if fill = 1(* Original calculation was the problem, averaging start, and size, not start and end of sector - GAK x = (cx - ((inner_rad + outer_rad) / 2 )* Cos((start_deg + sector_deg) / 2)) y = (cy - ((inner_rad + outer_rad) / 2 )* sin((start_deg + sector_deg) / 2)) *)// instead, add half the sector size, and that brings it into the middle - GAK x = (cx - ((inner_rad + outer_rad) / 2 )* Cos(start_deg + (sector_deg / 2))) y = (cy - ((inner_rad + outer_rad) / 2 )* sin(start_deg + (sector_deg / 2))) FloodFill(x, y, colour, colour, TRUE) endif end//EXAMPLE PROGRAM var i:integer a, b: integerbegin openscreen a=2 b=1 while not KeyDown(vk_escape) cls DRAW_SECTOR(200, 200, 60, 100, i, 270, 1, 150, 0, 0) DRAW_SECTOR(200, 200, 20, 50, -i, 270, 1, 100, 0, 0) DRAW_SECTOR(500, 200, 1+a, 60+a, i+240, 60, 0, 255, 255, 255) DRAW_SECTOR(500, 200, 1+a, 60+a, i+120, 60, 0, 255, 255, 255) DRAW_SECTOR(500, 200, 1+a, 60+a, i, 60, 0, 255, 255, 255) a=a+b if a > 100 then b = -b if a < 2 then b =-b i=i+1 if i = 360 then i = 0 flip wendend