2
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

glslでフィボナッチ数列

Posted at

概要

glslでフィボナッチ数列を作る

フィボナッチ数列のアルゴリズムは山ほどありますが、
https://qiita.com/rana_kualu/items/49a60a4076e63ac6e399
現在は最適化された一般項があるのでそれを使います。

wikipediaより

const float SQRT_5 = sqrt(5.);
const float PHY    = (1.+SQRT_5)*.5;

float fib(float n){return sign(n)*floor(pow(PHY,abs(n))/SQRT_5+.5);}

※ wikipediaの負数対応は微妙だったので、最適化してます。

フィボナッチ数列で円形グラデーション

美しい!
image.png

precision mediump float;
uniform vec2  m;       // mouse
uniform float t;       // time
uniform vec2  r;       // resolution
uniform sampler2D smp; // prev scene

const float SQRT_5 = sqrt(5.);
const float PHY    = (1.+SQRT_5)*.5;

float fib(float n){return sign(n)*floor(pow(PHY,abs(n))/SQRT_5+.5);}

void main(void){
	vec2 p = (gl_FragCoord.xy * 2.0 - r) / min(r.x, r.y);
	float c = fib(length(p)*15.)/600.;
	gl_FragColor = vec4(vec3(c), 1.0);
}

グロウしてもいいですね

image.png

precision mediump float;
uniform vec2  m;       // mouse
uniform float t;       // time
uniform vec2  r;       // resolution
uniform sampler2D smp; // prev scene

const float SQRT_5 = sqrt(5.);
const float PHY    = (1.+SQRT_5)*.5;

float fib(float n){return sign(n)*floor(pow(PHY,abs(n))/SQRT_5+.5);}

void main(void){
	vec2 p = (gl_FragCoord.xy * 2.0 - r) / min(r.x, r.y);
	float c = fib(length(p)*15.)/600.;
	gl_FragColor = vec4(vec3(.1/c), 1.0);
}

関連

2
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?