![]() |
Матрица статей Список статей Всячина Контакты | ||||||||||||
|
Фрактальные вихри
Для построения подобных фрактальных вихрей удобно использовать системы итерируемых функций. Рассмотрим следующую систему итерируемых функций, записанную в комплексной форме:
Воспользуемся рандомизированным алгоритмом, для этого нужны вероятности Ниже приведён фрагмент программы на java, реализующей данный алгоритм.
public Image createImage()
{
BufferedImage image = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB);
Graphics graphics = image.getGraphics();
graphics.setColor(Color.WHITE);
graphics.fillRect(0, 0, size.width, size.height);
AffineTransform resultTransform = new AffineTransform();
resultTransform.concatenate(getTransform());
Complex z = start;
for (int n = 0; n < count; ++n)
{
z = map.map(z);
if (n < BEGIN)
continue;
Point2D point = resultTransform.transform(
new Point2D.Double(z.getReal(), z.getImag()), null);
if ((point.getX() < 0) ||
(point.getX() > size.width - 1) ||
(point.getY() < 0) ||
(point.getY() > size.height - 1))
continue;
image.setRGB((int)point.getX(), (int)point.getY(), color.getRGB());
}
return image;
}
class Whirl implements Painter.Map
{
public Whirl(int n, double phi, double r, double R)
{
this.n = n;
this.phi = phi;
this.r = r;
this.R = R;
}
public Complex map(Complex z)
{
double D = R * R + n * r * r;
double p = Math.random();
if (p <= R * R / D)
return z.mul(R).rotate(phi);
int k = (int)(D * (p - R * R / D) / (r * r));
return z.mul(r).add(1).rotate(2 * Math.PI * k / n);
}
private final int n;
private final double phi;
private final double r;
private final double R;
}
Скачать: Смотрите также: |