1. Ellipse
- Posted by lithex <lithex at INTERGATE.BC.CA> Sep 18, 1998
- 439 views
- Last edited Sep 19, 1998
Hi Here's an ellipse drawer that works at any angle and uses only algebra and Euphoria. Start of Euphoria code -- This is a program that draws an ellipse -- Written by Martin Hunt -- This is a brute force approach, it examines each point on the screen and -- determines whether it is on the ellipse or not. -- If it is on the ellipse, it makes a white dot, otherwise it doesn't include image.e include get.e include graphics.e atom gr, sw, sh sequence p1, p2, p3, p4, vidconf gr=graphics_mode(18) vidconf=video_config() sw=vidconf[5] sh=vidconf[6] p1={120,120} p2={210,200} p3={220,20} p4={150, 175} function span_of(sequence p1, sequence p2) return (sqrt(power((p2[1]-p1[1]),2)+(power((p2[2]-p1[2]),2)))) end function procedure Plot_if_on_ellipse(sequence foci, sequence point, atom k) if floor(span_of(foci[1],point) + span_of(foci[2], point))=k then pixel (WHITE, point) end if end procedure for i=1 to sw by 1 do for j=1 to sh by 1 do Plot_if_on_ellipse({p1,p2},{i,j},220) Plot_if_on_ellipse({p2,p3},{i,j},230) Plot_if_on_ellipse({p3,p4},{i,j},240) Plot_if_on_ellipse({p4,p1},{i,j},250) end for end for End of Euphoria code This is a brute force approach, and is a little slow. The method just looks at every point on the screen, and sets it to white if it is on the ellipse. I'm trying to find a better method. Bye Martin