google / google/codeworld

Add parametricDrawingOf (generalizes LSU's randomDrawingOf and guiDrawingOf)

Offen
#1,243 22 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
discussion
Vorherrschende Sprache
Haskell
Sterne
1.3k
Forks
201
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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!

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne mit der Durchsicht der bestehenden Implementierungen von randomDrawingOf und guiDrawingOf und untersuche anschließend Extras.Widget und die zugehörigen API-Definitionen. Im Issue werden weiterhin Namen, Parametertypen, Transformationen und zustandsbehaftete Steuerelemente erkundet, daher müssen sich die Maintainer auf das gewünschte Verhalten und die Abschlusskriterien einigen, bevor mit der Implementierung begonnen werden kann.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
haskell
Bereich
api, backend
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
20/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.