第八章 函数
float calcuateMars(float w) {
float newWeight = w * 0.38;
return newWeight;
}
第九章
JitterBug jit;
JitterBug bug; //声明变量
void setup() {
size(480, 120);
smooth() ;
//创建对象并传递参数
bug = new JitterBug(width * 0.66, height/2, 20);
jit = new JitterBug(width * 0.33, height/2, 50);
}
void draw() {
jit.move();
jit.display();
bug.move();
bug.display();
}
class JitterBug {
float x;
float y;
int diameter;
float speed = 15;
JitterBug(float tempX, float tempY, int tempDiameter) {
x = tempX;
y = tempY;
diameter = tempDiameter;
}
void move() {
x += random(-speed, speed);
y += random(-speed, speed);
x = constrain(x, 0, width);
y = constrain(y, 0, height);
}
void display() {
ellipse(x, y, diameter, diameter);
}
}
第十章 数组
//10.3
//float x[] = new float[3000];
//void setup() {
// size(240, 120);
// smooth();
// noStroke();
// fill(255, 200);
// for (int i = 0; i<x.length; i++) {
// x[i] = random(-1000, 200);
// }
//}
//void draw() {
// background(0);
// for (int i =0; i<x.length; i++) {
// x[i] += 0.5;
// float y = i* 0.4;
// arc(x[i], y, 12, 12, 0.52, 5.76);
// }
//}
int[] x = new int[2000];
PImage[] images = new PImage[32];
1.声明和定义数据类型
2.创建新的关键字和数组长度
3.给每个元素配值
int[] x = { 12, 2}; //声明、创建、赋值
/*
nf(1,4) 0001
nf(4,4) 0004
nf(11,4) 0011
*/
