c++ - 这个分形的逻辑是什么?

标签 c++ logic

<分区>

我正在为学校做一个项目,需要粗略地重现这个分形(在 BGI 中):

enter image description here

我一直在尝试为中等大小的三角形寻找放置逻辑,因为必须将它们绘制到 for/while 循环中。 (我画了主三角形,在它的每一边画了一个圆圈。)

欢迎任何想法!

最佳答案

绝对是 IFS。 IFS 分形使用递归。它就像一个树结构,每个分支都可以有侧分支,这些分支又可以有自己的更小的侧分支。在(C-like)伪代码中,它看起来像:

draw_triangle(vector2d pos, float scale, int depth)
{
  if (depth < MAX_DEPTH) return;

  /* actual graphics code for the triangle goes here.. use pos and scale */

  /* compute center positions for circles side1_pos, side2_pos, etc... */

  draw_circle(side1_pos, 0.5*scale, depth+1);
  draw_circle(side2_pos, 0.5*scale, depth+1);
  draw_circle(side3_pos, 0.5*scale, depth+1);
}

draw_circle(vector2d pos, float scale, int depth)
{
  if (depth < MAX_DEPTH) return;
  /* actual graphics code for the circle goes here.. use pos and scale */

  /* compute center positions for triangles side1_pos, side2_pos, etc... */

  draw_triangle(side1_pos, 0.5*scale, depth+1);
  draw_triangle(side2_pos, 0.5*scale, depth+1);
  draw_triangle(side3_pos, 0.5*scale, depth+1);
}

关于c++ - 这个分形的逻辑是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15631697/

相关文章:

c++ - 更改项目以运行 VS2012 C++

java - jdk-13.0.2因为logisim导调用脑不可见

java - 如何避免同步和对象创建?

c++ - 初始化 const boost multi_array

c++ - 通过抽象类将参数传递给祖父类的构造函数

c++ - C++ 中的 fork() 学习操作系统开发

javascript - 如何创建自定义 JSON 数据结构?

javascript - 使用 Canvas Logic 在三 Angular 形中获得 180 度

php - 使用 PHP 创建交互式产品选择器

c++ - 逆离散傅里叶变换输出图像