Skip to content

Instantly share code, notes, and snippets.

@micuat
Created March 28, 2021 17:40
Show Gist options
  • Save micuat/6d5334fe4d8d01e176f0544f2ca7f518 to your computer and use it in GitHub Desktop.
Save micuat/6d5334fe4d8d01e176f0544f2ca7f518 to your computer and use it in GitHub Desktop.
ArrayList<PVector> points = new ArrayList<PVector>();
void setup() {
size(800, 800, P3D);
}
void draw() {
float thickness = 10;
ArrayList<Float> angles = new ArrayList<Float>();
for (int i = 0; i < points.size() - 1; i++ ) {
PVector v0 = points.get(i);
PVector v1 = points.get(i+1).copy();
v1.sub(v0);
float angle = v1.heading();
angles.add(angle);
}
float t = millis() * 0.001;
background(255);
noStroke();
fill(20, 100, 230);
beginShape(TRIANGLE_STRIP);
for (int i = 0; i < points.size() - 1; i++ ) {
PVector v0 = points.get(i);
float angle = angles.get(i);
{
float a = angle + PI/2;
float x = cos(a) * thickness;
float y = sin(a) * thickness;
vertex(v0.x + x, v0.y + y, 100 * sin(t*2 + i/3.0));
}
{
float a = angle - PI/2;
float x = cos(a) * thickness;
float y = sin(a) * thickness;
vertex(v0.x + x, v0.y + y, 100 * sin(t*2 + i/3.0));
}
}
endShape(CLOSE);
stroke(100, 20, 200);
strokeWeight(3);
noFill();
beginShape();
for (int i = 0; i < points.size() - 1; i++ ) {
PVector v0 = points.get(i);
float angle = angles.get(i);
angle += PI/2;
float x = cos(angle) * thickness;
float y = sin(angle) * thickness;
vertex(v0.x + x, v0.y + y, 100 * sin(t*2 + i/3.0));
}
for (int i = points.size() - 2; i >= 0; i-- ) {
PVector v0 = points.get(i);
float angle = angles.get(i);
angle -= PI/2;
float x = cos(angle) * thickness;
float y = sin(angle) * thickness;
vertex(v0.x + x, v0.y + y, 100 * sin(t*2 + i/3.0));
}
endShape(CLOSE);
}
void addPoint() {
PVector v = new PVector(mouseX, mouseY);
points.add(v);
}
void mousePressed() {
points.clear();
addPoint();
}
void mouseDragged() {
addPoint();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment