Drawing fractals is more of an algorithm issue; that is, you need to have a recursive algorithm to get the triangles at some "depth" level. You can find algorithms on the net by searching with parameters lke Sierpinski triangle algorithm.
There is one such example and algorith at the link below with python turtle:
http://interactivepython.org/runestone/static/pythonds/Recursion/pythondsSierpinskiTriangle.htmlYou can adapt that code to vpython like:
from vpython import *
def drawTriangle(points,color):
curve(pos=[points[0].pos,points[1].pos], color=color)
curve(pos=[points[1].pos,points[2].pos], color=color)
curve(pos=[points[2].pos,points[0].pos], color=color)
triangle(vs=[points[0], points[1], points[2]])
def getMid(p1, p2, color):
return vertex(pos=(p1.pos+p2.pos) /2.0, color=color)
colormap = [color.blue, color.red, color.green, color.white, color.yellow, color.magenta, color.orange]
def sierpinski(points,degree):
drawTriangle(points,colormap[degree])
if degree > 0:
sierpinski([points[0], getMid(points[0], points[1], colormap[degree]), getMid(points[0], points[2], colormap[degree])], degree-1)
sierpinski([points[1], getMid(points[0], points[1], colormap[degree]), getMid(points[1], points[2], colormap[degree])], degree-1)
sierpinski([points[2], getMid(points[2], points[1], colormap[degree]), getMid(points[0], points[2], colormap[degree])], degree-1)
myPoints = [vertex(pos=vec(-100,-50,0), color=colormap[0]),vertex(pos=vec(0,100,0), color=colormap[0]),vertex(pos=vec(100,-50,0), color=colormap[0])]
sierpinski(myPoints,3)
should give you a similar triangle fractal at depth level 3. Changing depth level, you can get more number of sub triangles.
16 Nisan 2018 Pazartesi 23:51:33 UTC+3 tarihinde BRCamy yazdı: