用
julia set
和mandelbrot set
实现
效果预览
主要代码
float real = (v_uv0.x-0.5)/zoom + offset.x;
float image = (v_uv0.y-0.5)/zoom + offset.y;
float r2 = 0.0;
float conut = 0.0;
for(float i = 0.0; i < 9999.0; i++){
float tmp_real = real;
// 计算新的复数-实数部分
// f(n+1) = f(n)*f(n) + c
// (a+bi)*(a+bi) + c = a*a - b*b + (2*a*b)i + c_real + (c_image)i
real = (tmp_real*tmp_real) - (image*image) + c_real;
// 虚数部分
image = 2.0*tmp_real*image + c_image;
// 复数大小的平方
r2 = real*real + image*image;
conut = i;
if(r2 >= 4.0){
break;
}
}
if(r2 < 4.0){
o = v_color;
}else{
o = vec4(mix(outColor1.rgb, outColor2.rgb, fract(conut*0.07)), 1);
}
更多精彩
欢迎关注【白玉无冰】公众号~