分形初步

分形的总结
首先我想在总结前申明依据,分形是“分形”这两个字而不是“分型”,这两者差别还是比较大的,千万不要乱用。
一、
做分形的感受:这是我第一次做分形,从来没有接触过,突然发现分形真的特别的神奇,原来最简单的重复往往会创造出最耀眼的美丽,
一个点一个点的积累会形成让你我都叹为观止的神奇于美丽,感觉分形很是不可思议 ,这样简单的积累就会得到这么美丽的世界,让我突然认识到:
只要量变达到一定的积累,那么耀眼只是一瞬间的功夫,后面的面的路还长,加油吧,从现在就开始人生的分形吧
1、什么叫分形?
分形,具有以非整数维形式充填空间的形态特征。1973年,曼德布罗特(B.B.Mandelbrot)在法兰西学院讲课时,首次提出了分维
和分形几何的设想。分形(Fractal)一词,是曼德布罗特创造出来的,其原意具有不规则、支离破碎等意义,分形几何学是一门以
不规则几何形态为研究对象的几何学。由于不规则现象在自然界普遍存在,因此分形几何学又被称为描述大自然的几何学。分形几何学建立
以后,很快就引起了各个学科领域的关注。不仅在理论上,而且在实用上分形几何都具有重要价值。
2、画分形图形主要就是函数的问题,只要把相关的参数设置正确,画出图形还是比较简单的,用计算机画分形的最大优点就是可以重复很多次
用量变来展示出质变的美丽。
package Shape;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.print.PrinterGraphics;
import java.util.Random;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class SuprisePitureListener implements ActionListener {
private Graphics g;
private JFrame sp;
//写一个构造方法,传参数
public SuprisePitureListener(Graphics g, JFrame sp) {
// TODO Auto-generated constructor stub
this.g = g;
this.sp = sp;
}
//画出第一个图形
public void actionPerformed(ActionEvent e) {
//清除屏幕上的图形
sp.getGraphics().clearRect(0, 0, 1500, 1500);
if (e.getActionCommand().equals("Picture1")) {
double a = -2;
double b = -2;
double c = -1.2;
double d = 2;
double x = 0;
double y = 0;
double nextx;
double nexty;
int tempx;
int tempy;

for (int j = 0; j < 200000; j++) {
nextx = (Math.sin(a * y) - Math.cos(b * x));
nexty = (Math.sin(c * x) - Math.cos(d * y));
tempx = (int) (x * 100) + 300;
tempy = (int) (y * 100) + 300;
g.setColor(Color.BLACK);
System.out.println(tempx + " " + tempy);
g.drawLine(tempx, tempy, tempx, tempy);
x = nextx;
y = nexty;
}
//让屏幕上的图形延迟一段时间
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
//清除屏幕上的图形
sp.getGraphics().clearRect(0, 0, 1500, 1500);
}
if (e.getActionCommand().equals("Picture2")) {
double a = 1.4;
double b = 1.56;
double c = 1.4;
double d = -6.56;
double x = 0;
double y = 0;
double nextx;
double nexty;
int tempx;
int tempy;

for (int i = 0; i < 50000; i++) {
nextx = (d * Math.sin(a * x) - Math.sin(b * y));
nexty = (c * Math.cos(a * x) - Math.cos(b * y));
tempx = (int) (50 * x) + 400;
tempy = (int) (50 * y) + 400;
g.setColor(Color.BLACK);
g.drawLine(tempx, tempy, tempx, tempy);
x = nextx;
y = nexty;
}
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
sp.getGraphics().clearRect(0, 0, 1500, 1500);
}
if (e.getActionCommand().equals("Picture3")) {
// sp.getContentPane().setBackground(Color.BLACK);


double a = 0.4;
double b = 1;
double c = 0;
double x = 0;
double y = 0;
double nextx;
double nexty;
int tempx;
int tempy;
//sp.setBackground(Color.black);
for (int i = 0; i < 500000; i++) {

nextx = y - Math.signum(x) * Math.sqrt(Math.abs(b * x - c));
nexty = a - x;
tempx = (int) (x * 100) + 300;
tempy = (int) (y * 100) + 300;
g.setColor(Color.BLUE);
g.drawLine(tempx, tempy, tempx, tempy);
x = nextx;
y = nexty;

}

try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
sp.getGraphics().clearRect(0, 0, 1500, 1500);
}
if (e.getActionCommand().equals("Picture4")) {
double a = 1;
double b = 4;
double c = 60;
double x = 0;
double y = 0;
double nextx;
double nexty;
int tempx;
int tempy;
for (int i = 0; i < 50; i++) {
Random rand = new Random();
int count1 = rand.nextInt(255);
int count2 = rand.nextInt(255);
int count3 = rand.nextInt(255);
for (int i1 = 0; i1 < 20000; i1++) {
Random rand1 = new Random();
nextx = y - Math.signum(x) * Math.sqrt(Math.abs(b * x - c));
nexty = a - x;
tempx = (int) (x * 1.2) + 450;
tempy = (int) (y * 1.2) + 450;
g.setColor(new Color(count1, count2, count3));
g.drawLine(tempx, tempy, tempx, tempy);
x = nextx;
y = nexty;
System.out.println(tempx + " " + tempy);
}

}
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
sp.getGraphics().clearRect(0, 0, 1500, 1500);
}
if (e.getActionCommand().equals("Picture5")) {
Random rand = new Random();
double a = 0;
double b = 0;
double c = 0;
double d = 0;
double x = 0;
double y = 0;
double nextx;
double nexty;
int tempx;
int tempy;
for (int j = 0; j < 3; j++) {

if (j == 0) {
a = 1.5;
b = -1.8;
c = 1.6;
d = 0.9;

}
if (j == 1) {
a = 1.7;
b = -1.7;
c = 0.06;
d = 1.2;
}
if (j == 2) {
a = -1.4;
b = 1.6;
c = 1.0;
d = 0.7;
}

for (int i = 0; i < 10; i++) {

int count1 = rand.nextInt(255);
int count2 = rand.nextInt(255);
int count3 = rand.nextInt(255);

for (int i1 = 0; i1 < 5000; i1++) {
nextx = (Math.sin(a * y) + c * Math.cos(a * x));
nexty = (Math.sin(b * x) - d * Math.cos(b * y));
tempx = (int) (100 * x) + 400;
tempy = (int) (100 * y) + 400;
g.setColor(new Color(count1, count2, count3));
g.setColor(Color.BLACK);
g.drawLine(tempx, tempy, tempx, tempy);
x = nextx;
y = nexty;

}

}
System.out.println(a);
try {
Thread.sleep(1000);
} catch (InterruptedException e2) {
e2.printStackTrace();
}
sp.getGraphics().clearRect(0, 0, 1500, 1500);
}
}
}
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值