前回2本の直線からできるベジェ曲線を描きましたが、さらに別の直線を増やすことで、
1本目と2本目のベジェ曲線、2本目と3本目のベジェ曲線ができます。
この二つのベジェ曲線の軌跡を線で繋いで、同じく等分割すると3つめのベジェ曲線ができます。
そして10個まで増やしてみるとこんな感じになりました。
int order;
int count;
int col_num;
float steps;
float diffs;
float cpx[];
float cpy[];
float tempx[][];
float tempy[][];
float bzx[][][];
float bzy[][][];
float col_val;
boolean step_flag;
boolean draw_flag;
void setup () {
size (1200, 800);
colorMode (HSB, 256);
background (0);
frameRate (60);
strokeWeight (0.5);
order = 10;
count = 0;
steps = 0.00;
diffs = 0.01;
cpx = new float[order + 1];
cpy = new float[order + 1];
tempx = new float[order][int (1 / diffs)];
tempy = new float[order][int (1 / diffs)];
bzx = new float[order][order][int (1 / diffs)];
bzy = new float[order][order][int (1 / diffs)];
step_flag = false;
draw_flag = false;
}
void draw () {
if (step_flag == true && count < int (1 / diffs)) {
for (int i = 0; i < order; i++) {
tempx[i][count] = (cpx[i + 1] * (1 - steps)) + (cpx[i] * steps);
tempy[i][count] = (cpy[i + 1] * (1 - steps)) + (cpy[i] * steps);
if (i > 0) {
stroke (255, 40);
line (tempx[i - 1][count], tempy[i - 1][count], tempx[i][count], tempy[i][count]);
for (int j = 0; j < order; j++) {
if (j == 0) {
bzx[j][i][count] = (tempx[i][count] * (1 - steps)) + (tempx[i - 1][count] * steps);
bzy[j][i][count] = (tempy[i][count] * (1 - steps)) + (tempy[i - 1][count] * steps);
} else {
bzx[j][i][count] = (bzx[j - 1][i][count] * (1 - steps)) + (bzx[j - 1][i - 1][count] * steps);
bzy[j][i][count] = (bzy[j - 1][i][count] * (1 - steps)) + (bzy[j - 1][i - 1][count] * steps);
}
if (count > 0) {
if (i > j) {
col_val = map (j, 0, order, 0, 220);
stroke (col_val, 255, 255);
//stroke (255 / (j + 1), 255 / (j + 1), 255 / (j + 1));
line (bzx[j][i][count - 1], bzy[j][i][count - 1], bzx[j][i][count], bzy[j][i][count]);
}
}
if (count == int (1 / diffs) - 1) {
if (i > j) {
col_val = map (j, 0, order, 0, 220);
stroke (col_val, 255, 255);
//stroke (255 / (j + 1), 255 / (j + 1), 255 / (j + 1));
line (bzx[j][i][count], bzy[j][i][count], cpx[i - j - 1], cpy[i - j - 1]);
}
}
}
}
}
steps += diffs;
count += 1;
} else {
step_flag = false;
}
}
void mouseReleased () {
background (0);
steps = 0;
count = 0;
cpx = new float[order + 1];
cpy = new float[order + 1];
for (int i = 0; i <= order; i++) {
cpx[i] = random (width);
cpy[i] = random (height);
if (i > 0) {
stroke (255, 80);
line (cpx[i], cpy[i], cpx[i - 1], cpy[i - 1]);
}
}
step_flag = true;
}