processing基础

https://www.processing.org/re...
https://www.openprocessing.org/
http://www.vizinsight.com/
http://learningprocessing.com/
http://www.wblut.com/processing/
http://www.wblut.com/construc...
http://www.complexification.n...
http://ofcourse.io/
http://learn.travelchinawith.me
http://zenbullets.com/abandon...

开始

单击run
shift+鼠标单击run 全屏
Processing文件名不允许空格和连字符-,也不能以数字开始,.pde结尾

控制台

print()
println()    
printArray()

基础

void setup() {}  //定义画布大小,背景,画笔等  仅执行一次后跳到draw()
void draw() {}  //程序作画  无限循环运行
void functionName() {}  //自定义函数
void mousePressed(){}  //鼠标事件
void keyPressed(){}  //键盘事件
class className(){}  //自定义类
size(Width,Height);//画布大小
strokeWeight(5);  //画笔大小
noLoop();  //循环一次
delay(100); 

变量

原始变量

int( –2147483648 ~ 2147483647)

int a;          
a = 23;        
int b = -256;   
int c = a + b;

float String(S大写)
boolean
color

color c1 = color(204, 153, 0);
color c2 = #FFCC00;

char(字母)
byte( –128 ~ 127)
short( –32768 ~ 32767)
long
double
全局变量,局部变量,尽量用驼峰命名,class是用大写字母开头

环境变量

width —sketch窗口的像素宽度.
height —sketch窗口的像素高度.
size(150, 200, P3D);
delay()
smooth();
cursor()
noCursor()
fullScreen()
frameCount —运行的帧数.
frameRate —每秒运行的帧数.
screen.width —整个萤幕的像素宽度
screen.height —整个萤幕的像素高度.

key —最近的一次键盘敲击.
keyCode —键盘敲击的数字代码(numeric code).
keyPressed —真还是假?键盘被敲击了么?
mousePressed —真还是假?鼠标被点击了么?
mouseButton —哪个键被点击了?左键?右键?还是中键?


//载体
PVector v1;
v1 = new PVector(40, 20);
v1.x
x1.y

数组

int[] numbers = {1,2,3};
numbers[0];
float[] values = new float[1000];
Car[] cars = new Car[num];
balls = (Ball[]) append(balls,b); 

颜色

color c1 = color(204, 153, 0);
colorMode(HSB, 100);
colorMode(RGB, 100);
fill();
noFill();
stroke();
noStroke();
alpha(rgba);
green(rgb);
blue(rgb);
red(rgb);
lerpColor(c1, c2, amt)

图片

PImage img;  
img = loadImage("1.jpg");  
background(img); 
image(img,0,0);
imageMode(CORNER); CORNER, CORNERS, or CENTER
save("C:\Users\shumei\Desktop");
saveFrame("line-######.png");

图片处理

loadPixels();
pixels[];
updatePixels();
red(color);
green(color);
blue(color);

图片滤镜

filter(MODE);  //THRESHOLD, GRAY, OPAQUE, INVERT, POSTERIZE, BLUR, ERODE, DILATE
blend(x,y,width,height,dx,dy,dwidth,dheight,MODE)
blend(srcImg,x,y,width,height,dx,dy,dwidth,dheight,MODE)  //BLEND, ADD, SUBTRACT, LIGHTEST, DARKEST, DIFFERENCE, EXCLUSION, MULTIPLY, SCREEN, OVERLAY, HARD_LIGHT, SOFT_LIGHT, DODGE, BURN
img1.mask();
copy(x,y,width,height,dx,dy,dwidth,dheight)    copy(srcImg,x,y,width,height,dx,dy,dwidth,dheight)

形状

arc(x, y, width, height, start, stop)
arc(x, y, width, height, start, stop, mode)
ellipse(x, y, width, height)
line(x1, y1, x2, y2)
line(x1, y1, z1, x2, y2, z2) 
point(x, y)
point(x, y, z)    
quad(x1, y1, x2, y2, x3, y3, x4, y4)
rect(x, y, width, height)
rect(x, y, width, height, radius)
rect(x, y, width, height, tl, tr, br, bl)
triangle(x1, y1, x2, y2, x3, y3)

mouseX 鼠标坐标
mouseY 鼠标坐标
pmouseX 移动鼠标之后的鼠标原位置坐标
pmouseY 移动鼠标之后的鼠标原位置坐标
abs()绝对值(absolute value)
frameRate(30) 1~60帧
rectMode(CENTER);
random(256);
dist();
max();
textAlign();
x= constrain(x,0,100);

你可能感兴趣的:(processing)