google / google/codeworld

parametricCurve function

Open
#1,361 1 comment 0 reactions 0 assignees View on GitHub
discussion
Dominant language
Haskell
Stars
1.3k
Forks
201
PR merge metrics
No merged PRs in 30d

Description

In a conversation with someone, I recently realized that a lot of real graphics work is done with parametric curves. There's no way to draw these in CodeWorld.

My proposal:

In codeworld-api:

parametricCurve :: (Double -> Point) -> Picture
thickParametricCurve :: Double {- thickness -} -> (Double -> Point) -> Picture

In codeworld-base:

parametricCurve :: (Number -> Point) -> Picture
thickParametricCurve :: (Number -> Point, Number {- thickness -}) -> Picture

One could add `parametricClosedCurve`, `thickParametricClosedCurve`, and `solidParametricClosedCurve` in a similar vein.

In this API, I'm assuming that the parameter would vary between 0 and 1. You could imagine passing in a range instead, but I think that makes the API too complex, and I'd rather give students an opportunity to make use of scaling and fractional values on their own.

The actual drawing would be done by sampling. One could even be clever and choose more anchor points when the curve is more complex, or when the picture is scaled up. It's not clear exactly how clever one should be here.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.