(一)基本思想:
基本思路:通过三角函数计算,给出初始值并不断循环迭代,将得到的点绘制出来,得到特殊图形;
需要用到的函数:sin(x),cos(x);
(二)迭代的具体实现
参数的设置:double temp_x,double temp_y,
double a,b,c,d;
在for循环中建立三角函数:通过在函数中计算并循环迭代,实现图形的绘制
for(int i=0;i<20000;i++)
{
double tempx=Math.sin(a*temp_y)-Math.cos(b*temp_x);
double tempy=Math.sin(c*temp_x)-Math.cos(d*temp_y); //函数计算初值
int x=(int)(tempx*100+100);
int y=(int)(tempy*100+100); //获取点的坐标
g.setColor(0,0,200);
g.drawLine(x,y,x,y); //画点
tempx=temp_x;
tempy=temp_y; //交换函数
}
(三)图形的绘制
其上代码所得到的图形如下,其中参数为:
a=1.641; b=1.902;
c=0.316; d=1.525;
temp_x=8.7;temp_y=5.2;
(四)拓展
随机数实现:
import java.util.Random;
Random random = new Random ();
int num = random.nextInt (200)-100;
其中,如果要选择概率:
int a=new int[100];
Random random=new Random();
for(int i=0;i<90;i++)
{
int a[i]=random(90);
}
for(int i=0;i<10;i++)
{
int a[i]=random(100)-10;
} //取不同的概率数字
-如果改变a,b,c,d的数值和函数,可以得到不同的图形,例如:
a=0.970; b=-1.899;
c=1.381; d=-1.506;
还可以通过改变函数来是实现图形的变化:
double tempx=Math.sin(a*temp_y)+c*Math.cos(a*temp_x);
double tempy=Math.sin(b*temp_x)+d*Math.cos(b*temp_y);
a=-1.8;
b=-2.0;
c=-0.5;
d=-0.9;