Proposal: Rework polygons and lines

32 views
Skip to first unread message

Chris Smith

unread,
Jul 29, 2014, 11:17:38 AM7/29/14
to codeworl...@googlegroups.com
Hey everyone!

I mentioned a few weeks ago that we're working on putting together a
more complete educational curriculum using CodeWorld. In that
process, I've come to think we might need to make some changes that
will, again, break a lot of existing code. Sorry!

Here are the changes I have in mind. Any comments are welcome.

Currently, we have three functions:

line :: [Point] -> Picture
thickLine :: ([Point], Number) -> Picture
polygon :: [Point] -> Picture

Here, "line" is a connected sequence of line segments. "thickLine" is
the same but with thickness, and "polygon" is a filled polygon.

Here's what I propose instead:

-- A line segment.
line :: (Point, Point) -> Picture

-- A line segment with thickness.
thickLine :: (Point, Point, Number) -> Picture

-- An open polygon.
polygon :: [Point] -> Picture

-- An open polygon with a thick border.
thickPolygon :: ([Point], Number) -> Picture

-- A filled polygon.
solidPolygon :: [Point] -> Picture

If there's a strong need, I could also add:

-- Connected sequence of lines.
path :: [Point] -> Picture

-- Connected sequence of lines, with thickness.
thickPath :: ([Point], Number) -> Picture

But honestly, I tend to think these are special-purpose enough that
students who want them could write them using pattern matching on
lists. For example:

path(p:q:more) = line(p, q) & path(q:more)
path(other) = blank

and similarly for thickPath. Or with list comprehensions:

path(points) = pictures[ line(p,q) | p <- points | q <- rest(points) ]

Thoughts?

Chris Smith

unread,
Jul 29, 2014, 11:28:34 AM7/29/14
to codeworl...@googlegroups.com
A less extreme version of this would be to leave line and thickLine as
is, but change polygon to draw an open polygon, and add thickPolygon
and solidPolygon.

Bartosz Wójcik

unread,
Jul 31, 2014, 3:52:32 PM7/31/14
to codeworl...@googlegroups.com
I've just started looking at this project/tool with intention of introducing programming to my 11 years old son. I've found awkward that line is of type line :: [Point] -> Picture. So for me the proposal is natural.
BTW: first impression is very positive - it's cool.
Best,
Bartosz

Chris Smith

unread,
Aug 14, 2014, 1:09:18 AM8/14/14
to codeworl...@googlegroups.com
Last call for comments on this.

If I don't hear any strong objections soon, then the changes I'll be making are:

1. Rename the function currently called polygon to solidPolygon.
2. Define polygon to draw an open polygon. In other words, define
polygon(points) = line(points ++ take(points, 1))
3. Add an analogous thickPolygon(points, k) = thickLine(points ++
take(points, 1), k)

This will be a breaking change, because polygon has been renamed. At
this time, I don't plan to make the proposed changes to line or
thickLine; they will still take lists as parameters. Those changes
are still on the table, but they don't seem like quite the slam-dunk
improvement that we get from making polygon follow the same pattern as
other shapes.
> --
> You received this message because you are subscribed to the Google Groups
> "codeworld-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to codeworld-disc...@googlegroups.com.
> To post to this group, send email to codeworl...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/codeworld-discuss/d052211b-600e-4edd-b4b8-39231cd30ed0%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Chris Smith

unread,
Aug 14, 2014, 1:12:44 AM8/14/14
to codeworl...@googlegroups.com
(As an aside, I've already made a change so that when the first and
last parameters to line or thickLine are the same, I close the shape.
This was necessary to fix thickRectangle, among other things. I
considered that a bug. Once this change is finished, an argument
could be made that I should revert the change to line and thickLine,
and only close paths with polygon and thickPolygon.)

Chris Smith

unread,
Aug 14, 2014, 5:31:57 PM8/14/14
to codeworl...@googlegroups.com
This change is live. You'll need to rename old uses of polygon to
solidPolygon. I also reverted the change to thickLine, so if you try
to draw a closed shape using thickLine, the ends won't stitch
together. Draw your closed shapes using thickPolygon instead.
Reply all
Reply to author
Forward
0 new messages