Moon Wave Maker.

Beautiful sine waves around the curved axis.

Sine waves around the curved axis.


Description of this generative art work.

Generative art work made with Processing.

I wanted to make some work with sine waves.
And I focused on sine wave around a curved axis.

Processing code example.

Please feel free to use this example code, if you like it.
To see other works based on my code is my pleasure. And my honor.

// Moon Wave Maker.
// @deconbatch
// Processing 3.2.1
// 2018.07.01

void setup() {

  size(720, 720);
  colorMode(HSB, 360, 100, 100, 100);
  blendMode(ADD);
  smooth();
  noLoop();
  noStroke();

}

void draw() {

  translate(width / 2, height / 2);
  rotate(PI * random(1.0));

  float waveClassMin = 1.0;
  float waveClassMax = 5.0;
  float hueBase      = random(360.0);
  int   armCntMax    = 3 + 2 * floor(random(1.5));
  int   frameCntMax  = 24 * 6;  // 24fps * 6s

  // draw image and save per frame
  for (int frameCnt = 0; frameCnt < frameCntMax; ++frameCnt) {

    // animate sine wave with phase
    float phase = map(frameCnt, 0, frameCntMax, 0.0, 1.0);
    background(0, 0, 0, 100);

    // draw each arms. it's inefficient way but you can have effects on each arm.
    for (int armCnt = 0; armCnt < armCntMax; ++armCnt) {

      rotate(2.0 * PI / (armCntMax * 1.0));

      // draw sine wave with various frequency and amplitude
      for (float waveClass = waveClassMin; waveClass <= waveClassMax; waveClass += 0.5) {

        float frequency = waveClass;
        float amplitude = height * 0.25 * pow(map(waveClass, waveClassMin, waveClassMax, 1.0, 0.2), 2);
        float length    = width * 0.45;
        float hueApply  = hueBase + map(waveClass, waveClassMin, waveClassMax, 0.0, 30.0);
        float briApply  = 30.0 / waveClass;

        drawWave(
                 frequency,
                 phase,
                 amplitude,
                 length,
                 hueApply,
                 briApply
                 );
      
      }
    }

    saveFrame("frames/" + String.format("%04d", frameCnt) + ".png");

  }

  exit();

}

void drawWave(float frequency, float phase, float amplitude, float length, float hueApply, float briApply) {

  if (length <= 0) {
    return;
  }

  // x axis
  for (float pX = 0; pX <= length; pX += 0.5) {

    float pxRate = pX / length;
    float pSize  = 0.5 + pow(sin(1.0 * PI * (phase + frequency + frequency * pxRate)), 4) * 2.0;     // thickness animate with phase
    float pHue   = (hueApply - sin(1.0 * PI * (phase + frequency * pxRate)) * 30.0 + 360.0) % 360.0; // color animate with phase

    // draw same sine wave in different amplitude
    for (float ampMult = 0.0; ampMult <= 1.0; ampMult += 0.025) {

      float pY   = amplitude * sin(2.0 * PI * (-phase + frequency * pxRate)) // sine wave
        * sin(PI * map(ampMult, 0.0, 1.0, 0.2 / frequency, 0.5));            // smaller wave with ampMult
      float pBri = briApply * sin(1.0 * PI * (0.04 + 0.96 * pxRate))         // darker in center and far end
        * sin(PI * map(ampMult, 0.0, 1.0, 0.01, 0.5));                       // darker in smaller wave

      fill(
           pHue,
           40.0,
           pBri,
           100.0
           );

      pushMatrix();
      rotate(-PI * sin(0.5 * PI * pxRate) * 0.5);
      ellipse(
              pX,
              pY,
              pSize,
              pSize
              );
      popMatrix();
        
    }

  }

}

/*
Copyright (C) 2018- deconbatch

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see 
*/





No comments :

Post a Comment