Last active
August 6, 2021 09:00
-
-
Save Tricky1975/398006c3abe963d8d39a9afd8be8345c to your computer and use it in GitHub Desktop.
This is a kind of formula math professionals appear to avoid... I had to try if I could turn it into a nice effect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Main | |
Const Cycles = 360 | |
Const Width = 1200 | |
Const Height = 1000 | |
Function Even(a%) | |
Return a Mod 2 = 0 | |
End Function | |
Function Max(A,B) | |
If A>B | |
Return A | |
Else | |
Return B | |
EndIf | |
End Function | |
Function Main() | |
DebugLog "Let's do it! "+Cycles+" Cycles" | |
AppTitle "3x+1" | |
Graphics Width,Height | |
SetBuffer FrontBuffer() | |
For ak=1 To Cycles | |
DebugLog "Cycle: "+Ak | |
Local R% = Abs(Sin(ak)*255) | |
Local G% = Abs(Cos(ak)*255) | |
Local B% = Abs(ak-Floor(Cycles/2)) Mod 256 | |
Color R,G,B | |
Local D = ak | |
For Pos=0 To Max(Width,Height) | |
;DebugLog "Cycle: "+Ak+"; Pos: "+Pos | |
If Even(D) | |
D = D / 2 | |
Else | |
D = (D*3) + 1 | |
EndIf | |
If D>4 | |
DebugLog "Cycle: "+Ak+"; Pos: "+Pos+"; D: "+D | |
EndIf | |
For Y=0 To D | |
; Base | |
Plot Pos,Y | |
Plot Pos,Height-Y | |
Plot Y,Pos | |
Plot Width-Y,Pos | |
; Inverse | |
Plot Width-Pos,Y | |
Plot Width-Pos,Height-Y | |
Plot Y,Height-Pos | |
Plot Width-Y,Height-Pos | |
Next | |
Next | |
Next | |
WaitKey | |
DebugLog "It's over" | |
End | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The result looks a bit like this