📰 newsreader

hackernews score 0.38 好み 0.00 en

パーリンノイズ・フィールドを活用したクリエイティブな表現

原題: Getting Creative with Perlin Noise Fields

perlin noisegenerative artflow fieldsprocessingprocedural generationvector fieldsparticle simulationcreative coding
原文 ↗

日本語訳

# パーリンノイズ・フィールドによるクリエイティブな表現

**要約:** パーリン・フロー・フィールドというシンプルなジェネレーティブ・アルゴリズムのみを使用して、25種類の異なるデザインを作成しました。結果は下にスクロールしてご覧ください。

この記事で使用されているすべてのProcessingコード、および画像とアニメーションGIFは、GitHubで公開しています。

博士課程の研究から離れてリラックスしたい隙間時間に、ジェネレーティブ・アートを作るのが私の趣味です。シンプルなアルゴリズムを使って、短時間で興味深い画像が生成される様子を見ることは、成果が出るまでに数ヶ月、あるいは数年もかかる学術的な研究とは対照的で、気分転換になります。

去年の12月の退屈な週末、私は自分自身に楽しい挑戦を課すことにしました。それは、「シンプルなジェネレーティブ・プロセスを一つ選び、利用可能なさまざまなパラメータを調整するだけで、できるだけ多くのバリエーションを作ってみる」というものです。

選んだアルゴリズムは、パーリンノイズ・フィールドです。これは、パーリンノイズによって作成されたシンプルな力場(フォース・フィールド)に基づき、キャンバス上のパーティクルを移動させるものです。アイデアを素早く形にするために、Processingでいくつかのシンプルなクラスを作成し、作業を開始しました。

この記事では、私が作り上げたものと、そこから得られた教訓について詳しく説明します。特に、この挑戦は「自らに課した制約の中で、いかに能動的に創造性を実践するか」を理解する上で非常に役立ちました。

### パーリンノイズ・フィールド:概要

パーリンノイズ・フィールドの考え方は非常にシンプルです。(注:パーリン・フロー・フィールドやベクトル場と呼ばれることもあります)

キャンバスを2次元の力場と考えてみてください。キャンバス上の各点には、パーティクルをそらす「力」の方向が割り当てられています。

例えば、キャンバス上のすべての点にランダムな力の方向を割り当てると、次のような結果になります。

ここで、ランダムさに有機的な質感を与えるために、力の方向を決定する際にパーリンノイズを使用します。Adrian Biagioli氏による、パーリンノイズの仕組みを詳細に解説した素晴らしい記事があります。パーリンノイズを使用すると、次のような結果が得られます。

見ての通り、ランダム版の唐突な変化に比べ、方向が非常に滑らかになっています。

これが準備できたら、次のステップは、キャンバスにパーティクルを放出し、基礎となる力の影響を受けた動きをシミュレートすることです。

これだけです! 先に述べた通り、非常にシンプルです。

今回の演習では、コードをより整理しやすくするために、いくつかの基本的なクラスを追加しました。主に、パーティクルの集合を定義できるようにしたかったのです。各集合には1つ以上のパーティクルが含まれ、独自の描画関数に関連付けられています。また、パーティクル集合をレイヤー化するためのクラスも実装しました。これにより、一連のレイヤーをキャンバスに順番に描画し、特定のレイヤーに割り当てられたすべてのパーティクル集合が一定ステップのシミュレーションを完了した時点で、次のレイヤーへ進むという仕組みを作ることができました。

### イテレーション(試行)

下の画像をクリックすると、プロセスのアニメーションを見ることができます。警告:モバイルデータ通信で閲覧している場合、一部のGIFはかなりサイズが大きいです!

まずは、最も手近なものから始めました。白い背景に、不透明度の低い黒いパーティクルを多数配置すると、次のような結果になります。パーティクルが集まる領域が暗くなります。

**Iteration 1**

好奇心から、色を反転させてみることにしました。黒い背景に、さまざまな太さの白い筋を描きます。結果はより面白くなり、奥行き感が強まりました。

**Iteration 2**

その奥行き感を活かして、色を取り入れることにしました。紫色のパレットを自ら選び、暗い色から明るい色へと、複数のパーティクル集合をレイヤー化しました。結果は予想外に美しいものでした!

**Iteration 3**

予想外なことに、わずか3つのバリエーションを作っただけで、次にどう進めるべきかアイデアが尽きたように感じてしまいました。その考えは一旦脇に置き、線の太さを変えたり、パーティクルの不透明度を非常に低く(1%)したりして遊んでみました。結果は非常に満足のいくもので、グレーの色がどこからともなく現れたかのように見えました!

**Iteration 4**

線のパラメータをいろいろと弄っている最中、完全に偶然ですが、線のストロークの端(キャップ)をデフォルトの丸型から角型に変更してみました。驚いたことに、それによって画像に全く新しいテクスチャが加わり、まるで粗い紙に描かれた木炭画のようになりました。

色を入れたいと考え、プロシージャルに心地よい色のセットを生成する方法を探し始めました。そこで、色の生成に関する素晴らしい記事を見つけ、そこに記載されていた黄金比カラージェネレーターを使用しました。これもまた、素晴らしい結果となりました!

**Iteration el**

プロシージャルな色はそのままに、他の形状を試してみることにしました。線を引く代わりに、弧(アーク)を描くように変更しました。これもまた、結果は全く異なるものになりました!

**Iteration 6**

黄金比に基づいたカラージェネレーターがHSB(またはHSL)色空間を使用していることに気づき、それを少し弄ってみることにしました。好みの色相(Hue)を選び、彩度(Saturation)と明度(Lightness)にランダムな値を割り当てた結果、これができました。

**Iteration 7**

次に、パーティクルの寿命に基づいて彩度の値を変化させることにしました。画面上で展開される様子を見たとき、その効果には驚かされました。色がフルサチュレーションから白へと変化しながら幅が狭まり、美しい炎のような形を作り出したのです!

**Iteration 8**

なぜか、突然『ライオン・キング』のハイエナの巣にある緑色の雲を思い出しました。

奇妙な結びつきですが、楽しみとして少し追求してみることにしました。レイヤー化を少し加えることで、納得のいくものが出来上がりました。

**Iteration 9**

この時点で、少しパニックになり始めました。アイデアが尽きかけているようで、ほとんどのバリエーションに目新しさがありませんでした。当初の目標である25種類に、一体どうやって到達すればいいのでしょうか? 再び、そのような考えは脇に置いて、構図の観点から考えることにしました。一度シンプルなグレースケールに戻り、まず興味深い背景を作り、その上に細かいディテールをレイヤー化することにしました。

**Iteration 10**

この時点で、より劇的に変化させることにしました。描画の前に移動と回転を加えることで、動きの方向に対して垂直な線を引くことにしました。ロジックのミスにより、結果として「霧の中に小さな明瞭な斑点がある」という、幸運な偶然が生まれました!

**Iteration 11**

これらの探索中に発見された画像の、儚い性質には何か美しいものがあります。ここに、以前破棄して保存していたバージョンがあります。しかし、今見返すと、気に入っている自分に気づきます。残念なことに、これを生成するための正確なコードは、復元する簡単な方法もなく永遠に失われてしまいました。皮肉なことに、この画像が最も貴重なものとなっています!

この時点で、再びアイデアが尽きていると感じましたが、方針は変えませんでした。円を描くことにしましたが、エッジがゆらゆらと揺れるカスタムスタイルにしました。ここでも、コードのバグによって、次のような画像という幸運な発見につながりました!

**Iteration 12**

これを見て、もっと暗くすれば星空のような感じが出せるのではないかと考えました。そこで、そのような方向性を試してみました。同じ基本的なアルゴリズムを使用して、空にいくつかの星と、空を横切る流れ星を加えました。

**Iteration 13**

パーティクルの寿命に合わせて線の太さを変化させた、流れ星の形状が気に入りました。複雑さと密度を出すために、これらの形状の異なるサイズを白い背景にレイヤー化することにしました。結果は、ダルメシアンの毛並みに非常によく似ています!

**Iteration 14**

この基本的な「彗星」の形状を再利用し、尾を長くし、時間の経過とともに不透明度を下げてパーティクルが消えていくようにしました。また、黒と白の筋を交互にレイヤー化することで、画像内のさまざまなグレーレベルに大きな変化をもたらしました。結果は非常に滑らかで有機的でした!

**Iteration 15**

そこに色を加えることにしました。明るいサンギーネ(赤土色)で描かれたチョーク画のような質感を目指しました。これもまた、小さくランダムなインスピレーションから得られたものですが、良い結果となりました!

**Iteration 16**

宇宙のような画像に戻り、星空のエフェクトがとても気に入ったので、宇宙の星雲のような見た目を試してみることにしました。しかし、結果として出来上がったのは、怒ったような...

原文(英語)を表示

Getting Creative with Perlin Noise Fields

TL;DR: I made twenty five different designs using only Perlin flow fields, a simple generative algorithm. Scroll down to see the results.

All Processing code for this article, along with images and animated GIFs, can be found on Github

In little gaps of time when I’m trying to unwind from my PhD work, I have a hobby of making generative art. Seeing interesting images appear within a short time using simple algorithms provides a refreshing change from my academic work where one ends up working for months or years on a project before seeing any success.

On a boring weekend in December last year, I decided to set myself a fun challenge: pick a simple generative process to simulate and attempt to make as many different variations as I can by just playing with the various available parameters.

The algorithm I picked was perlin noise fields, the movement of particles on a canvas based on a simple force field created using Perlin noise. I built a handful of simple classes in Processing to help me quickly iterate on ideas and I was off.

This post details what I came up with along with some lessons learnt. In particular, this challenge has been helpful in understanding how to actively practice creativity using self-imposed constraints.

Perlin Noise Fields: A Brief Overview

The idea behind Perlin noise fields is quite simple. (Note: they are sometimes referred to as perlin flow fields or vector fields)

Think of the canvas as a two-dimensional force field. Each point on the canvas is assigned a direction in which it’s “force” redirects particles.

So for example, by assigning random directions of force for every point on the canvas, we might end up with the following.

Now, to give a more organic feel to the randomness, Perlin noise is used instead in determining the directions of forces. Adrian Biagioli has a great writeup explaining how Perlin noise works in detail. Using Perlin noise, what we end up with is something along these lines.

As you can see, the directions have a much smoother feel compared to jarring changes in the random version.

With this in place, the next step is to release some particles onto the canvas and simulate their movement as effected by the underlying forces.

That’s it! Like I said, it’s pretty simple.

For this exercise, I added some basic classes to help me organize the code better. Primarily, I wanted to be able to define particle sets, each containing one or more particles and associated with a custom drawing function. I also implemented classes to help me layer particle sets. That way I can have a sequence of layers which are drawn on the canvas one after the other, and a layer is finished only when all particle sets assigned to a given layer have been simulated a certain number of steps.

The Iterations

Click on the images below to see an animation of the process. WARNING: in case you’re viewing this on your mobile data, some of the GIFs are fairly large!

I first started with the low hanging fruit. A white background with many low-opacity black particles results in the following, where the areas attracting more particles end up being darker.

Iteration 1

Just out of curiosity, I decided to flip the colors; a black background with white streaks of different thicknesses across it. The result was more interesting with a greater sense of depth.

Iteration 2

Going off that sense of depth, I decided to throw in some colors. Hand-picking a palette of purples, I layered multiple sets of particles, going from darker to lighter. The result was unexpectedly beautiful!

Iteration 3

Unexpectedly, just after three variations, I already felt like I was out of ideas on where to take things next. I put aside the thought and played around with varying the line thickness and used a very low opacity (1%) for the particles. The result was quite pleasing, with the gray color almost appearing out of nowhere!

Iteration 4

While playing around with the different line parameters, completely by chance, I happened to change the stroke cap for the lines to square instead of the default round one. To my surprise, it introduced a whole new texture to the image, like a charcoal pencil on rough paper.

I wanted to get some color in there and so I started looking for a way to procedurally generate a pleasing set of colors. I ended up finding this great article on generating colors, and used the golden ratio color generator described there. Again, the result was spectacular!

Iteration 5

I decided to keep the procedural colors and decided to explore other shapes; instead of drawing lines, I switched to drawing arcs instead. Again, the result is completely different!

Iteration 6

I noticed that the golden-ratio based color generator was using the HSB (or HSL) color space and decided to play with that a bit. I picked a hue that I liked and picked random saturation and lightness values and ended up with this.

Iteration 7

Next I decided to vary the saturation value based on the lifetime of the particle. The resulting effect took me by surprise as I watched it unfurl on the screen. The color went from full saturation to white while reducing in width, creating these beautiful flames!

Iteration 8

For some reason, it suddenly reminded me of the green clouds in the hyena’s den from Lion King.

An odd connection which I decided to pursue a little for fun! With a bit of layering, I was quite happy with what emerged.

Iteration 9

At this point, I began to panic a little. I seemed to be running out of ideas and most of my variations weren’t very novel. How was I ever going to get to my initial target of twenty five? Again, putting aside such thoughts, I decided to think in terms of composition. I decided to back off to simple grayscale, build an interesting background first, and layer fine details over it.

Iteration 10

At this point I decided to change things up more drastically. I decided to draw lines perpendicular to the direction of motion using some translation and rotation prior to drawing. Due to some broken logic, I ended up with a happy accident; a haze with little blotches of clarity!

Iteration 11

There is something beautiful about the ephemeral nature of the images discovered during these explorations. Here’s a version I found saved, which I had discarded. However, looking at it now, I find myself liking it. Unfortunately, the exact code for generating it has been lost forever with no easy way to recover it, making this image, ironically, the most precious one!

At this point, I again found myself running out of ideas but I stayed the course. I decided to draw circles, but a custom style that had wobbly edges. Again some bug in my code led me to a happy discovery of the following image!

Iteration 12

Looking at it, I thought I could make it darker and achieve the feel of a starry sky. So I tried to make something along those lines. I threw in some stars in the sky and some shooting stars streaking across the sky, all using the same basic algorithm.

Iteration 13

I liked the shape of the shooting star where I varied the thickness of the line over the lifetime of the particle. I decided to layer different sizes of these shapes onto a white background to bring about a sense of complexity and busy-ness. The result reminds me very much of the fur on a Dalmatian!

Iteration 14

I decided to re-use this basic “comet” shape and make the tails longer while lowering the opacity over time so that particles fade away. I also did this in alternating layers of black and white streaks to get a lot of variation in the different gray levels in the image. The result was super smooth and organic!

Iteration 15

I decided to add some color in there. I tried to get the feel of a chalk drawing done with a light sanguine color. Again, small and random inspiration, but nice results!

Iteration 16

Going back to the space-like image, I really liked the starry effect and decided to try and do the look of some kind of nebula in space. Instead I ended up with an angry swarm of some kind of space aliens from Star Trek. I love how “failure” can suddenly turn into success! All you have to do is define failure differently, in this case as stagnation or a lack of progress!

Iteration 17 Iteration 18

The little elements in there kind of looked like leaves so I deliberately tried doing a scene of autumn leaves on the ground. Again, reusing the background from the space scene, and playing with different colors and layers, I got to this.

Iteration 19

One aspect I had not played with at all was the scale of the Perlin noise. Varying this, one can go from small scribbles to long sweeping lines as the force lines become more or less detailed. I simply drew ten layers with each one’s hue (in HSB space) mapped evenly along the color range.

Iteration 20

I didn’t particularly like the details on this one so I decided not to play with the noise levels anymore. Instead I chose to draw some text, just a big ‘X’, as the particle moved. Along with some layering and choice of color, I ended up with this. Just a whole lot of X’s!

Iteration 21

At this point I remembered an old program I had seen over at OpenProcessing on simulating water color and decided to implement a similar drawing style for my particles. (Note: the animated GIF in this case is not that good due to the limited color palette.)

Iteration 22

I also tried varying the scale of the force. This meant that particles jumped a larger distance each frame, and instead of drawing lines, I just drew small circles at the new locations to end up with this.

Iteration 23

At this point I was really running out of novel ideas but I had just two more to go. I decided to try a different shape; I drew rectangles with some variation in their size and color. To me the result feels like paint over a rough canvas.

Iteration 24

Finally, for the last one, I decided to draw triangles. Every time a particle moved from an old position to a new position, I would use those as the first two points of triangle. I would additionally pick a point somewhere between them displaced vertically, and use that as a third point for a triangle. With some layering of colors, the result was quite intense!

Iteration 25

Phew!

Why?

Why bother doing all this? It’s fun! While personally, that’s enough for me, I want to add some concluding thoughts on the exercise.

Initially, it was surprisingly difficult to come up with new ways to work within my self-imposed constraints. However, by the end of the exercise, I can confidently point at countless potential variations using what I learnt building the above designs. The more you do, the more ways forward you’ll see.

If you had told me at the beginning that I’d come up designs like Iteration 25, I would have scoffed. However, just sitting down and working on something, anything, even as simple as the first few designs above, gets your brain going. After a while, I started picking up and applying higher-level, re-usable building blocks (e.g., the color-generation algorithm, the dark, space-like background). So if you see some complex work and wonder how in the world the creators came up with it, they probably didn’t do it in one swoop. They probably iterated from something much simpler to reach that level of complexity over time. Creativity is a process, not a state of mind.

Constraints help. Trying to be creative without constraints, among endless potential possibilities, is like wandering aimlessly through a vast desert while looking for an oasis. Trying to be creative within strict constraints is akin to walking through a thick forest by picking one of a handful of paths revealed in front of you.

Finally, you’ll notice from my commentary that many times along the way my mind would surface all kinds of doubts and discouraging thoughts. I had to actively fight to suppress those thoughts as they came up to continue making progress.

So stop “waiting for motivation” or “for inspiration to strike” and get to work.

← 一覧に戻る