google / codeworld

Educational computer programming environment using Haskell
http://code.world
Apache License 2.0
1.24k stars 197 forks source link

Adjustable runtime Parameters #491

Open tbelaire opened 7 years ago

tbelaire commented 7 years ago

I was working on trying to get a nice looking fibonacci tree, and I had two constants

branchAngle = 30
splayAngle = 30

which I keep tweaking, but it's hard to get them right. It'd be pretty neat if I could mark them as "Parameters" or something, and have sliders for their values to adjust and see what happens in realtime, instead of recompiling all the time.

But I'm not sure how it'd look for the code. I mean, it could just be a reader monad, (Parameters -> Picture) kinda thing, but that seems like a massive change to the fundementals to have to write everything in monadic style now.

cdsmith commented 7 years ago

I've built things like this in the past: https://code.world/#PDEgf1CE9Ev21OTuYILk3qA

cdsmith commented 6 years ago

I stuck this together: https://code.world/#Pkg25ZSBxq11j6uCbHNp0jA

We could easily generate it to take a list of parameter ranges. That is:

parameterizedDrawingOf :: ([Number] -> Picture, [(Number, Number)]) -> Program

or in the haskell dialect:

parameterizedDrawingOf :: [(Double, Double)] -> ([Double] -> Picture) -> IO ()

One could also advocate for a label in the bounds tuple, so it's clear which parameter is which slider.

The issue here is that I'm hesitant to add an explosion of CodeWorld entry points. In fact, I'm working on the opposite: eliminating simulationOf as a separate thing. That still leaves us with a lot (drawingOf, animationOf, activityOf, groupActivityOf, and debugActivityOf) @alphalambda also has a few extra entry points he's put together, for instance, drawings and animations that get random numbers as input, or for slideshows, etc.

What I'm afraid of losing is a sense of the universality of the model. I don't want students to end up feeling like they can only do something in CodeWorld if we anticipated that type of program and gave them an entry point tailored to their purpose.

Still, this is worth leaving open. It's also worth mentioning that I already offered to create an Extras package that runs on the main server, and this would fit there quite well.