Hier mal ein kleines Programm, welches das Sierpinskie Dreieck beliebiger Iteration auf dem Blidschirm ausgibt.
Man sollte es mit den Iterationen allerdings nicht übertreiben, weil bei jeder Iteration neue Dreiecke entstehen
und so bei hoher Iterationszahl massig Speicher belegt wird (temporär).
Das Programm folgt dem IFS beschrieben auf folgender Seite:
http://ecademy.agnesscott.edu/...iertri.htm
Viel Spaß damit
BlitzBasic: [AUSKLAPPEN] [EINKLAPPEN] Type Triangle Field point1[1] Field point2[1] Field point3[1] End Type
Type TriangleList Field tri.Triangle Field it End Type
Const SIDE = 400
Local tri.Triangle = New Triangle tri\point2[0] = SIDE tri\point3[0] = SIDE/2 tri\point3[1] = -(Sin(60)*Float(SIDE))
Local triList.TriangleList = New TriangleList triList\tri = tri
AppTitle "Sierpinski Dreieck"
Local it = Input("Wieviele Iterationen?: "), tempTri.TriangleList, i, j
If it > 0 Then For i = 0 To it - 1 For triList = Each TriangleList If triList\it = i Then For j = 0 To 2 tempTri = New TriangleList tempTri\it = i + 1 tempTri\tri = CopyTriangle(triList\tri) Insert tempTri After Last TriangleList If j = 0 Then Transform1(tempTri\tri) If j = 1 Then Transform2(tempTri\tri) If j = 2 Then Transform3(tempTri\tri) Next Delete triList\tri Delete triList Else Exit End If Next Next End If
Delete Each TriangleList
Graphics 800, 600, 16, 2
Local pic = CreateImage(800, 600) SetBuffer ImageBuffer(pic)
For tri = Each Triangle Line tri\point1[0] + (400 - SIDE/2), tri\point1[1] + 400, tri\point2[0] + (400 - SIDE/2), tri\point2[1] + 400 Line tri\point2[0] + (400 - SIDE/2), tri\point2[1] + 400, tri\point3[0] + (400 - SIDE/2), tri\point3[1] + 400 Line tri\point3[0] + (400 - SIDE/2), tri\point3[1] + 400, tri\point1[0] + (400 - SIDE/2), tri\point1[1] + 400 Next
Delete Each Triangle
SetBuffer FrontBuffer() DrawImage pic, 0, 0
WaitKey End
Function Transform1(tri.Triangle) Local i For i = 0 To 1 tri\point1[i] = tri\point1[i]*.5 tri\point2[i] = tri\point2[i]*.5 tri\point3[i] = tri\point3[i]*.5 Next End Function
Function Transform2(tri.Triangle) Local i For i = 0 To 1 tri\point1[i] = tri\point1[i]*.5 tri\point2[i] = tri\point2[i]*.5 tri\point3[i] = tri\point3[i]*.5 Next tri\point1[0] = tri\point1[0] + SIDE/2 tri\point2[0] = tri\point2[0] + SIDE/2 tri\point3[0] = tri\point3[0] + SIDE/2 End Function
Function Transform3(tri.Triangle) Local i For i = 0 To 1 tri\point1[i] = tri\point1[i]*.5 + (-1 + 2*(i = 0)) * ((i = 0)*Float(SIDE/4) + (i = 1)*Float(Sqr(3)/4)*SIDE) tri\point2[i] = tri\point2[i]*.5 + (-1 + 2*(i = 0)) * ((i = 0)*Float(SIDE/4) + (i = 1)*Float(Sqr(3)/4)*SIDE) tri\point3[i] = tri\point3[i]*.5 + (-1 + 2*(i = 0)) * ((i = 0)*Float(SIDE/4) + (i = 1)*Float(Sqr(3)/4)*SIDE) Next End Function
Function CopyTriangle.Triangle(tri.Triangle) Local tr.Triangle = New Triangle, i For i = 0 To 1 tr\point1[i] = tri\point1[i] tr\point2[i] = tri\point2[i] tr\point3[i] = tri\point3[i] Next Return tr End Function
~EDITIERT~
Überlange unterbrechungsfreie Kommentarzeilen entfernt, weil diese das Forenlayout zerschiessen.
mfG, Holzchopf
|