2

Can anyone tell me how to draw an Ellipse using the CodeWorld package of Haskell? I want it to be like the rectangle function where I give two arguments for length and width. I have tried using solidClosedCurve-am I heading in the right direction?

Amy
  • 31
  • 3

1 Answers1

1

Using a closed curve, you can set the 4 vertices like so:

ellipse'(a, b) = closedCurve([(a,0),(0,b),(-a,0),(0,-b)])

Another way to do it is to say that an ellipse is a circle rescaled in one direction.

ellipse(a, b) = scaled(circle(1), a, b)

https://code.world/#Ps8tKc4KH4v8Z4iq91NZsew

Chris Smith
  • 2,615
  • 19
  • 18
Li-yao Xia
  • 31,896
  • 2
  • 33
  • 56
  • 2
    Just FYI, the first example using `closedCurve` will be approximately an ellipse, but not exact. To get a true ellipse, scaling a circle is the right way. – Chris Smith Jul 07 '18 at 20:27