Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying my hand at Processing, the "Logo" for grown-ups
#6
Still in my log spiral binge, now with multiple spirals:

[Image: 2PJGxEY.png]

Code:
float startAngle=0; // degrees

void setup() {
  size(800, 800);
  //fullScreen(2);
  colorMode(HSB, 360, 100, 100);
  frameRate(20);
}

void drawSquare(float radius, float angle, float size, float pitch) {
  float squareX=width/2+radius*cos(angle);
  float squareY=height/2+radius*sin(angle);
  pushMatrix();
  translate(squareX, squareY);
  rotate(angle+pitch); // Compensate "slope"of log spiral
  rect(0, 0, size, size, size/3);
  popMatrix();
}

float  angleVariation(float baseValue, float angle, float frequency, float shift) {
  return baseValue+(100-baseValue)*sin(frequency*angle+shift);
}

void drawSpiral(float baseRadius, float startAngle, float shrinkRate, float stepAngle) {
  float baseSize=baseRadius/20;
  float baseBrightness=85;
  float baseSaturation=80;
  float relativeAngle=0; // Degrees
  float pitch=atan(shrinkRate); // radians
  while (true)  {
    float shrink=exp(shrinkRate*radians(relativeAngle));
    float radius=baseRadius*shrink;
    float size=baseSize*shrink;
    float absoluteAngle=radians(startAngle+relativeAngle); // radians
    if (radius < 1) break;
    float hue=(startAngle+(relativeAngle*1.35))%360;
    fill(hue,
      angleVariation(baseSaturation, absoluteAngle, 8, radians(0)),
      angleVariation(baseBrightness, absoluteAngle, 8, radians(30))
      );
    drawSquare(radius, radians(startAngle+relativeAngle), size, -pitch);
    relativeAngle+=stepAngle;
  }
}



void draw() {
  noLoop();
  noStroke();
  background(0, 0, 100);
  float baseRadius=height/2-60.;
  float shrinkRate=-.1;
  float stepAngle=3.123; // degrees
  float startAngle=1.*(frameCount-1); // degrees, For animation
  int spirals=12;
  for (int i=0; i<spirals;i++) {
    drawSpiral(baseRadius,startAngle+i*(360/spirals),shrinkRate,stepAngle);
  }
  save("/tmp/Processing.png");
}
Reply


Messages In This Thread
RE: Trying my hand at Processing, the "Logo" for grown-ups - by Ofnuts - 06-23-2024, 09:14 AM

Forum Jump: