Back to a Half-Century Later:
"From Sketchpad61 to Sketchpad14"
Part V: Creating Applications from Scratch in CDP,
(Remaking the "Parables of the Polygons" Demo)


Hesam Samimi, Alex Warth
Communications Design Group



Parable of the Polygons

Recently, CDG's Vi Hart and web programmer Niky Case relased a highly cited and praised web page called Parables of the Polygons. Not only beautifully designed, the page explains a mathematics concept in an explorable way and leads to conveying a positive social lesson for tolerance of all. We took the task of remaking the web page in Sketchpad14 and the CDP model to understand the advantages and limitations of our approach. This chapter summarizes what it took to make the demo.

Figure above is a snapshot of the demo done in Sketchpad14. Though this demo does not fully implement the original page, most interesting and interactive behaviors are present. Surprisingly, only three new constraint types had to be defined, two of which can be seen in the constraint list view in the figure above. The other five type of constraints were already part of our predefined set of constraints or present in previous demos.


What's it take to program in CDP/Sketchpad14?

You could find the source code for this demo at "../2d/demo/polygons/example-polygons.js" or scroll down to the bottom of this page to play it. Let's examine it. It should be possible to develop it all within the tool itself, but at the moment the UI just isn't usable yet.

All CDP programs are conventionally organized in the same way. Data classes are defined first, then constraint classes. Afterwards data objects are created and then constraints are instantiated to operate on them. Finally, should this be an interactive program (all Sketchpad14 programs are because objects are draggable), events are registered, whose job is to modify the data and constraint stores.


Data Classes

Constraint Classes

Reactive Parts

Now that we have all the constraint types we need, we can worry about the interactive/reactive part of the demo.


Final Step:
Laying out data and constraints

By now all kinds of data, and continuous and reactive behaviors have been defined. All that's left to do is layout the page and add constraints.

To get the temporal constraints going, don't forget to add a TimerConstraint so that the system's clock gets ticking:


	addConstraint(new TimerConstraint(new Timer(1))) // steps pseudo-time by 1 unit at each frame

Now we'll instantiate as many Shapes, Boards, TextBoxes, etc. as we need, and add constraints as appropriate. That is, all shapes on a board get a ShapeMoodConstraint, and so on.

That's all folks. We omitted some parts of the demo (e.g., In the tool see the slider demo, which was implemented separately and reused here), but you should have gotten a good overview of things by now!


Read Part VI: Comparison of CDP and Imperative Programming
Back to Table of Contents


Click to view this demo!