Dreieck-Algorythmus von ???
Im Prog gibt es Linien als Type, die verarbeitet werden, und zwar so:
die Linie wird aufgeteilt in 3 Drittel und im mittleren Drittel wird ein Dreieck gesetzt. Dadurch entstehen neue Linien und es entsteht eine nette kurvige Linie. Man kann auch mit den Start-Linien ein bisschen rumprobieren. Der Code is aber kaotisch, weils schnell gehn sollte.

[code:1:248516bad3]
Graphics 1024,768,16,1
SetBuffer FrontBuffer()


Type linie
Field x1,y1
Field x2,y2
Field stufe
End Type


Global dieStufe


Function Winkel(x1,y1,x2,y2)
If x1>=x2
If y1>=y2
Return ATan2(Abs(x1-x2),Abs(y1-y2))
Else
Return 180-ATan2(Abs(x1-x2),Abs(y1-y2))
EndIf
Else
If y1<=y2
Return 180+ATan2(Abs(x1-x2),Abs(y1-y2))
Else
Return 360-ATan2(Abs(x1-x2),Abs(y1-y2))
EndIf
EndIf
End Function


Function NeueStufe()
dieStufe=dieStufe+1
;Alle vorhandenen Linien mit einem Dreieck versehen.
For xx.linie=Each linie
If xxstufe=dieStufe Exit
;Daten lesen und Linie löschen.
x1=xxx1
y1=xxy1
x2=xxx2
y2=xxy2
;If x1<=x2 leftX=x1 rightX=x2 leftY=y1 rightY=y2 Else leftX=x2 rightX=x1 leftY=y2 rightY=y1
;If y1<=y2 topY=y1 downY=y2 topX=x1 downX=x2 Else topY=y2 downY=y1 topX=x2 downX=x1
downX=x1
downY=y1
topX=x2
topY=y2
Delete xx
w=Winkel(topX,topY,downX,downY)+90
a=((Abs(x1-x2)^2+Abs(y1-y2)^2)^0.5)
h=Sin(60)*(a/3)
PX=downX+Sin(w-90)*(a/2)
PY=downY+Cos(w-90)*(a/2)
CX=PX+Sin(w)*h
CY=PY+Cos(w)*h
DX=downX+Sin(w-90)*(a/3)
DY=downY+Cos(w-90)*(a/3)
EX=downX+Sin(w-90)*(2*(a/3))
EY=downY+Cos(w-90)*(2*(a/3))
one.linie=New linie
two.linie=New linie
three.linie=New linie
four.linie=New linie
onex1=downX oney1=downY onex2=DX oney2=DY onestufe=dieStufe
twox1=DX twoy1=DY twox2=CX twoy2=CY twostufe=dieStufe
threex1=CX threey1=CY threex2=EX threey2=EY threestufe=dieStufe
fourx1=EX foury1=EY fourx2=topX foury2=topY fourstufe=dieStufe
DrawLinie(one) DrawLinie(two) DrawLinie(three) DrawLinie(four)
If KeyDown(1) End
Next
End Function


Function DrawLinie(theLinie.linie)
Line theLiniex1,theLiniey1,theLiniex2,theLiniey2
End Function



Function StartLinie(x1,y1,x2,y2)
start.linie=New linie
startx1=x1
starty1=y1
startx2=x2
starty2=y2
End Function


;IN DIESEN BEREICH DIE STARTLINIEN EINFÜGEN
StartLinie(200,300,700,300)
StartLinie(700,300,200,300)
;IN DIESEN BEREICH DIE STARTLINIEN EINFÜGEN


Repeat

Locate 0,0
Print "Space gedrückt:"+dieStufe
;Draw()
WaitKey
Cls
NeueStufe()

Forever

[/code:1:248516bad3]
===
von ???
Schön programmiert, das Teil nennt sich Kochkurve. Um das Ergebnis
zu optimieren, müsstest du nicht zwei Kochkurven gespiegelt
untereinander platzieren, sondern eine oben, eine um 120 Grad
nach rechts gedrehte, und eine dritte, ebenfalls wieder um 120
Grad nach rechts gedrehte. Das Ergebnis sieht wie eine Schneeflocke
aus:

[code:1:b940f20c1e] Graphics 800,600

Global PositionX# = GraphicsWidth()/2, PositionY#=GraphicsHeight()/2, Kurs#

For i = 1 To 3
Koch 3,300
re 120
Next

WaitKey()
End

;====================================================0

Function Koch(n, Laenge#)
If n = 0 Then vw Laenge# Return
Koch n - 1, Laenge# / 3 li 60
Koch n - 1, Laenge# / 3 re 120
Koch n - 1, Laenge# / 3 li 60
Koch n - 1, Laenge# / 3
End Function

Function VW(Laenge#)
x1# = PositionX
y1# = PositionY
x2# = PositionX + Cos(Kurs) * Laenge#
y2# = PositionY + Sin(Kurs) * Laenge#
Line x1,y1,x2,y2
PositionX = x2
PositionY = y2
End Function

Function RE(Winkel#)
Kurs = (Kurs + Winkel# + 360) Mod 360
End Function

Function LI(Winkel#)
Kurs = (Kurs - Winkel# + 360) Mod 360
End Function[/code:1:b940f20c1e]

Dieser Code kommt eigentlich aus der Anfängersprache LOGO, ich habe
mal auf die Schnelle einen kleinen Interpreter geschrieben und das
Logo-Kochprogramm angepasst. Du siehst das selbe Ergebnis wie bei
deinem Programm, nur dass meins viel kleiner ist ;)

[EDIT]
Mein Code hat natürlich níx mehr mit Types oder so nem Kram zu tun :D
Es ist einfache Rekursion, welche ich angewendet habe.
===
von ???
Ganz einfach: Erstetze diesen Teil[code:1:acd204f461]For i = 1 To 3
Koch 3,300
re 120
Next[/code:1:acd204f461]durch diesen:[code:1:acd204f461]For i = 1 To 3
Koch 5,300
re 120
Next[/code:1:acd204f461]
Du siehst, dass der Parameter "n" von der Funktion "Koch(n,Laenge#)"
erhöht wurde, somit wird also die Dichte des Fraktals verändert.
Natürlich kannst du für "n" beliebige Werte eingeben...

[EDIT]
Ich wollte übrigens nicht sagen, dass dein Programmcode schlecht ist
oder so, nur dass es auch einfacher (:)) geht. Und übrigens: Es würde
mich nicht wundern, wenn die Rekursion die schnellere Variante ist :wink:
Peace
===
von ???
Hier nochmals ein wenig optimiert:

[code:1:72f99787d7]
Graphics 800,600,32,2

Dim sins#(5)
Dim coss#(5)

For i=0 To 5
sins(i) = Sin(i*60)
coss(i) = Cos(i*60)
Next

Global PositionX# = GraphicsWidth()/2, PositionY#=GraphicsHeight()/2, Kurs

;---

For i = 1 To 3
Koch(10,300)
re(2)
Next

WaitKey()
End


;====================================================0

Function Koch(n, Laenge#)
If n = 0 Then VW(Laenge#) : Return
Koch(n - 1, Laenge# / 3) : LI(1)
Koch(n - 1, Laenge# / 3) : RE(2)
Koch(n - 1, Laenge# / 3) : LI(1)
Koch(n - 1, Laenge# / 3)
End Function

Function VW(Laenge#)
x1# = PositionX
y1# = PositionY
x2# = PositionX + coss(Kurs) * Laenge#
y2# = PositionY + sins(Kurs) * Laenge#
Line x1,y1,x2,y2
PositionX = x2
PositionY = y2
End Function

Function RE(Winkel)
Kurs = (Kurs + Winkel + 6) Mod 6
End Function

Function LI(Winkel)
Kurs = (Kurs - Winkel + 6) Mod 6
End Function
[/code:1:72f99787d7]



Suche:
(unterstützt mySQL Wildcards ala %)
Titel:
Text:
Autor: