1. circle.e

I have created a circle routine that uses
center, radius, and ratio.

It is here for the pickings.

--circle is similiar to ellipse.
--ellipse's use is stated below.
--circle's use follow ellipse's use.
--ellipse uses box like corners.
--circle uses a center, a radius, and a ratio.
-----------------------------------<ellipse>------------------------------------

--Syntax:      include graphics.e
--      ellipse(i1, i2, s1, s2)

--Description: Draw an ellipse with color i1 on a pixel-graphics screen.
The
--             ellipse will neatly fit inside the rectangle defined by
diagonal
--             points s1 {x1, y1} and s2 {x2, y2}. If the rectangle is a
square
--             then the ellipse will be a circle. Fill the ellipse when
i2 is 1.
--             Don't fill when i2 is 0.
--
--Example:     ellipse(MAGENTA, 0, {10, 10}, {20, 20})

--      This would make a magenta colored circle just fitting inside the
--      square: {10, 10}, {10, 20}, {20, 20}, {20, 10}.

--Example Program: demo\sb.ex

-----------------------------------<circle>-------------------------------------

--Syntax:      include circle.e
--      circle(i, s1, a, s2)

--Description: Draw an ellipse or circle at center point of s1 {x, y}
with
--             color i and radius of a using a ratio of x to y {x, y}.

--Example:     circle(MAGENTA, {160, 100}, 50, {1, 1})

--      This would make a magenta colored circle with at the center point
--      of {160, 100} with a radius of 50 with ratio of 1 to 1 {1, 1}.
-- no filling created (supported) yet.
-----------------------------------<circle>-------------------------------------
procedure circle(integer c, sequence p, atom r, sequence ratio)
  atom r1, r2
  integer t

  r1 = ratio[1]
  r2 = ratio[2]
  if r1 != r2 then
    if r1 > r2 then
      r1 = r2 / r1
      r2 = 1
    else
      r2 = r1 / r2
      r1 = 1
    end if
  end if
  ratio = {r1, r2}

  for a = -r to r do
    t = floor(sqrt(r * r - a * a) + .5)
    pixel(c, {a, t} * ratio + p)
    pixel(c, {t, a} * ratio + p)
    pixel(c, {a, -t} * ratio + p)
    pixel(c, {-t, a} * ratio + p)
  end for
end procedure

--Lucius Lamar Hilley III
--  E-mail at luciuslhilleyiii at juno.com
--  JUNO JUNO JUNO.  I use JUNO and
--  I support transferring of files less than 60K.
--  I can Decode both UU and Base64 format.

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu