ScratchData LogoScratchData
Back to gtoal's profile

Ellipse Drawing Library (outlined or filled)

GTgtoal•Created February 28, 2015
Ellipse Drawing Library (outlined or filled)
36
24
1252 views
View on Scratch

Instructions

This contains a procedure to draw an ellipse specified by the lengths of the major and minor axes, and a rotation in degrees around a center point. It can be drawn as an outline, or filled. The implementation is very efficient and the filling is done using only horizontal lines, which makes the algorithm ideal for raster converting directly into a frame store. See an animated demo of the rotation-via-shearing algorithm at http://g6auc.me.uk/ellipses/index.html

Description

The code uses Bresenham's ellipse-drawing algorithm as its base. However Bresenham's only draws axis-aligned ellipses. By applying a shear to a Bresenham ellipse, we create an ellipse aligned to any arbitrary angle. The mapping between a rotational specification and the shearing implementation was worked out by @nXIII in the discussion at http://scratch.mit.edu/discuss/topic/94194/ The underlying Bresenham implementation comes from Ruslan Cray: https://sites.google.com/site/ruslancray/lab/projects/bresenhamscircleellipsedrawingalgorithm/bresenham-s-circle-ellipse-drawing-algorithm TO DO: the shear is applied by using floating point math. It should be reimplemented using Bresenham's line drawing algorithm to make the drawing code 100% integer. Only the mapping of the parameters should require floating point arithmetic. (However the FP arithmetic for the shear calculation isn't a significant overhead in the Scratch system) Other things I need to do - reduce all rotations into the 0-90 degree range. Also it may be that rotations between 45 and 90 might look better if they were done by shearing down the other axis. Finally: take care in the fill code so that transparency will be supported. There's no underlying reason why it shouldn't.

Project Details

Project ID50039326
CreatedFebruary 28, 2015
Last ModifiedJuly 31, 2018
SharedFebruary 28, 2015
Visibilityvisible
CommentsAllowed