'Simple coordinate system And projection
Const PI As Single = 3.1415926
Dim Shared Cartesian_Array_(0 To 2) As Single
Dim Shared Projection_array_(0 To 2) As Single
Sub Cartesian(byval Pitch As Single,byval Yaw As Single,byval Roll As Single,byval X_Vector As Single, byval Y_Vector As Single,ByVal Z_vector As Single) Export
Dim As Single sx,cx,sy,cy,sz,cz,xy,xz,yz,yx,zx,zy
Pitch *= PI / 180
Yaw *= PI / 180
Roll *= PI / 180
sx = Sin(Pitch)
cx = Cos(Pitch)
sy = Sin(Yaw)
cy = Cos(Yaw)
sz = Sin(Roll)
cz = Cos(Roll)
'// rotation around X
xy = cx*Y_Vector - sx*Z_Vector
xz = sx*Y_Vector + cx*Z_Vector
'// rotation around Y
yz = cy*xz - sy*X_vector
yx = sy*xz + cy*X_vector
'// rotation around Z
zx = cz*yx - sz*xy
zy = sz*yx + cz*xy
Cartesian_Array_(0)=zx
Cartesian_Array_(1)=zy
Cartesian_Array_(2)=yz
End Sub
Function CartesianX() As Single Export
Return Cartesian_Array_(0)
End Function
Function CartesianY() As Single Export
Return Cartesian_Array_(1)
End Function
Function CartesianZ() As Single Export
Return Cartesian_Array_(2)
End Function
Sub Project3Dto2D(byval Graphics_Center_X As Single,ByVal Graphics_Center_Y As Single,byval Graphics_Center_Z As Single,ByVal X_Point As Single,byval Y_Point As Single,byval Z_Point As Single,ByVal Distance_Human_To_Screen As Single,byval Distance_Screen_To_Point As Single) Export
Projection_array_(0) = Graphics_Center_X + (Distance_Human_To_Screen * X_Point / (Z_Point + Distance_Screen_To_Point))
Projection_array_(1) = Graphics_Center_Y + (Distance_Human_To_Screen * Y_Point / (Z_Point + Distance_Screen_To_Point))
Projection_array_(2) = Graphics_Center_Z + (Distance_Human_To_Screen * Z_Point / (X_Point + Distance_Screen_To_Point))
End Sub
Function ProjectedX() As Single Export
Return Projection_array_(0)
End Function
Function ProjectedY() As Single Export
Return Projection_array_(1)
End Function
Function ProjectedZ() As Single Export
Return Projection_array_(2)
End Function
'----------------------- The MAIN PROGRM ---------------------
' A division reduction fractal. I call it n0n.
' The real goal is to get this so large that you cannot see the angles of the lines
' and with rotations some pretty cool things happen, not sure how they fit into the
' information of division and reduction but still should be pretty cool.
' I wanted to use multithreading on this but kept running into errors so here is
' the procedural version.
#include "fbgfx.bi"
#If __FB_LANG__ = "fb"
Using FB '' Scan code constants are stored in the FB namespace in lang FB
#endif
screenres 800,600,32,2
Dim Shared As Integer GW,GH
screeninfo GW,GH
Dim Shared MaxGen As Integer = 2 'Number of generations, 0 is first
Dim Shared MaxIter As Integer = 1000 ' Number of iterations per generation
Dim Shared Col(0 To 9 , 0 To 2) As Integer
For i As Integer = 0 To 9
For j As Integer = 0 To 2
col(i,j) = Int(rnd()*255)
Next
Next
Type Info
Dim As Integer A,B,Rot,Iteration,Generation
Dim As Single Pitch,Yaw,Roll,Zoom
Dim As Integer X,Y,Z
End Type
Declare Sub Divide( Inf As Info PTR)
Dim As Single Pitch,Yaw,Roll,Zoom = 1000
While MultiKey(sc_escape) = 0
If MultiKey(sc_left) Then Yaw = (Yaw + .1) Mod 360
If MultiKey(sc_right) Then Yaw = (Yaw -.1) Mod 360
If MultiKey(sc_up) Then Zoom = Zoom - 1
If MultiKey(sc_down) Then Zoom = Zoom + 1
Dim Inf As Info PTR = New Info
Inf->A = 132 ' just a random number
Inf->B = 343 ' just a random number
Inf->Pitch = Pitch
Inf->Yaw = Yaw
Inf->Roll = Roll
Inf->Zoom = Zoom
Divide(Inf)
Wend
Sleep
End
Sub Divide( Inf As Info PTR )
'Make temp X,Y,Z holders For drawing last point To Next point
Dim As Integer tx,ty,tz
tx = Inf->X
ty = Inf->Y
tz = Inf->Z
'Test limits of coninued Iteration
While Inf->A > 0 And Inf->B > 0 And MultiKey(sc_escape) = 0 And Inf->Generation <= MaxGen And Inf->Iteration <= MaxIter
Dim c As Integer = Int(Inf->A/Inf->B) 'first step of division 1/3
Inf->A -= (Inf->B*c) 'second step of division 2/3
' Find position of the sequence (ie. convert 1d To 3d coordinates)
Select Case Inf->Rot
Case 0
Inf->X += c
Case 1
Inf->Y += c
Case 2
Inf->Z += c
Case 3
Inf->X -=c
Case 4
Inf->Y -= c
Case 5
Inf->Z -= c
Inf->Rot = -1
End Select
Inf->Rot += 1
' the MultiKey thing isn't working right.. not sure why
If MultiKey(sc_left) Then Inf->Yaw = (Inf->Yaw + .1) Mod 360
If MultiKey(sc_right) Then Inf->Yaw = (Inf->Yaw -.1) Mod 360
' Zoom works but not the above
If MultiKey(sc_up) Then Inf->Zoom = Inf->Zoom - 1
If MultiKey(sc_down) Then Inf->Zoom = Inf->Zoom + 1
' Convert 3d coordinates And rotations To 3d coordinates with rotations
cartesian(Inf->Pitch,Inf->Yaw,Inf->Roll,Inf->X,Inf->Y,Inf->Z)
' project 3d coordinates with rotations To 2d surface
Project3Dto2D(Gw/2,gh/2,0,cartesianx(),cartesiany(),cartesianz(),1000,Inf->Zoom)
' Store Then For use with A line
Dim thisx As Single = projectedx()
Dim thisy As Single = projectedy()
' convert the last position To 3d coordinates with rotations
cartesian(Inf->Pitch,Inf->Yaw,Inf->Roll,tx,ty,tz)
' Project the 3d To 3d
Project3Dto2D(Gw/2,gh/2,0,cartesianx(),cartesiany(),cartesianz(),1000,Inf->Zoom)
' Make the color the value of place in divisional sequence
Color RGB(col(c,0),col(c,1),col(c,2))
' Draw the line
Line (thisx,thisy)-(projectedx(),Projectedy())
' Store the current position into the temp
tx = Inf->X
ty = Inf->Y
tz = Inf->Z
' Create A New Information Type And assign it current values swaping
' A And B For reduction
Dim Tinf As Info PTR = New Info
Tinf->A = Inf->B
Tinf->B = Inf->A
Tinf->X = Inf->X
Tinf->Y = Inf->Y
Tinf->Z = Inf->Z
Tinf->Zoom = Inf->Zoom
Tinf->Generation = Inf->Generation + 1
Tinf->Rot = Inf->Rot
Divide(Tinf) ' Process the newly created Information
Inf->A *= 10 ' last step of division 3/3
Inf->Iteration += 1 ' count the number of iterations
Wend
Delete Inf 'some limit is reached weather divide by 0 or other so delete this Info
End Sub