shiffman / LearningProcessing

A repo for examples from the book Learning Processing
http://learningprocessing.com
606 stars 276 forks source link

example 13-8 #188

Open shiffman opened 9 years ago

shiffman commented 9 years ago

From reader:

I think there's something wrong with the code pag. 252 > Learning Processing 2d ediotion.

Example 13-8 Wave:

Missing variable: "angle" Missing variable incrementation angle += "something";

SetupandDraw commented 9 years ago

to be more precise: looks like there is a variable name "angle" that should be replaced with variable name "x" or viceversa in order for the sketch to work properly.

// float y = map(sin(angle), -1, 1, 0, height);

Here is the code with "x" instead of "angle"

// starting angle float theta = 0.0;

void setup() { size(512, 512); }

void draw() { background(255); theta += 0.02;

noStroke();
fill(0);
float x = theta;

for (int i = 0; i <= width; i++){
    float y = map(sin(x), -1, 1, 0, height);
    ellipse(i*10, y, 16, 16);

    // Increment angle
    x += 0.1;
}   

}