<分区>
我正在为学校做一个项目,需要粗略地重现这个分形(在 BGI 中):
我一直在尝试为中等大小的三角形寻找放置逻辑,因为必须将它们绘制到 for/while 循环中。 (我画了主三角形,在它的每一边画了一个圆圈。)
欢迎任何想法!
<分区>
我正在为学校做一个项目,需要粗略地重现这个分形(在 BGI 中):
我一直在尝试为中等大小的三角形寻找放置逻辑,因为必须将它们绘制到 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/