驼峰命名camelCasing
–小写开头
–易读
Ø变量存储的类别。取值的范围。
Øint:: 非负自然数.
–InProcessing, 范围 [ -2147483648 , 2147483647 ]
–操作符operators: +, -, *, DIV, MOD
Ø浮点数float
–InProcessing, 范围[ -3.40282347E+38 , 3.40282347E+38 ]
–操作符: +, -, *, /, square root, ...
Øboolean:: 两个值:true and false
–操作符: AND, OR, NOT, ...
Ø只读,不能赋值
Ø mouseX/ mouseY :: 当前鼠标值
Ø width / height :: 当前窗口的长宽
Ø frameCount:: 当前帧的数量,从程序开始.
Ø应该把大段代码编程小段的函数,从而易于理解
Ø全局变量尽量少用
custom shapes 自定义形状
Øvertex()
Ø放在beginShape() 和endShape() 中间
voidsetup() {
size(400, 400);
smooth();
noStroke();
}
voiddraw() {
background(0);
// draw a star at the current mouse position
fill(216, 61, 4);
drawStar(mouseX, mouseY, 100);
}
void drawStar(intxPos,intyPos,intstarSize){
beginShape();
vertex(xPos, yPos-starSize/2);
vertex(xPos-starSize/3, yPos+starSize/2);
vertex(xPos+starSize/2, yPos-starSize/8);
vertex(xPos-starSize/2, yPos-starSize/8);
vertex(xPos+starSize/3, yPos+starSize/2);
vertex(xPos, yPos-starSize/2);
endShape();
}
![]()
Ø常用函数
–round()
–abs()
–ceil()
–floor()
–random()
–sqrt()
Ø只读,不能赋值
Ø mouseX/ mouseY :: 当前鼠标值
Ø width / height :: 当前窗口的长宽
Ø frameCount:: 当前帧的数量,从程序开始.
Ø应该把大段代码编程小段的函数,从而易于理解
Ø全局变量尽量少用
custom shapes 自定义形状
Øvertex()
Ø放在beginShape() 和endShape() 中间
voidsetup() {
size(400, 400);
smooth();
noStroke();
}
voiddraw() {
background(0);
// draw a star at the current mouse position
fill(216, 61, 4);
drawStar(mouseX, mouseY, 100);
}
void drawStar(intxPos,intyPos,intstarSize){
beginShape();
vertex(xPos, yPos-starSize/2);
vertex(xPos-starSize/3, yPos+starSize/2);
vertex(xPos+starSize/2, yPos-starSize/8);
vertex(xPos-starSize/2, yPos-starSize/8);
vertex(xPos+starSize/3, yPos+starSize/2);
vertex(xPos, yPos-starSize/2);
endShape();
}
Ø常用函数
–round()
–abs()
–ceil()
–floor()
–random()
–sqrt()