MCB419 logo  


In this course we will be programming in javascript using a library called p5js to develop interactive, agent-based simulations. We will have weekly programming assignments and will be doing in-class programming exercises almost every class session. Please bring a laptop to class. If this is a problem, talk to Prof. Nelson.

Getting Started

We will be using a couple of different online code editors: the p5js editor and the jsbin editor.
Here are some useful keyboard shortcuts for the p5js editor.

Here's a sample MCB 419 template file in both environments: the p5js template and the jsbin template.
If you create a user account you can "duplicate" or "clone" the template files and save your own modified version.

Here are some p5js examples and the full language reference.

If you are relatively new to programming, you might want to work through Dan Schiffman's p5js tutorial videos.

If you are an experienced programmer, but your javascript skills are rusty, I recommend Learn javascript in Y minutes.

I will provide lots of course-specific tutorials and examples in class to help you get started.

Abbreviated Reference

Here are links to some of the most common p5.js functions:

Structure/Control draw() setup()
Graphics Properties createCanvas() frameRate() frameCount height width
Math Functions abs() ceil() constrain() dist() exp() floor() log() mag() map() min() max() norm() pow() round() sq() sqrt()
Trig Functions sin() cos() tan() asin() acos() atan() atan2()
Random Values random() randomSeed() randomGaussian() noise() noiseSeed()
Useful Variables height width frameCount frameRate
Primitive Shapes ellipse() line() point() rect() triangle()
Color background() color() fill() noFill() stroke() noStroke()
Transforms push() pop() translate() rotate() scale()
Text/String text() textAlign() + nf()
Mouse Functions mouseClicked() mouseDragged() mouseMoved() mousePressed() mouseReleased() mouseWheel()
Mouse State mouseX mouseY
Graphical User Interface html() mousePressed() parent() value()
Math Operators + - * / += -= *= /= ++(increment) --(decrement) %(modulus)
Relational Operators !=(inequality) ==(equality) < <= > >=
Logical Operators !(logical NOT) &&(logical AND) ||(logical OR)
Constants true false HALF_PI PI QUARTER_PI TWO_PI
Comments //(inline comment) /* ... */(block comment)

Mark E. Nelson, University of Illinois at Urbana-Champaign, 2005-2019.