Add parametricDrawingOf (generalizes LSU's randomDrawingOf and guiDrawingOf)
- Dominant language
- Haskell
- Stars
- 1.3k
- Forks
- 201
- PR merge metrics
- No merged PRs in 30d
Description
FYI @alphalambda
I think I'm hopeful that `randomDrawingOf` and `guiDrawingOf` belong in the core CodeWorld API. They make for a nice transition between animations and more general parameterized drawings.
I'd like to combine them into a single entry point, though. Maybe `parametricDrawingOf`? That's a horrible name, but the idea is not to use "widget" because some of the common and earliest uses might not affect the UI at all. I'll keep thinking, though!
The API would look something like:
-- Main entry point:
parametricDrawingOf :: ([Number] -> Picture, [Parameter]) -> Picture
-- Specific parameters:
slider :: (Text, Range, Point) -> Parameter
randomNumber :: Range -> Parameter -- (invisible)
randomButton :: (Text, Range) -> Parameter
prompt :: Text -> Parameter -- (invisible after program start)
currentHour, currentMinute, currentSecond :: Parameter -- (invisible)
currentTime :: Parameter -- (invisible, time since program start)
timer :: Point -> Parameter -- (visible, with start and stop buttons)
-- Utility type, mainly to prevent confusion between position and range
data Range where Between :: (Number, Number) -> Range
-- API for creating parameters: basically activities with local state and an output number.
parameterOf
:: ([Number] -> state, -- Input is stream of random numbers
(state, Event) -> state,
state -> Picture,
state -> Number)
-> Parameter
Example:
program = parametricDrawingOf(picture, params)
params = [
slider("Size", Between(1, 10), (5, 5)),
randomNumber(Between(-10, 10)),
randomButton("Change color", Between(0, 1)),
prompt("How many circles?"),
currentSecond
]
picture([size, x, color, num, sec]) = ...
@alphalambda also has a scheme where transformations can be applied to a widget (such as withConversion, etc.) rather than reimplemented each time. I need to investigate this. It seems to require a more complex UI for defining widgets (and indeed, in Extras.Widget, there are no user-defined widgets at all), and yet not be sufficient for anything more than what can be accomplished by passing a range in as a parameter. In particular, transformations might be interesting if they could be changed over the life of the program, but they cannot in the current implementation. My guess is that students would rather just give the desired range as an argument.
@alphalambda also has a scheme for stateful controls, which looks way trickier, but maybe useful. Not sure how to think about that yet!
Contributor guide
Assessment
This issue has not been assessed yet.