level 2
007kiol
楼主
int sampling = 500;
float amplitude = 50;
float cycle = 1.5;
float wavelength = 300;
float minWeight = 2;
float maxWeight = 8;int _frameRate = 60;
int wave_num = 3;
int sampling = 100;float amplitude = 100;
float cycle = 1;
float wavelength = 200;float offset_time;
float offset_time_velocity = TWO_PI/_frameRate/cycle; float offset_time_eachPoint;
float point_position_y;ArrayList<Wave> waves;
Point tempP;
Wave tempW; void setup() {
size(400,400,P3D);
colorMode(HSB,100);
frameRate(_frameRate);
offset_time_eachPoint = TWO_PI / (wavelength/width * sampling);
waves = new ArrayList<Wave>();
for (int i = 0; i < wave_num; i ++) {
Wave w = new Wave(i);
waves.add(w);
}
} void draw() {
background(51);
offset_time += offset_time_velocity;
stroke(255);
for (int i = waves.size() - 1; i >= 0; i --) {
tempW = waves.get(i);
tempW.change();
}
}class Wave{
int index_wave;
ArrayList<Point> points;
Wave(int _i){
index_wave = _i;
points = new ArrayList<Point>();
for (int i = 0; i < sampling; i ++) {
Point p = new Point(i, index_wave);
points.add(p);
}
}
void change() {
for (int i = points.size() - 1; i >= 0; i--) {
tempP = points.get(i);
tempP.move();
tempP.display();
}
}
} class Point{
PVector pos;
int index_point;
int index_wave;
float offset_time_currentPoint;
float offset_eachWave = 1;
float shrink;
float offset_eachWave = PI;
float _weight;
color c;
float h;
float s = 85;
float b = 99;
}
Point(int _i, int _i_w) {
index_point = _i;
index_wave = _i_w;
pos = new PVector();
offset_time_currentPoint = index_point * offset_time_eachPoint + index_wave*offset_eachWave;
pos.x = (index_point+0.5)/sampling*width;
shrink = pow( sin(pos.x/width * PI), 2);
_weight = map(shrink, 0, 1, minWeight, maxWeight - index_wave*2);
}
void move() {
if(index_wave == 0) {
pos.y =shrink * amplitude * sin(offset_time + offset_time_currentPoint) + height/2;
} else if (index_wave == 1) {
pos.y =shrink * -0.42 * amplitude * ( sin(offset_time + offset_time_currentPoint) + sin(offset_time/2 + offset_time_currentPoint/2) ) + height/2;
} else {
pos.y =shrink * 0.5 * amplitude * ( sin(offset_time + offset_time_currentPoint) + 2*sin(offset_time/2 + offset_time_currentPoint/2) ) + height/2;
}
}void display() {
strokeWeight(_weight);
h = (map(shrink, 0, 1, 75, 65) + map(pos.y, height/2 + amplitude, height/2 - amplitude, 60, 90)) / 2;
c = color(h, s, b);
stroke(c);
point(pos.x, pos.y);
}
}
2020年05月17日 07点05分
1
float amplitude = 50;
float cycle = 1.5;
float wavelength = 300;
float minWeight = 2;
float maxWeight = 8;int _frameRate = 60;
int wave_num = 3;
int sampling = 100;float amplitude = 100;
float cycle = 1;
float wavelength = 200;float offset_time;
float offset_time_velocity = TWO_PI/_frameRate/cycle; float offset_time_eachPoint;
float point_position_y;ArrayList<Wave> waves;
Point tempP;
Wave tempW; void setup() {
size(400,400,P3D);
colorMode(HSB,100);
frameRate(_frameRate);
offset_time_eachPoint = TWO_PI / (wavelength/width * sampling);
waves = new ArrayList<Wave>();
for (int i = 0; i < wave_num; i ++) {
Wave w = new Wave(i);
waves.add(w);
}
} void draw() {
background(51);
offset_time += offset_time_velocity;
stroke(255);
for (int i = waves.size() - 1; i >= 0; i --) {
tempW = waves.get(i);
tempW.change();
}
}class Wave{
int index_wave;
ArrayList<Point> points;
Wave(int _i){
index_wave = _i;
points = new ArrayList<Point>();
for (int i = 0; i < sampling; i ++) {
Point p = new Point(i, index_wave);
points.add(p);
}
}
void change() {
for (int i = points.size() - 1; i >= 0; i--) {
tempP = points.get(i);
tempP.move();
tempP.display();
}
}
} class Point{
PVector pos;
int index_point;
int index_wave;
float offset_time_currentPoint;
float offset_eachWave = 1;
float shrink;
float offset_eachWave = PI;
float _weight;
color c;
float h;
float s = 85;
float b = 99;
}
Point(int _i, int _i_w) {
index_point = _i;
index_wave = _i_w;
pos = new PVector();
offset_time_currentPoint = index_point * offset_time_eachPoint + index_wave*offset_eachWave;
pos.x = (index_point+0.5)/sampling*width;
shrink = pow( sin(pos.x/width * PI), 2);
_weight = map(shrink, 0, 1, minWeight, maxWeight - index_wave*2);
}
void move() {
if(index_wave == 0) {
pos.y =shrink * amplitude * sin(offset_time + offset_time_currentPoint) + height/2;
} else if (index_wave == 1) {
pos.y =shrink * -0.42 * amplitude * ( sin(offset_time + offset_time_currentPoint) + sin(offset_time/2 + offset_time_currentPoint/2) ) + height/2;
} else {
pos.y =shrink * 0.5 * amplitude * ( sin(offset_time + offset_time_currentPoint) + 2*sin(offset_time/2 + offset_time_currentPoint/2) ) + height/2;
}
}void display() {
strokeWeight(_weight);
h = (map(shrink, 0, 1, 75, 65) + map(pos.y, height/2 + amplitude, height/2 - amplitude, 60, 90)) / 2;
c = color(h, s, b);
stroke(c);
point(pos.x, pos.y);
}
}