circle.e - Reply
- Posted by "BABOR, JIRI" <J.Babor at GNS.CRI.NZ> Aug 05, 1997
- 769 views
Last night, when I saw Lucius' creation, I thought there must be a better way. The routine below is based on a bastardized Bresenham's algorithm, but only partially unrolled for speed. There is not much point in adding inferior routines to our collection, but this one, at least, has a tile option, missing from the Euphoria version. It is adapted from my virtual screen set of routines, which includes virtual pixels, lines and tiled rectangles, ellipses and polygons, as well as the basic virtual screen manipulation routines. No assembly, just high level Euphoria routines, but they compare surprisingly well with build-in routines in mode 19. I shall release them as soon as I find some time to write a decent demo and some docs. In the meantime, if anybody is desperate enough, just mail me. Jiri. -- ellipse.ex ------------------------------------------------------------------ -- Jiri Babor -- j.babor at gns.cri.nz include graphics.e include get.e -- wait_key() object junk sequence tile procedure v_ellipse(object c,integer f,atom xc,atom yc,atom m,atom n) -- c is color or 2d tile sequence, f is fill flag -- xc,yc are centre coordinates, and m,n are major/minor radii sequence s integer x,y,dx,dy,r,rx,ry,xx,lx,ly,mx,my xc=floor(xc) yc=floor(yc) m=floor(m) n=floor(n) dx=2*m*m dy=2*n*n r=m*n*n rx=2*r ry=0 x=m y=0 if not f then -- hollow ellipse pixel(c,{xc-m,yc}) pixel(c,{xc+m,yc}) while x>0 do if r>0 then y=y+1 ry=ry+dx r=r-ry end if if r<=0 then x=x-1 rx=rx-dy r=r+rx end if pixel(c,{xc-x,yc-y}) pixel(c,{xc+x,yc-y}) pixel(c,{xc-x,yc+y}) pixel(c,{xc+x,yc+y}) end while elsif atom(c) then -- filled ellipse: single color xx=m+m+1 s=repeat(c,m+m+1) pixel(s,{xc-m,yc}) while x>0 do if r>0 then y=y+1 ry=ry+dx r=r-ry end if if r<=0 then x=x-1 xx=xx-2 rx=rx-dy r=r+rx end if pixel(s[1..xx],{xc-x,yc-y}) pixel(s[1..xx],{xc-x,yc+y}) end while else -- tiled ellipse ly=length(c) lx=length(c[1]) xx=m+m y=0 s=c for i=1 to ly do while length(s[i])<xx+lx do s[i]=s[i]&c[i] end while end for mx=1+remainder(xc-x,lx) my=1+remainder(yc-y,ly) pixel(s[my][mx..mx+xx],{xc-x,yc}) while x>0 do if r>0 then y=y+1 ry=ry+dx r=r-ry end if if r<=0 then x=x-1 xx=xx-2 rx=rx-dy r=r+rx end if mx=1+remainder(xc-x,lx) my=1+remainder(yc-y,ly) pixel(s[my][mx..mx+xx],{xc-x,yc-y}) my=1+remainder(yc+y,ly) pixel(s[my][mx..mx+xx],{xc-x,yc+y}) end while end if end procedure -- examples -------------------------------------------------------------------- junk=graphics_mode(19) {9,14,14,14,9,9},{9,14,14,14,9,9}} v_ellipse(tile,1,50,100,30,50) v_ellipse(tile,1,200,100,100,50) junk=wait_key() junk=graphics_mode(-1)