之前在网上看到《不可思议的分形几何》视频,我对视频中的巴恩斯利蕨感兴趣,所以自己就上手用代码实现了。
巴恩斯利蕨数学公式
巴恩斯利蕨数学公式看原视频截图:
巴恩斯利蕨源码实现:
package lyc.spring.fractal;
import javax.swing.*;
import java.awt.*;
import java.util.HashMap;
import java.util.Map;
/**
* 巴恩斯利蕨
*/
public class BarnsleyFern extends JApplet {
// 画板
Image image = null;
// 绘图
Graphics graphics = null;
// 画板的尺寸
int width = 1500, height = 1500;
// 图片中心坐标点所在位置
int offsetX = 1000, offsetY = 50;
// 缓存数据
int x2 = 0, y2 = 0;
// 像素数目
int pixelCounts = 200000;
// 图片放大倍数
double magnification = 56;
// 图像翻转
int overturnY = 400;
// 函数出现概率
private static final int f1 = 1, f2 = 85,f3 = 7;
// 定义map的键值对
private static final String X = "x",Y = "y";
// 创建Map容器
Map<String,Double> entry = new HashMap<>(),temp = new HashMap<>();
/**
* 程序入口
*/
public void init(){
image = this.createImage(width, height)