Advertisement
wblut

Euler spiral

Sep 9th, 2018
1,184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1. void setup() {
  2.   fullScreen(P3D);
  3. }
  4.  
  5. void draw() {
  6.   background(240);
  7.   stroke(15);
  8.   noFill();
  9.   drawEulerSpiral(width/2, height/2, frameCount*0.01, 1000, 500.0);
  10. }
  11.  
  12. void drawEulerSpiral(float centerX, float centerY, float range, int numPoints, float scale) {
  13.   float ds=range/numPoints;
  14.   float prevX=0;
  15.   float prevY=0;
  16.   float currentX=0;
  17.   float currentY=0;
  18.   float s=0;
  19.   for (int i=0; i<numPoints; i++) {
  20.     prevX=currentX;
  21.     prevY=currentY;
  22.     currentX+=scale*Math.cos(s*s)*ds;
  23.     currentY+=scale*Math.sin(s*s)*ds;
  24.     line(centerX+prevX, centerY+prevY, centerX+currentX, centerY+currentY);
  25.     line(centerX-prevX, centerY-prevY, centerX-currentX, centerY-currentY);
  26.     s+=ds;
  27.   }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement