# 用PolarDB生成“上帝的指纹”

+关注继续查看

## 背景

PS: 如何部署PolarDB开源版, 请参考: 《如何用 PolarDB 证明巴菲特的投资理念》

1、分形公式:

z=z^2+c

z可以是单数、也可以是复数、甚至可以是多维数.

2、复数运算:

(a+bi)(c+di) = (ac-bd)+(ad+bc)i
(a+bi) + (c+di) = (a+c)+(b+d)i
(a+bi) - (c+di) = (a-c)+(b-d)i

3、如何产生"上帝的指纹"?

WITH RECURSIVE t(n, zr, zi, cr, ci) AS (
VALUES (1, 0::float8, 0::float8, 0.1::float8, 0.1::float8)
UNION ALL
SELECT n+1, zr*zr - zi*zi + cr, zr*zi + zi*zr + ci, cr, ci FROM t WHERE n < 100
)
SELECT n,zr,zi FROM t;
do language plpgsql $$declare zr float8 := 0; zi float8 := 0; cr float8 := 0.1; ci float8 := 0.1; tmpr float8; tmpi float8; begin for i in 1..100 loop raise notice '%, %i', zr, zi; tmpr := zr*zr - zi*zi + cr; tmpi := zr*zi + zi*zr + ci; zr := tmpr; zi := tmpi; end loop; raise notice '%, %i', zr, zi; end;$$;
NOTICE:  0, 0i
NOTICE:  0.1, 0.1i
NOTICE:  0.1, 0.12000000000000001i
NOTICE:  0.0956, 0.12400000000000001i
NOTICE:  0.09376336, 0.12370880000000001i
NOTICE:  0.09348770048104961, 0.123198705499136i
NOTICE:  0.0935620291045716, 0.12303512735871254i
NOTICE:  0.09361621072599009, 0.12302283233364109i
NOTICE:  0.09362937763530182, 0.12303386279170858i
NOTICE:  0.093629128962925, 0.1230391680025096i
NOTICE:  0.09362777692760627, 0.12304010025679593i
NOTICE:  0.0936272943412032, 0.1230399421199872i
...

f(z)=z^2+(-0.75+0i)时的Julia集:

4、用PolarDB来生成"上帝的指纹":

do language plpgsql $$declare zr numeric := 0.0; -- z0r zi numeric := 0.0; -- z0i tmpr numeric; tmpi numeric; i int; begin <<label_x>> for x in -300..300 loop -- cr, 表示白布的x轴像素点范围是-300到300 <<label_y>> for y in -200..200 loop -- ci, 表示白布的y轴像素点范围是-200到200 <<label_i>> for k in 1..200 loop -- z的发散速度, i 表示颜色深度; 最多迭代200次, 200次就是黑色, 1次可能就接近白色. tmpr := zr*zr - zi*zi + x::numeric/300.0::numeric; tmpi := zr*zi + zi*zr + y::numeric/200.0::numeric; zr := tmpr; zi := tmpi; i := k; exit label_i when sqrt(zr*zr + zi*zi) > 2; -- z的迭代次数截止于|z|>2, 因为此时z会无限发散. end loop label_i ; raise notice 'cr:%, ci:%, i:%', x, y, i; zr := 0.0; -- z0r zi := 0.0; -- z0i end loop label_y ; end loop label_x ; end;$$;

cr为x坐标,ci为y坐标,i为颜色深度:

NOTICE:  cr:-300, ci:-200, i:3
NOTICE:  cr:-300, ci:-199, i:3
NOTICE:  cr:-300, ci:-198, i:3
NOTICE:  cr:-300, ci:-197, i:3
NOTICE:  cr:-300, ci:-196, i:3
NOTICE:  cr:-300, ci:-195, i:3
NOTICE:  cr:-300, ci:-194, i:3
NOTICE:  cr:-300, ci:-193, i:3
NOTICE:  cr:-300, ci:-192, i:3
NOTICE:  cr:-300, ci:-191, i:3
NOTICE:  cr:-300, ci:-190, i:3
NOTICE:  cr:-300, ci:-189, i:3
NOTICE:  cr:-300, ci:-188, i:3
NOTICE:  cr:-300, ci:-187, i:3
NOTICE:  cr:-300, ci:-186, i:3
NOTICE:  cr:-300, ci:-185, i:3
NOTICE:  cr:-300, ci:-184, i:3
NOTICE:  cr:-300, ci:-183, i:3
NOTICE:  cr:-300, ci:-182, i:3
NOTICE:  cr:-300, ci:-181, i:3
NOTICE:  cr:-300, ci:-180, i:3
NOTICE:  cr:-300, ci:-179, i:3
NOTICE:  cr:-300, ci:-178, i:3
NOTICE:  cr:-300, ci:-177, i:3
NOTICE:  cr:-300, ci:-176, i:3
NOTICE:  cr:-300, ci:-175, i:3
NOTICE:  cr:-300, ci:-174, i:3
NOTICE:  cr:-300, ci:-173, i:3
NOTICE:  cr:-300, ci:-172, i:3
NOTICE:  cr:-300, ci:-171, i:3
NOTICE:  cr:-300, ci:-170, i:3
NOTICE:  cr:-300, ci:-169, i:3
NOTICE:  cr:-300, ci:-168, i:3
NOTICE:  cr:-300, ci:-167, i:3
NOTICE:  cr:-300, ci:-166, i:3
NOTICE:  cr:-300, ci:-165, i:3
NOTICE:  cr:-300, ci:-164, i:3
NOTICE:  cr:-300, ci:-163, i:3
NOTICE:  cr:-300, ci:-162, i:3
NOTICE:  cr:-300, ci:-161, i:3
NOTICE:  cr:-300, ci:-160, i:3
NOTICE:  cr:-300, ci:-159, i:3
NOTICE:  cr:-300, ci:-158, i:3
NOTICE:  cr:-300, ci:-157, i:3
NOTICE:  cr:-300, ci:-156, i:3
NOTICE:  cr:-300, ci:-155, i:3
NOTICE:  cr:-300, ci:-154, i:3
NOTICE:  cr:-300, ci:-153, i:3
NOTICE:  cr:-300, ci:-152, i:3
NOTICE:  cr:-300, ci:-151, i:3
NOTICE:  cr:-300, ci:-150, i:3
NOTICE:  cr:-300, ci:-149, i:3
NOTICE:  cr:-300, ci:-148, i:4
NOTICE:  cr:-300, ci:-147, i:4
NOTICE:  cr:-300, ci:-146, i:4
NOTICE:  cr:-300, ci:-145, i:4
NOTICE:  cr:-300, ci:-144, i:4
NOTICE:  cr:-300, ci:-143, i:4
NOTICE:  cr:-300, ci:-142, i:4
NOTICE:  cr:-300, ci:-141, i:4
NOTICE:  cr:-300, ci:-140, i:4
NOTICE:  cr:-300, ci:-139, i:4
NOTICE:  cr:-300, ci:-138, i:4
NOTICE:  cr:-300, ci:-137, i:4
NOTICE:  cr:-300, ci:-136, i:4
NOTICE:  cr:-300, ci:-135, i:4
NOTICE:  cr:-300, ci:-134, i:4
NOTICE:  cr:-300, ci:-133, i:4
NOTICE:  cr:-300, ci:-132, i:4
NOTICE:  cr:-300, ci:-131, i:4
NOTICE:  cr:-300, ci:-130, i:4
NOTICE:  cr:-300, ci:-129, i:4
NOTICE:  cr:-300, ci:-128, i:4
NOTICE:  cr:-300, ci:-127, i:4
NOTICE:  cr:-300, ci:-126, i:4
NOTICE:  cr:-300, ci:-125, i:4
NOTICE:  cr:-300, ci:-124, i:4
NOTICE:  cr:-300, ci:-123, i:4
NOTICE:  cr:-300, ci:-122, i:4
NOTICE:  cr:-300, ci:-121, i:4
NOTICE:  cr:-300, ci:-120, i:4
NOTICE:  cr:-300, ci:-119, i:5
NOTICE:  cr:-300, ci:-118, i:5
NOTICE:  cr:-300, ci:-117, i:5
NOTICE:  cr:-300, ci:-116, i:5
NOTICE:  cr:-300, ci:-115, i:5
NOTICE:  cr:-300, ci:-114, i:5
NOTICE:  cr:-300, ci:-113, i:5
NOTICE:  cr:-300, ci:-112, i:5
NOTICE:  cr:-300, ci:-111, i:5
NOTICE:  cr:-300, ci:-110, i:5
NOTICE:  cr:-300, ci:-109, i:5
NOTICE:  cr:-300, ci:-108, i:5
NOTICE:  cr:-300, ci:-107, i:5
NOTICE:  cr:-300, ci:-106, i:5
NOTICE:  cr:-300, ci:-105, i:5
NOTICE:  cr:-300, ci:-104, i:5
NOTICE:  cr:-300, ci:-103, i:5
NOTICE:  cr:-300, ci:-102, i:5
NOTICE:  cr:-300, ci:-101, i:5
NOTICE:  cr:-300, ci:-100, i:5
NOTICE:  cr:-300, ci:-99, i:5
NOTICE:  cr:-300, ci:-98, i:5
NOTICE:  cr:-300, ci:-97, i:5
NOTICE:  cr:-300, ci:-96, i:5
NOTICE:  cr:-300, ci:-95, i:5
NOTICE:  cr:-300, ci:-94, i:5
NOTICE:  cr:-300, ci:-93, i:5
NOTICE:  cr:-300, ci:-92, i:5
NOTICE:  cr:-300, ci:-91, i:5
NOTICE:  cr:-300, ci:-90, i:5
NOTICE:  cr:-300, ci:-89, i:5
NOTICE:  cr:-300, ci:-88, i:5
NOTICE:  cr:-300, ci:-87, i:6
NOTICE:  cr:-300, ci:-86, i:6
NOTICE:  cr:-300, ci:-85, i:6
NOTICE:  cr:-300, ci:-84, i:6
NOTICE:  cr:-300, ci:-83, i:6
NOTICE:  cr:-300, ci:-82, i:7
NOTICE:  cr:-300, ci:-81, i:7
NOTICE:  cr:-300, ci:-80, i:7
NOTICE:  cr:-300, ci:-79, i:8
NOTICE:  cr:-300, ci:-78, i:8
NOTICE:  cr:-300, ci:-77, i:8
NOTICE:  cr:-300, ci:-76, i:8
NOTICE:  cr:-300, ci:-75, i:8
NOTICE:  cr:-300, ci:-74, i:9
NOTICE:  cr:-300, ci:-73, i:9
NOTICE:  cr:-300, ci:-72, i:10
NOTICE:  cr:-300, ci:-71, i:10
NOTICE:  cr:-300, ci:-70, i:10
NOTICE:  cr:-300, ci:-69, i:10
NOTICE:  cr:-300, ci:-68, i:11
NOTICE:  cr:-300, ci:-67, i:11
NOTICE:  cr:-300, ci:-66, i:12
NOTICE:  cr:-300, ci:-65, i:13
NOTICE:  cr:-300, ci:-64, i:15
NOTICE:  cr:-300, ci:-63, i:18
NOTICE:  cr:-300, ci:-62, i:23
NOTICE:  cr:-300, ci:-61, i:37
NOTICE:  cr:-300, ci:-60, i:35
NOTICE:  cr:-300, ci:-59, i:34
NOTICE:  cr:-300, ci:-58, i:59
NOTICE:  cr:-300, ci:-57, i:200
NOTICE:  cr:-300, ci:-56, i:200
.....

## 参考

http://www.matrix67.com/blog/archives/4570

http://www.matrix67.com/blog/archives/6231

https://www.cnblogs.com/anderslly/archive/2008/10/10/mandelbrot-set-by-fsharp.html

http://www.matrix67.com/blog/archives/292

https://www.eefocus.com/e/500748

https://zhuanlan.zhihu.com/p/450061289

[原创]springboot整合elasticsearch全文检索入门
[原创]springboot整合elasticsearch全文检索入门
94 0
Springboot 验证码生成和校验，图片格式和base64编码串
Springboot 验证码生成和校验，图片格式和base64编码串
231 0
ElasticSearch的安装以及与springboot的集成
elasticseach简称es，现在用得非常广泛，像百度等一些知名互联网公司都有用到es。那么es到底是什么呢？如何使用呢？下面就一起来学习一下。
128 0
【Spring Boot 快速入门】十九、Spring Boot 集成JWT
【Spring Boot 快速入门】十九、Spring Boot 集成JWT
440 0
【Spring Boot 快速入门】十三、Spring Boot集成Elasticsearch
【Spring Boot 快速入门】十三、Spring Boot集成Elasticsearch
127 0
.Net异步编程详解入门
565 0

958 0
+关注