環境/macOS Montery Apple Silicon Mac

ジェネラティブ・アート、サウンドビジュアライズのアイディアとしてMath(数学)を利用しました。現在でも暗号理論で使われている基本的なアルゴリズム“ユークリッドの互除法”でサウンドの可視化を試みています。
I used mathematics as an idea for generative art and sound visualization. I attempted to visualize sound using the Euclidean algorithm, a basic algorithm still used today in cryptanalysis.

Sound Euclidean Algorithm

Processing-Sound library

コードは、Processingのadd moreよりSoundライブラリーをインストールが必要になります。
The following source code requires the Sound library to be installed from Processing’s add more.

Source code of Sound Euclidean Algorithm

下記コード内の soundfile = new SoundFile(this, “音源ファイル”); 適宜変更します。

下記ソースコードでは、最大公約数を求める際の二つの自然数の片方を10、もう一方をサウンド音量に当てています。最大公約数を求める際の式を正方形や長方形に分割し、その二つを組み合わせ“再帰性”を加える視覚表現としています。

ユークリッドの互除法 – Wikipedia

soundfile = new SoundFile(this, “sound file”) in the code below; modify as appropriate.

In the source code below, one of the two natural numbers used to find the greatest common divisor is 10, and the other is the sound volume. The expression for finding the greatest common divisor is divided into squares and rectangles, and the two are combined to create a visual representation that adds “recursion.

Euclidean Algorithm


/**
 *Sound-Euclidean-Algo
 *This code made by barbe_generative_diary
 *URL https://barbegenerativediary.com/
 *date 3.22.2022 Sound-Euclidean-Algo
 */
 
import processing.sound.*;
SoundFile soundfile;
Amplitude vol;

euclidAlgo euclidA;

void setup(){
  //size(500,500);
  background(10);
  size(1300,1300);
  //background(10);
  frameRate(10);
  soundfile = new SoundFile(this, "211108_ambient_01.wav");
  soundfile.loop();
  vol = new Amplitude(this);
  vol.input(soundfile);
  
  euclidA = new euclidAlgo();
}

void draw(){
  fill(10);  
  noStroke();
  rect(0,0,width,height);
  soundfile.rate(1.1);
  int ampLength = int(vol.analyze()*100);
  euclidA.update(ampLength);
}

ユークリッドの互除法を使用したクラス
Class for drawing squares using Euclidean Algorithm.


/**The euclidean-Algo class
 * Drawing Euclidean-Rect
 */
 
class euclidAlgo{
  float margin; //margin
  float fra, initFra; //frame
  int wid;
  int amp; 
  float ratio; //ratio
  float xPos,yPos; 
  int itr;

  euclidAlgo(){
    margin = 300; //margin
    fra = width - margin; //frame
    initFra = fra;
    wid = 10;
    amp = 1;
    ratio = (float)amp/wid; //ratio
    xPos = 0;
    yPos = 0;
    itr = 0;
  }
  
  void update(int vol){
    translate(margin/2,margin/2);
    stroke(255);
    strokeWeight(2);
    smooth();
    noFill();  
    wid = 10;
    amp = vol+1;
    println(wid,amp);
    ratio = (float)amp/wid;
 
    while(fra>0.1){
      itr++;
      if(itr%2 == 1){
        while(xPos + fra*ratio < initFra+0.1){
          divRect(xPos,yPos, fra*ratio);
          xPos += fra*ratio;
        }
        fra = initFra - xPos;  
      }else{
        while(yPos + fra/ratio < initFra+0.1){
          divRect(xPos,yPos, fra);
          yPos += fra/ratio;
        }
        fra = initFra - yPos;
      }
    }
    //init
    fra = width - margin;
    xPos = 0;
    yPos = 0;
    itr = 0;
  }
  
  void divRect(float xPos, float yPos, float fra){
    int itrDs = 0;
    float xEndPos = xPos + fra;
    float yEndPos = yPos + fra/ratio;
    while(fra > 0.1){
      itrDs++;
      if(itrDs%2 == 0){
        while(xPos + fra < xEndPos+0.1){
          rect(xPos,yPos, fra,fra);  
          xPos += fra;
        }
        fra = xEndPos - xPos;
      }else{
        while(yPos + fra < yEndPos+0.1){
          rect(xPos,yPos, fra,fra);
          yPos += fra;
        }
        fra = yEndPos - yPos;
      }
    }
    itrDs = 0;
  }
}

ーーーーー
Processing / Soundライブラリーの仕様は、下記ドキュメントにて参照ください。
Please refer to the following document for Sound library specifications.
Processing-Sound library documentation
ーーーーー

Sample

ジェネラティブアート おすすめの本

mathmade-processing_gizyu-image

数学から創るジェネラティブアート - Processingで学ぶかたちのデザイン

本書は、数学とプログラミングを組み合わせてクリエイティブなアートを生み出す方法に焦点を当てた書籍です。Processing言語を使用し、読者を数学的なアプローチを通じて美しいデザインの作成にを紹介します。

数学の概念を具体的なコードと視覚的な表現と結びつけて説明し、数学が苦手な読者でも理解しやすく、手を動かしながら学ぶことができる構成になっています。段階的に難易度を上げながら、芸術的なコードを書くスキルを身につけることができます。

また、豊富なサンプルコードや具体的なプロジェクト例を通じて、理論を実践に落とし込む手助けとなります。デザインやアートに興味がある人、プログラミングを通じてクリエイティブな表現を追求したい人にとって、この書籍は理論と実践を結びつけ、新しいアートの可能性を広げる手助けとなることでしょう。

ーーーーー
► 数学から創るジェネラティブアート - Processingで学ぶかたちのデザイン
初版/ 2019.4.17
ページ数/304ページ
出版社/技術評論社
言語/日本語
ーーーーー