File Exchange

image thumbnail

Megan Simulator (XKCD)

version (4.95 MB) by Alfonso Nieto-Castanon
Stick-figure model


Updated 16 Jun 2015

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

This is a simple/fun stick-figure model of Megan (XKCD character).

A user-friendly GUI allows users to generate model movements, visualize the results in real-time, as well as create snapshots and videos. A variety of predefined (and somewhat silly) environments will have Megan dancing, jumping, painting, skating, and more (see accompanying video for an example).

Model highligts:
Pose can be controlled using PCA-based "natural" pose/articulatory dimensions
Model includes automatically-maintained state parameters and dynamic physics-based rules
Simple physics-based rules allow walking/jumping: while on the floor changes in pose will make Megan pivot over her standing foot -or other extremity- with perfect equilibrium; inertia/gravity modeling allows jumps, hair movement, wind effects, etc.

GUI highlights:
Define random trajectories in pose space and load/save trajectories from a mat file
Change movement speed/extent or manually browse through the pose trajectories at the desired pace
Choose among 5 pre-defined environments (none / little planet / pool skating / painting / wave riding) with more to come.
Fine-tune physics rules and environment look with a great variety of user-definable settings
Create snapshots or videos of your results

Visit this Trendy plot ( for a one-painting-a-day display of Megan's artwork
Stay tuned for Cody challenges associated with this model, and have fun!

Cite As

Alfonso Nieto-Castanon (2020). Megan Simulator (XKCD) (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (11)

Joel Berg


Yu Ang Tan

Well done! Really well done!!

Ander Biguri

This exists. And its amazing. AMAZING


Really impressive, Alfonso!

LY Cao

Luke Gahan


. speed-up the display (~30fps real-time display on my laptop)
. improved hair physics

added wind effects

physics model: added hair movement and angular momentum conservation (e.g. extend your arms to reduce spin velocity)
GUI: added explanations of all user-definable parameters in Settings

fixed camera-tracking issue


simplified drawMegan calling syntax

added angular control and angular momentum rules (spinning!)

no changes: just updating the file description info

added click-and-drag functionality on pose trajectory display

MATLAB Release Compatibility
Created with R2008b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired: Intuitive RGB color values from XKCD