/** * Array. * * An array is a list of data. Each piece of data in an array * is identified by an index number representing its position in * the array. Arrays are zero based, which means that the first * element in the array is [0], the second element is [1], and so on. * In this example, an array named "coswave" is created and * filled with the cosine values. This data is displayed three * separate ways on the screen. */float[] coswave; //创建了一个数组void setup(){ size(640, 360); //设置窗口大小 coswave = new float[width]; //将数据放入数组内 for (int i = 0; i < width; i++) { //使用map函数将0-width与0-PI对应 float amount = map(i, 0, width, 0, PI); //abs()计算绝对值,cos()函数 coswave[i] = abs(cos(amount)); } background(255); //背景色 noLoop(); //禁止循环}void draw() { int y1 = 0; int y2 = height/3; for (int i = 0; i < width; i++) { //绘制线条或者边框的颜色值 stroke(coswave[i]*255); //绘制一条线 line(i, y1, i, y2); } y1 = y2; y2 = y1 + y1; for (int i = 0; i < width; i++) { stroke(coswave[i]*255 / 4); line(i, y1, i, y2); } y1 = y2; y2 = height; for (int i = 0; i < width; i++) { stroke(255 - coswave[i]*255); line(i, y1, i, y2); }}