Nature-of-Code-S11
Syllabus / Nature-of-Code-S11

## The Nature of Code

• Spring 2011
• Section 1: Tuesdays 12:30 - 3:00 pm
• Section 2: Wednesdays 12:30 - 3:00 pm
• Daniel Shiffman, daniel.shiffman@nyu.edu
• Office Hours Signup

## Syllabus

Week 1 -- Jan 25/26 -- Numbers and Vectors

• Class Intro / Overview
• Processing review
• Randomness, Probability, and Perlin Noise
• Object Oriented Programming Review & Vectors
• Assignment: Take a look at these two examples of a square randomly moving around the screen: Walker without vectors, Walker with vectors. Find an example of real-world "natural" motion and develop a set of rules for simulating that behavior. Ideas: nervous fly, hopping bunny, slithering snake, etc. See if you can avoid using randomness, or at least consider your use of random carefully and justify it. Consider the challenge of usual minimal visual design, i.e. only grayscale primitive shapes. Can you give your "being" a personality? Can it express emotions -- happiness, sadness, fear, etc.? Post a link to your work, as well as any thoughts on the above, on the homework wiki.
• Reading: Processing PVector tutorial, also available as PDF.
• PDF Handout about probability (available via course mailing list)
• Mathematics and Physics for Programmers, Chapter 5 -- Vectors, Danny Kodicek
• Reading: Computational Beauty of Nature, Introduction, Gary William Flake (you must be logged in through NYU to access the online version.)
• Reading: Probability Theory -- great friendly site!

Week 2 -- Feb 1/2 -- Vectors and Forces

• Object Oriented Programming Review & Vectors
• Attraction/Repulsion
• Friction/Drag
• Core examples
• Homework (choose one / create your own) Post your work on the wiki:
• Rework your motion sketch from week 1 using PVector. Try incorporating the concept of forces into the environment by affecting only the acceleration. Create a formula for calculating a dynamic acceleration, one that changes over time based on any number of factors. Make more than one object by creating an array.
• Create an example where instead of objects bouncing off the edge of the wall, an invisible force pushes back on the objects to keep them in the window. Can you weight the force according to how far the object is from an edge, i.e. the closer it is, the stronger the force?
• Create pockets of air resistance / friction in a Processing sketch. Try using circles instead of rectangles, i.e. pockets of mud (or ice). What if you vary the strength (drag / friction coefficient) of each circle? What if you make some of them the opposite of drag—i.e., when you enter a given pocket you actually speed up instead of slow down?
• Can you create an example where all of the Mover objects are attracted to the mouse, but repel each other? Think about how you need to balance the relative strength of the forces and how to most effectively use distance in your force calculations.
• Research a force not covered in class and implement it as a vector.
• Use the concept of forces to visualize some input (could be data, literal example would be get windspeed online and translate to a wind force in Processing, but feel free to think more abstractly)

Week 3 -- Feb 8/9 -- Oscillations

• (First, continuation of Forces)
• Trigonometry
• Polar vs. Cartesian Coordinates
• Pendulum
• Graphing waves (perlin noise waves)
• 2D trig equation graphing ("graphing inequalities")
• Core examples
• Assignment: Incorporate oscillatory motion into a previous assignment (or create a new one). Some suggestions:
• Create a simulation where objects are shot out of a cannon. Each object should experience a sudden force when shot (just once) as well as gravity (always present). Step 2. Add rotation to the object to model its spin as its shot from the cannon. How realistic can you make it look?
• Create a moving body with a shape made from oscillating parts, i.e. the object moves according to the usual vector motion, but its shape incorporates oscillation around its center point. Consider tying the speed of oscillation to the speed of motion. Think of a butterfly’s flapping wings or the legs of an insect. Can you make it appear that the creature’s internal mechanics (oscillation) drive its locomotion? Example Answer
• Research and implement a simulation of Torque.
• String together a series of pendulums so that the endpoint of one is the origin point of another.
• Create an example that simulates a box sliding down an incline with friction. Note that the magnitude of the friction force is equal to the normal force.
• Rework the wave examples to have a Wave class and visualize the wave using something other than circles. Example Answer (minus the change in visualization)
• Using the Spring example as a basis, create a system of multiple bobs and spring connections. How would you have a Bob connected to a Bob with no fixed anchor?

Week 4 -- Feb 15/16-- Particle Systems

Week 5 -- Feb 22/23 -- Physics Libraries!

• Box2D tutorial: http://www.shiffman.net/teaching/nature/box2d-processing/
• Box2D particle System: http://www.shiffman.net/itp/classes/nature/box2d_2010/liquid
• Reading: This isn't terribly exciting, but read the Box2D manual. It's actually quite helpful for the concepts (you can ignore the code and focus on our class examples instead.)
• Homework: Work on midterm project due to present Week 7. Your midterm assignment should build off of the concepts we've covered this first half of the semester, however you should feel free to think non-traditionally, i.e. your midterm need not simply be a Processing sketch. Please include both visual and text documentation of your project, i.e. you might include a short paragraph description, links to relevant projects, video documentation, screenshots, or online applet, etc. The midterm need not be a finished project, it is useful to use this time to build out a single component of a larger idea. If you are stuck, some midterm suggestions are:
• Extend one of the examples into 3D
• Design a single creature (that you imagine living in a larger eco-system).
• Develop a non keyboard/mouse way of interacting with an environments' forces (i.e. video tracking, sensors, etc.)
• Use physics simulation to fabricate something -- a print, a sculpture, etc.

Week 6 -- Mar 1/2 -- More Libraries, Steering Behaviors

Week 7 -- Mar 8/9 -- Present Midterm

## SPRING BREAK

Week 8 -- Mar 22/23 -- Complex Systems

• Self-Organization Craig Reynolds' Boids -- Alignment, Cohesion, Separation
• Reading: Chapter 15, Cellular Automata, Computational Beauty of Nature, Flake
• Reading: Chapter 16 — Autonomous Agents and Self-Organization, The Computational Beauty of Nature, Gary William Flake,
• Reading: Conway's Game of Life, Scientific American, 1970
• Reading: Exploring Emergence, Mitchel Resnick and Brian Silverman Epistemology and Learning Group MIT Media Laboratory
• Reading: From Ants to People, an instinct to Swarm
• Assignment: Choose one of the following options or create your own.
• Develop your midterm project one step further based on class feedback / discussion.
• Using the flocking example as a model, develop your own set of rules for boid interaction.
• Implement Flake's "View" rule, described in Computational Beauty of Nature
• Create a flow field that changes over time
• Create a flow field based on image data
• Use applyForce() in Box2D or addForce() in Toxiclibs to create a flocking simulation in one of those physics engines
• Combine the concepts of Cellular Automata with the flocking example -- what happens if you assign each boid a "state" which influences its behavior?
• Consider the state of a cell to be its color. What types of image processing filters can you create using the principles of Cellular Automata?
• Develop your own rules for a Cellular Automata, 1D or 2D. This could be something completely made up or a simulation of real-world phenomena. For example, forest fires: [http://en.wikipedia.org/wiki/Forest-fire_model] or Predator, Prey [p. 191 of Computational Beauty of Nature.]
• Develop an alternative "Game of Life" with time as factor, i.e. what does it mean for a cell to be "alive" or "dead" for many frames in a row.

Week 9 -- Mar 29/30 -- More Complex Systems + Self-Similarity

• Wolfram CA, The Game of Life
• Fractals, MandelBrot Set
• Recursion
• L-Systems
• Reading: The Computational Beauty of Nature, Gary William Flake, Chapter 5 — Self-Similarity and Fractal Geometry, Chapter 6 — L-Systems and Fractal Growth
• Reading: Algorithmic Beauty of Plants -- suggested
• Watch: Nova: The Hidden Dimension
• Assignment: Sign up for a final project proposal and presentation slot. Include in your proposal a title, brief description, and links to things you want to show / talk about -- work that inspired you, reference pages, sketches you've made, sample programs/code, previous projects, etc. Tues, Wed

Original Week 10 -- Apr 5/6 -- CANCELLED!!!

Week 10 -- Apr 12/13 -- Final Project Proposals

• This week will be entirely final project proposals. Schedule is here: Tues, Wed

Week 11 -- MAKEUP SESSION -- Friday, Apr 15, 12:30 - 3:00 PM or Monday, April 18, 2:30 - 5:00 PM -- Genetic Algorithms

Week 12 -- Apr 19/20 -- Neural Networks, Remaining Final Project Proposals, and misc. workshop time

Week 13 -- Apr 26/27 -- Final Project Presentations

Week 14 -- May 2/3 -- Final Project Presentations