# Pen Studio field guide

A self-contained HTML/CSS/JavaScript website documenting this Squeak project.

## Inside the four Pen Studio windows

`classic-studio.html`, `live-pen-lab.html`, `3d-studio.html`, and `morphic-playground.html` explain the original project code. They include 13 complete Workspace recipes, 43 extracted implementation methods, 13 native window PNGs, four native GIFs, experiments, and the ten-file source suite ZIP. The 3D page covers mesh construction, perspective, face culling, painter ordering, lighting, candidate scene compilation, wireframe controls, and orbital updates. It identifies the renderer as this project's software polygon renderer and explains its near-plane and depth-ordering limits.

Regenerate from the project root in this order:

```powershell
python website/tools/build_pen_studio_tutorials.py
& 'C:\Users\Humayun\Documents\Utils\Squeak6.0\SqueakConsole.exe' -headless .\PenStudioMorphic.image .\website\tools\run-pen-studio-lessons.st
python website/tools/export_pen_studio_tutorials.py
python website/tools/render_pen_studio_tutorials.py
```

The native run passed 13 recipes and 267 checks with zero failures, including every documented method's source comparison. It records 168 full-window frames, supplies native Pen/scene/item update messages, and closes the windows without saving the image. Export verifies source hashes, native completion, GIF dimensions, looping, durations, and visible decoded changes. Consecutive identical GIF frames may merge. Source frames remain local and are excluded from the hosted collection.

Studio classes are custom project code. Install the source ZIP in its documented order before running a recipe in a fresh Squeak 6.0 image. The code tabs distinguish runnable Workspace expressions from Browser method definitions. Recordings start as stills and play only when requested. Code, source downloads, and the shared light/dark preference also work offline.

## Pixel Studio: image editor and tutorial

Open `image-editor.html` or use the root `Open Image Editor Tutorial.cmd`. The self-contained native Squeak tool is in `assets/pixel-studio/PixelStudio.st`. File it in and evaluate `PSStudioMorph open.`, or use the root `Open Pixel Studio.cmd` / `LaunchPixelStudio.st` to load it into the project image. If an image is already running, use its File List and Workspace. No earlier tutorial class is required, and the launcher does not save automatically.

The four classes are `PSStudioMorph` (interface), `PSCanvasMorph` (mouse gestures and redraw), `PSDocument` (state, commands, history, effects, and PNG I/O), and `PSRasterLayer` (32-bit Form and layer attributes). Six tools draw brush strokes, erase, fill rectangles/ellipses, sample a composited color, and move a layer. The 2–48 pixel brush interpolates samples and clips at the document edges. Layer controls add/delete, rename, reorder, show/hide, and blend through opacity. Effects change only the selected layer, preserving alpha. Undo/redo snapshots copy pixel storage and metadata, retain at most 12 document edits, and discard redo after a new edit. Closing removes model subscriptions and stops label stepping.

The fixed document is 512 × 352 at 100% display scale. Import accepts a real PNG path (press Return in the field), converts to 32-bit pixels, centers smaller images, and scales larger images down to fit. Export writes a flattened white-backed PNG, replacing its accepted destination; it does not serialize the editable layer stack. Source and layers can be kept by saving the running Squeak image. This teaching editor does not include zoom, selections, arbitrary document resizing, PSD support, or a custom color picker.

The website includes seven tutorial chapters, exact runnable Workspace expressions, syntax colors/line numbers/copy controls, method definitions extracted from the loaded source, individual native screenshots of every example, full-source expansion, and three GIF workflows with before/after stills. Reduced-motion preference selects a still by default. The shared light/dark setting and all downloads work offline.

To refresh the native output and publish the tutorial data, run these commands in order from the project root:

```powershell
node website/tools/build_pixel_studio.js
& 'C:\Users\Humayun\Documents\Utils\Squeak6.0\SqueakConsole.exe' -headless .\PenStudioMorphic.image .\website\tools\run-pixel-studio.st
python website/tools/export_pixel_studio.py
```

The native run passed **237 checks with zero failures**: 46 behavioral checks, seven exact Workspace examples, seven example screenshot round trips, 168 captured-frame checks, and nine recording/result checks. Tests exercise real control actions and text acceptance, native mouse-event handlers including `HandMorph` mouse focus, interpolated/clipped brush pixels, transparent erasing, shape fills, eyedropper history neutrality, selection/reordering, alpha-preserving opacity and effects, snapshot independence and branches, PNG export/import pixel equivalence, oversized image import, invalid-file preservation, last-layer protection, and disposal. The runner exits without saving the image. The file example writes `PixelStudio-export.png` in the project root; verification fixtures stay under `assets/pixel-studio`.

Three GIFs contain 168 source frames at 120 ms per frame (8.33 sampled fps): painting and layers each 7.44 seconds, effects 5.28 seconds. Pillow encodes native 1080 × 720 PNG frames with a shared 224-color palette and verifies size, movement, infinite looping, and exact total durations. Identical hold frames may combine; no synthetic image frames are added. Source/catalog hashes bind the verification log to the exported data, and export refuses failures or missing output. The displayed execution date uses the client date, 2026-10-02.

## Complex UI demos

Open `complex-ui.html`, select **Complex UI** in any page’s navigation, or use the root `Open Complex UI Demos.cmd`. Three larger examples include a three-column task board with editable drafts, a searchable master-detail browser with validation and empty-result handling, and a preferences dashboard with a model-dependent live preview and Apply/Reset snapshots.

File in `assets/complex-ui/ComplexMorphicDemos.st`, then evaluate `CUIDemos taskBoard.`, `CUIDemos recordBrowser.`, or `CUIDemos settingsDashboard.` in a Workspace. No earlier demo classes are required. Press Return in text editors to accept a draft before using Save. Preferences Apply stores an in-memory snapshot. All example data is temporary unless you save the running image yourself.

Each example includes initial and result native PNGs, explanations, experiments, executed checks, a Workspace entry point, builder methods, and behavior methods extracted from the exact file-in. The full source expander includes four classes and every helper. Standard PluggableListMorph, PluggableTextMorph, PluggableButtonMorph, PluggableCheckBoxMorph, Slider, ProgressBarMorph, and UpdatingStringMorph objects provide the controls. A custom composite preview subscribes to model notifications.

Refresh from the project root in this order:

```powershell
node website/tools/build_complex_ui.js
& 'C:\Users\Humayun\Documents\Utils\Squeak6.0\SqueakConsole.exe' -headless .\PenStudioMorphic.image .\website\tools\run-complex-ui.st
node website/tools/export_complex_ui.js
```

The native run passed **3 demos, 37 checks, 0 failures**, including child bounds, widget actions and acceptance, filtered selection mapping, title validation, empty searches, renaming outside the current filter, observer updates, and complete snapshot restoration. Six 1020 × 690 PNGs round-trip through Squeak’s PNG reader. The runner exits without saving the image. Export rejects failures, missing demos, changed source/catalog hashes, and incorrect PNG dimensions. `complex-ui-data.js` records the client date, 2026-10-02, rather than deriving it from the execution host’s timezone. The page works offline and shares the site’s theme preference.

Open `index.html` in a browser. No build step, internet connection, package manager, or server is required. For an HTTP preview, run `python -m http.server 8000 --directory website` from the project folder and visit http://localhost:8000.

The site includes four demo tours, light/dark screenshot comparisons, nine implementation explanations, an image gallery, and a searchable browser for all ten original Smalltalk files. Copy buttons copy actual source; screenshots can be enlarged and downloaded. The website does not evaluate Smalltalk. Run the demos in Squeak using the instructions at the bottom of the page.

## General Smalltalk / Squeak tutorial

Open `tutorial.html`, or select **Tutorial** in the guide's navigation. Twelve lessons cover Workspace commands, messages, literals, temporaries, precedence, cascades, blocks, collections, classes, polymorphism, reflection, Morphic, Pen drawing, and image persistence. Each example identifies its execution context and expected result. Exercises have revealable solutions, five quiz questions explain their answers, and lesson completion is stored locally when browser storage is available.

`shared.js` provides shared syntax display, copy buttons, and the theme preference for both pages. The tutorial uses `tutorial-content.js`, `tutorial.js`, and `tutorial.css`. Downloadable Workspace examples, offline notes, and a complete file-in class are in `assets/tutorial`.

Regenerate the notes and example download after editing tutorial content:

```powershell
node website/tools/export_tutorial.js
```

The tutorial examples passed 32 behavioral checks in the installed Squeak 6.0 VM, including the counter class, collections, Morph ownership, and visible Pen strokes. The check script exits without saving the image. From the project root, rerun it with:

```powershell
& 'C:\Users\Humayun\Documents\Utils\Squeak6.0\SqueakConsole.exe' -headless .\PenStudioMorphic.image .\website\tools\verify-tutorial.st
```

Success is reported as `TUTORIAL VERIFIED: 32 checks`; failures are printed as `TUTORIAL FAILED`. The VM's process exit code alone does not indicate success.

`styles.css` contains the responsive layout and light/dark website themes. `app.js` handles the project tours, searching, and screenshot dialog. No third-party scripts, fonts, or services are used. Tutorial reference links open official Squeak resources when requested.

The PNGs are original project screenshots rendered by Squeak, copied into `assets/screenshots`. The `.st` sources are copied into `assets/source`; snippets in `content.js` are extracted directly from those methods. To refresh the bundled content after changing the project, run:

```powershell
python website/tools/build_content.py
```

Import the ten source files into Squeak in the order listed in the source browser. The main project README has build and verification details.

## Verified Morphic object reference

Open `morphs.html`, choose **Morphic objects** from either page, or double-click the root `Open Morphic Reference.cmd`. This page covers all 19 classes installed under `Morphic-Basic` / `Morphic-Basic-NewCurve`, plus 17 common foundations, form controls, containers, and editing tools. Every object has a native screenshot, complete Workspace code, usage notes, and its passed checks. Search classes, descriptions, or messages; filter by category, copy source, enlarge images, or download examples and verification evidence. The shared light/dark preference applies to all three pages.

Six model-connected examples need `assets/morphs/MorphicReferenceModel.st` filed in first. The remaining examples use installed classes. The displayed images are initial specimens; subsequent behavioral checks may change their state. Examples and screenshots were generated in the actual installed Squeak VM, not simulated by JavaScript.

The catalog generator is the source of truth. To refresh code and native screenshots from the project root, run these commands in order:

```powershell
node website/tools/build_morphic_reference.js
& 'C:\Users\Humayun\Documents\Utils\Squeak6.0\SqueakConsole.exe' -headless .\PenStudioMorphic.image .\website\tools\run-morphic-reference.st
node website/tools/export_morphic_reference.js
```

The run passed **36 examples, 138 checks, 0 failures**. `assets/morphs/verification.txt` records the installed category inventory and each check. The runner evaluates the exact catalog strings, checks returned types and renderability, renders native 640 × 350 Forms, saves and reads back PNGs, and exercises object behavior. It exits without saving the image. Export refuses to publish if the log has failures, examples are missing, or PNG dimensions are wrong. A VM exit code of zero alone does not establish success.

Image-specific details are documented in the examples: `LineMorph` is a factory returning a `PolygonMorph`; `AnimatedImageMorph` needs an explicit backing Form; the pluggable checkbox needs `installButton`; the progress bar needs its initial model refresh; and windows apply their size after opening.

## Advanced Morphic demos

Open `advanced-morphic.html`, choose **Advanced demos** from the other pages, or double-click the root `Open Advanced Morphic Demos.cmd`. Six examples cover nested TableLayout cards, a shared-model dashboard, grid-snapping drag events, scheduled animation with pause/play, custom Canvas chart rendering, and transforming a composite object.

Each demo has initial and verified-result screenshots, explanation, experiments, copyable Workspace entry points, line-numbered source tabs, and its passed checks. The **Build the view** tab shows class-side methods on `AMDDemos`; **Custom behavior** shows instance-side methods on the indicated model or Morph subclass. The entire file-in is available through the source expander and download links. File in `assets/advanced/AdvancedMorphicDemos.st` once before evaluating the entry points; the definitions use standard Squeak Morphic plus six supplied classes.

The exact file-in and entry points passed **6 demos, 44 checks, 0 failures** in the installed Squeak 6.0 VM. Twelve native 820 × 480 PNGs record initial and resulting states. Tests exercise layout resizing, control actions, native editor acceptance, event handlers supplied with native mouse-event objects, deterministic animation steps and pause/play, rendered chart pixels, and transform ownership. These checks do not use desktop mouse automation. The runner exits without saving the image.

To regenerate the code bundle, execute examples, refresh screenshots, and export the page data, run these in order from the project root:

```powershell
node website/tools/build_advanced_morphic.js
& 'C:\Users\Humayun\Documents\Utils\Squeak6.0\SqueakConsole.exe' -headless .\PenStudioMorphic.image .\website\tools\run-advanced-morphic.st
node website/tools/export_advanced_morphic.js
```

Methods displayed on the page are extracted directly from the loaded `.st` file. The log contains a SHA-256 identity for both the source and generated catalog. Export rejects changed content, failed or missing checks, and incorrect screenshot sizes. The website uses the same shared theme and syntax display as the other pages and works offline without a server.

## Simple Squeak animations and GIFs

Open `animations.html`, choose **Animations** in the navigation, or double-click the root `Open Squeak Animations.cmd`. Six examples cover a bouncing ball, orbiting dots, a size/color pulse, a rotating star, a cosine-eased slide, and progressive Pen drawing of an eight-petal flower. Every example includes a representative native PNG, a downloadable looping GIF, complete Workspace entry point, setup/update methods, shared scheduling methods, and experiments. Code has syntax colors, line numbers, and copy controls. GIF previews can be swapped to stills; reduced-motion preference selects stills by default.

File in `assets/animations/SqueakAnimationDemos.st` once to define `SAAnimationMorph`. Evaluate an expression such as `SAAnimationMorph open: #orbit.` in a Workspace. The class is self-contained and uses standard Squeak Morphic, TransformationMorph, Form, and Pen. Use Inspect it for an Inspector on the returned animation, where `self running: false`, `self running: true`, and `self delete` control its lifecycle. The supplied `.st` is a file-in; individual setup/update/clock tabs show instance-side method definitions, not Workspace expressions.

The actual Squeak VM rendered **444 native PNG frames** and passed **492 checks with zero failures**. The runner evaluates the exact entry points, checks the phase and contained bounds of every frame, verifies a complete cycle returns to the initial native pixels, and tests stopping and deletion. It exits without saving the image. The six GIFs are encoded from those PNG frames with Pillow and a shared palette, then reopened to verify 640 × 360 size, visible motion, infinite looping, and exact total duration. GIF palette conversion reduces color precision; the representative PNGs preserve the native rendering. Identical flower hold frames may combine during GIF encoding while keeping the total 3.36-second duration; the other loops are 2.88 seconds. Fixed 40 ms sampled steps encode 25 fps; live World scheduling may vary.

Regenerate the examples, native frames, GIFs, and offline browser data in this order:

```powershell
node website/tools/build_squeak_animations.js
& 'C:\Users\Humayun\Documents\Utils\Squeak6.0\SqueakConsole.exe' -headless .\PenStudioMorphic.image .\website\tools\run-squeak-animations.st
python website/tools/export_squeak_animations.py
```

The encoder requires Pillow. It rejects changed source/catalog hashes or a failed native run. Raw PNG sequences are in `assets/animations/frames`; the `.gif`, representative `.png`, source, Workspace examples, and both verification logs are in `assets/animations`. `animations-data.js` contains the exact source methods and native/GIF recording metadata. No external services or browser animation simulation are used for the previews.

## Shipped Morphic examples

Open `shipped-morphic.html`, choose **Shipped demos** from any guide page, or double-click the root **Open Shipped Morphic Demos.cmd**. The page documents ten native examples already installed in this project image: atoms, infection, MovingEyeMorph’s Squeak-logo factory, Flasher, WatchMorph/ClockMorph, MagnifierMorph, Tetris, SameGame, Mines, and BannerMorph. It provides filtered/searchable cards, animated GIF and initial/representative/final PNG views, enlargement, downloads, complete Workspace recipes, 37 extracted installed methods, recording-driver closures, syntax colors, copy controls, and keyboard-operable code tabs. It uses the shared light/dark theme and works offline.

No new demo classes are defined or filed in. Recipes were executed in the actual Squeak VM, which passed **10 demos, 332 checks, 0 failures**, rendering **226 native 960 × 680 frames**. The runner compares every documented method with the installed compiled-method source before recording. Other checks cover object types, native actions, contained frame bounds, visible changes, and representative PNG round trips. The ten GIFs are encoded from those PNGs and reopened to validate dimensions, visible changes, duration, and looping. Identical hold frames may combine while preserving duration. The runner exits without saving the image.

The inventory contains **49 classes in four categories**, read from SystemOrganization. It includes helper classes and discovery leads; only the ten selected recipes were executed. Other Squeak distributions may omit these MorphicExtras/Etoys packages. Method downloads are Browser source fragments, not file-ins. Workspace recipes return the opened Morph; recording closures require the runner’s `demo` and zero-based `index` arguments.

The GIFs show native methods with deterministic scripted input. Eyes and magnifier move the World hand programmatically; Tetris rotates/moves/drops its native board; SameGame alternates hints/removals; Mines chooses safe cells after its native first reveal. Clocks wait real seconds and use the VM’s local Time API. Banner is a static shipped example, with a GIF showing successive text configurations assembled through its native creation methods. The presentation frame, title, and labels are documentation fixtures. Sampling rates are stated per demo; most loops repeat excerpts rather than closed cycles.

Regenerate installed source exports, recordings, GIFs, and offline data in order from the project root:

```powershell
node website/tools/build_shipped_morphic.js --prepare
& 'C:\Users\Humayun\Documents\Utils\Squeak6.0\SqueakConsole.exe' -headless .\PenStudioMorphic.image .\website\tools\extract-shipped-source.st
node website/tools/build_shipped_morphic.js
& 'C:\Users\Humayun\Documents\Utils\Squeak6.0\SqueakConsole.exe' -headless .\PenStudioMorphic.image .\website\tools\run-shipped-morphic.st
python website/tools/export_shipped_morphic.py
```

Node generates the native extraction and recording scripts; the encoder requires Pillow. Catalog data embeds exact extracted methods. The SHA-256 identity binds that catalog to its native run; export rejects changed source copies, failed/missing demo verification, wrong image sizes, or invalid GIF output. Source files, inventory, recordings, Workspace recipes, and logs are in `assets/shipped`; published offline metadata is `shipped-morphic-data.js`.
