当前位置:网站首页>迭代分形图形的绘制
迭代分形图形的绘制
2022-07-13 17:59:00 【柠ning】
第一步操作永远都是创建一个界面
public class DrawUI extends JFrame {
public void initUI(){
this.setTitle("通过迭代画图");
this.setSize(800,800);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
this.setVisible(true);
}
}创建的类通过继承自JFrame类,可以直接调用父类的方法,无需创建窗体对象。
接下来重写父类中的方法paint
在这个方法内调用绘制图形的方法(DrawPicture),该方法在下文会有写,调用这个方法就可以将方法内的图形画出来,我们也可以选择在paint方法内写,直接显示。
在这里是创建一个方法,通过调用来显示
public void paint(Graphics g)//重绘图形
{
super.paint(g);
DrawPicture(g);
}在窗体上绘制分形图形(是以数学函数公式为基础的)

上图为公式和参数值
public void DrawPicture(Graphics g){
double x=0d,y=0d;
double a=-1.8,b=-2.0,c=-0.5,d=-0.9;
double nx=Math.sin(a*y)+c*Math.cos(a*x);
double ny=Math.sin(b*x)+d*Math.cos(b*y);
x=nx;
y=ny;
int px=(int)(x*100);
int py=(int)(y*100);
g.fillRect(px+400,py+400,1,1);
}
}效果图:

代码:
public void DrawPicture(Graphics g){
double x=0d,y=0d;
double a=-1.7,b=1.3,c=-0.1,d=-1.2;
for (int i=0;i<10000;i++){
double nx=Math.sin(a*y)+c*Math.cos(a*x);
double ny=Math.sin(b*x)+d*Math.cos(b*y);
x=nx;
y=ny;
int px=(int)(x*100);
int py=(int)(y*100);
g.fillRect(px+400,py+400,1,1);
}
}效果图:

接下来,就直接写代码和效果图了,公式和参数值都在代码中
3.
public void DrawPicture(Graphics g){
double x=0d,y=0d;
double a=1.5,b=-1.8,c=1.6,d=0.9;
for (int i=0;i<10000;i++){
double nx=Math.sin(a*y)+c*Math.cos(a*x);
double ny=Math.sin(b*x)+d*Math.cos(b*y);
x=nx;
y=ny;
int px=(int)(x*100);
int py=(int)(y*100);
g.fillRect(px+400,py+400,1,1);
}
}
效果图:

4.
public void DrawPicture(Graphics g){
double x=0d,y=0d;
double a=1.7,b=1.7,c=0.6,d=1.2;
for (int i=0;i<10000;i++){
double nx=Math.sin(a*y)+c*Math.cos(a*x);
double ny=Math.sin(b*x)+d*Math.cos(b*y);
x=nx;
y=ny;
int px=(int)(x*100);
int py=(int)(y*100);
g.fillRect(px+400,py+400,1,1);
}
}效果图:

5.
public void DrawPicture(Graphics g){
double x=0d,y=0d;
double a=1.7,b=-1.8,c=1.6,d=0.9;
for (int i=0;i<10000;i++){
double nx=Math.sin(a*y)+c*Math.cos(a*x);
double ny=Math.sin(b*x)+d*Math.cos(b*y);
x=nx;
y=ny;
int px=(int)(x*100);
int py=(int)(y*100);
g.fillRect(px+400,py+400,1,1);
}
}效果图:

6.
public void DrawPicture(Graphics g){
double x=0d,y=0d;
double a=1.641,b=1.902,c=0.316,d=1.525;
for (int i=0;i<10000;i++){
double nx=Math.sin(a*y)-Math.cos(b*x);
double ny=Math.sin(c*x)-Math.cos(d*y);
x=nx;
y=ny;
int px=(int)(x*100);
int py=(int)(y*100);
g.fillRect(px+400,py+400,1,1);
}
}效果图:

7.
public void DrawPicture(Graphics g){
double x=0d,y=0d;
double a=0.970,b=-1.899,c=1.381,d=-1.506;
for (int i=0;i<10000;i++){
double nx=Math.sin(a*y)-Math.cos(b*x);
double ny=Math.sin(c*x)-Math.cos(d*y);
x=nx;
y=ny;
int px=(int)(x*100);
int py=(int)(y*100);
g.fillRect(px+400,py+400,1,1);
}
}效果图:

8.
public void DrawPicture(Graphics g){
double x=0d,y=0d;
double a=-1.8,b=-2,c=-0.88,d=1;
for (int i=0;i<10000;i++){
double nx=Math.sin(a*y)-Math.cos(b*x);
double ny=Math.sin(c*x)-Math.cos(d*y);
x=nx;
y=ny;
int px=(int)(x*100);
int py=(int)(y*100);
g.fillRect(px+400,py+400,1,1);
}
}效果图:

9.
public void DrawPicture(Graphics g){
double x=0d,y=0d;
double a=1.40,b=1.56,c=1.40,d=-6.56;
for (int i=0;i<10000;i++){
double nx=d*Math.sin(a*x)-Math.sin(b*y);
double ny=c*Math.cos(a*x)+Math.cos(b*y);
x=nx;
y=ny;
int px=(int)(x*100);
int py=(int)(y*100);
g.fillRect(px+400,py+400,1,1);
}
}效果图:

10.
public void DrawPicture(Graphics g){
double x=0d,y=0d;
double a=0.4,b=1,c=0;
for (int i=0;i<10000;i++){
double nx=y-Math.signum(x)*Math.sqrt(Math.abs(b*x-c));
double ny=a-x;
x=nx;
y=ny;
int px=(int)(x*100);
int py=(int)(y*100);
g.fillRect(px+400,py+400,1,1);
}
}效果图:

11.
public void DrawPicture(Graphics g){
double x=0d,y=0d;
double a=1,b=4,c=60;
for (int i=0;i<10000;i++){
double nx=y-Math.signum(x)*Math.sqrt(Math.abs(b*x-c));
double ny=a-x;
x=nx;
y=ny;
int px=(int)x;
int py=(int)y;
g.fillRect(px+400,py+400,1,1);
}
}效果图:

边栏推荐
- 交易模块开发
- [introduction to go language] 04 go language operator
- [go language introduction] 13 go language interface details
- 数据库黑马笔记DML
- 一盏茶的功夫我学会了JWT单点登录
- RT_ Thread producer and consumer issues
- 小阶段总结
- Chapter 4 stm32+ld3320+syn6288+dht11 realize voice acquisition of temperature and humidity values (Part 2)
- Scope when multiple else if are nested
- [hbuilderx development uniapp] automatic code formatting plug-in installation and configuration
猜你喜欢

Getting started with spark

Three minute markdown -- a quick start to basic grammar

Experience of using voice chip jq8400

Redis is the fastest to get started in history (attach redis on ECs)

Web复习

Stm32-tim3 output PWM signal to drive mg996r steering gear (key control)

Distributed theory
![[introduction to go language] 08 go language array](/img/f6/6e113d9090a0c58a68b2e379e64500.png)
[introduction to go language] 08 go language array

SSM图书管理系统
![[introduction to go language] 14 go language goroutine and channel details](/img/5f/7fef8e5f082f11fe6e29333e622e43.png)
[introduction to go language] 14 go language goroutine and channel details
随机推荐
I learned JWT single sign on with a cup of tea
AMD RDNA 3 Navi 31旗舰GPU据称采用3D V-Cache封装以及最高384MB缓存
Théorie de la distribution
LeetCode 刷题 第七天
[introduction to go language] 12 go language structure (struct) detailed explanation
[Go语言入门] 14 Go语言goroutine和通道详解
How to classify the consumption ability of members?
leetcode-3 无重复字符的最长字串(滑动窗口,unordered_set, st.find(string[i]))
信息安全基础
数据库黑马笔记DML
[introduction to go language] 04 go language operator
vim用法
go语言json解析库jsoniter的使用(替换标准库encoding/json)
[introduction to go language] 07 go language string
Three minute markdown -- a quick start to basic grammar
RT_ Thread critical zone protection
2021-07-31
分布式理论
二叉树中的递归问题
Record: vscode connects to Alibaba cloud via SSH