Basics of programming
1. Coordinates
2. Provide a command (which we will refer to as a “ function ” ) for the machine to follow entitled “ line. ” In addition, we specify some arguments for how that line should be drawn, from point A (0,1) to point B (4,5).
3. Color and transparency
4. Zoog
Coding in Processing
1. Basic syntax rules. Th ere are three kinds of statements we can write:
• Function calls 函数调用
quad(38, 31, 86, 20, 69, 63, 30, 76);
noFill();
stroke(255, 102, 0);
curve(5, 26, 5, 26, 73, 24, 73, 61);
stroke(0);
curve(5, 26, 73, 24, 73, 61, 15, 65);
stroke(255, 102, 0);
curve(73, 24, 73, 61, 15, 65, 15, 65);
• Assignment operations 赋值操作
Varaible declaration and initialization: Variables can hold primitive values or references to objects and arrays . Variables are declared by first stating the type, followed by the name. A type is the kind of data stored in that variable
• Control structure 控制结构
The flow of a processing program (two “ blocks of code ” setup( ) and draw( ) -----A block of code is any code enclosed within curly brackets.)
Blocks1: setup(): Initialize conditions; Just as a game begins with a set of initial conditions: you name your character, you start with a score of zero, and you start on level one.
After these conditions are initialized, you begin to play the game.
Blocks2: draw() and mouse events: At every instant, the computer checks what you are doing with the mouse, calculates all the appropriate behaviors for the game characters, and updates the screen to render all the game graphics. Th is cycle of calculating and drawing happens over and over again, ideally 30 or more times per second for a smooth animation.
Note: If nothing in the draw() function varies each, the program will still run over time redrawing the window, but it looks static to us !!!
The speed at which the mouse is moving is :
• abs( mouseX - pmouseX )
Blocks3: Mouse Events : mousePressed, keyPressed
frameRate( ) , which requires an integer between 1 and 60, enforces the speed at which Processing will cycle through draw( ).frameRate (30) ,
for example, means 30 frames per second, a traditional speed for computer animation.
This concept is crucial to our ability to move beyond static designs with Processing .
Step 1. Set starting conditions for the program one time.
Step 2. Do something over and over and over and over (and over … ) again until the program quits.
Consider how you might go about running a race.
Step 1. Put on your sneakers and stretch. Just do this once, OK?
Step 2. Put your right foot forward, then your left foot. Repeat this over and over as fast as you can.
Step 3.After 26 miles, quit.