Add parametricDrawingOf (generalizes LSU's randomDrawingOf and guiDrawingOf)
- Lingua principale
- Haskell
- Stelle
- 1.3k
- Fork
- 201
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
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!
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia esaminando le implementazioni esistenti di randomDrawingOf e guiDrawingOf, quindi analizza Extras.Widget e le definizioni API correlate. La issue sta ancora esplorando nomi, tipi di parametro, trasformazioni e controlli con stato, quindi i maintainer devono concordare il comportamento desiderato e i criteri di completamento prima che l'implementazione possa iniziare.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- haskell
- Ambito
- api, backend
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 20/100