Der Code ist lauffähig bzw. funktioniert ?
Ich poste trotzdem mal ein Programm um zu beweisen das der Code funktioniert.
Die Funktion SierpinskiFractal() will 3 mal die XY-Positionen für die jeweiligen Ecken des Dreiecks.
Das Ursprungsdreieck muss vorgegeben werden (S0, S1 und S2).
Alle anderen benöigten Ausgangspunkte werden innerhalb der Funktion berechnet (A, B und C).
Code: Alles auswählen
;PB v.5.62
;REPLICATOR by Mijikai
;Music by Phekki (Title: Comeback)
Structure VECTOR
X.f
Y.f
Z.f
EndStructure
Global S0.VECTOR, S1.VECTOR, S3.VECTOR, Flags.i,Ticks.f,Iterations.i,Color.i,*ModBuffer
Procedure.i RenderBox(X.f,Y.f,Width.f,Height.f)
Static Tick.f,C.f,Flip.b
If Tick > 360:Tick = 0:If Flip = #True:Flip = #False:Else:Flip = #True:EndIf
Else:Tick + 6:EndIf:If Flip:C = 1 - (Tick / 360):Else:C = Tick / 360:EndIf
glLineWidth_(20)
glPushMatrix_()
glTranslated_(X,Y,0)
glBegin_(#GL_LINE_LOOP)
glColor4f_(C,0,C,1):glVertex2i_(X,Y)
glColor4f_(0,0,C,1):glVertex2i_(X,Y + Height)
glColor4f_(0,C,C,1):glVertex2i_(X + Width,Y + Height)
glColor4f_(0,C,C,1):glVertex2i_(X + Width,Y)
glEnd_()
glPopMatrix_()
EndProcedure
Procedure.i SierpinskiFractal(*P0.VECTOR,*P1.VECTOR,*P2.VECTOR,Iteration.i)
Protected.VECTOR A,B,C
If Iteration:Iteration - 1
glLineWidth_(3)
glBegin_(#GL_LINE_LOOP)
glColor4ub_(255,25,63,200)
glVertex2f_(*P0\X,*P0\Y)
glVertex2f_(*P1\X,*P1\Y)
glColor4ub_(55,125,63,200)
glVertex2f_(*P2\X,*P2\Y)
glColor4ub_(55,125,163,200)
glVertex2f_(*P0\X,*P0\Y)
glEnd_()
A\X = (*P0\X + *P1\X) / 2:A\Y = (*P0\Y + *P1\Y) / 2
B\X = (*P1\X + *P2\X) / 2:B\Y = (*P1\Y + *P2\Y) / 2
C\X = (*P2\X + *P0\X) / 2:C\Y = (*P2\Y + *P0\Y) / 2
SierpinskiFractal(*P0,@A,@C,Iteration)
SierpinskiFractal(@A,*P1,@B,Iteration)
SierpinskiFractal(@C,@B,*P2,Iteration)
EndIf
EndProcedure
InitNetwork():InitSound()
*ModBuffer = ReceiveHTTPMemory("https://api.modarchive.org/downloads.php?moduleid=178900#phekkis_-_comeback.xm")
If *ModBuffer:S0\X = - 200:S0\Y = 200:S0\Z = 100:S1\X = 0:S1\Y = - 200:S1\Z = 0:S3\X = 200:S3\Y = 200:S0\Z = 100
Flags = #PB_Window_SystemMenu|#PB_Window_Tool|#PB_Window_ScreenCentered
If OpenWindow(0,#Null,#Null,400,400,"REPLICATOR by mijikai | Music by Phekki (Comeback)",Flags) And OpenGLGadget(1,#Null,#Null,400,400)
StickyWindow(0,#True)
glOrtho_(0,400,400,0,-1000,1000)
glMatrixMode_(#GL_MODELVIEW)
Iterations = 1:Color = $31281B
glClearColor_(Red(Color) / 255,Green(Color) / 255,Blue(Color) / 255,1)
CatchMusic(2,*ModBuffer,MemorySize(*ModBuffer))
MusicVolume(2,40):PlayMusic(2)
Repeat
Repeat:Select WindowEvent():Case #PB_Event_CloseWindow:Break 2:Case 0:Break:EndSelect:ForEver
glClear_(#GL_COLOR_BUFFER_BIT|#GL_DEPTH_BUFFER_BIT)
glLoadIdentity_()
If Ticks > 360:If Iterations > 5:Iterations = 0:Else:Iterations + 0.8:EndIf:Ticks = 0:Else :Ticks + 3:EndIf
glTranslatef_(200,200,-200)
glRotatef_(Ticks,0,1,1)
SierpinskiFractal(@S0,@S1,@S3,Iterations)
glTranslatef_(0,0,300)
glRotatef_(Ticks,-1,1,0)
SierpinskiFractal(@S0,@S1,@S3,6 - Iterations)
glLoadIdentity_()
RenderBox(0,0,400,400)
SetGadgetAttribute(1,#PB_OpenGL_FlipBuffers,#True)
ForEver
EndIf
FreeMemory(*ModBuffer)
EndIf