1. ## Mystery Curve

Mystery Curve article here:
http://www.johndcook.com/blog/2015/06/03/mystery-curve/
he provides formula Exp(it) – Exp(6it)/2 + i Exp(-14it)/3 , for t going to 2*pi and i is the imaginary number, he provides a python code using numby math library
i see thinbasic have complex numbers functions, but until i find a way to use these functions in this context, i have resorted to wolfram alpha to simplify the formula, interestingly they recognize i as imaginary:
simplify Exp(it) – Exp(6it)/2 + i Exp(-14it)/3
fortunately they provide this simplification
1/3 sin(14 t)+cos(t)-1/2 cos(6 t)+ i (sin(t)-1/2 sin(6 t)+1/3 cos(14 t))
note that wolframAlpha is too advanced and have something like A.I.
so what comes after i we assign to y, and what come first we assign to x
x = Cos(t) - Cos(6* t)/2 + Sin(14* t)/3
y = Cos(14* t)/3 + Sin(t)- Sin(6* t)/2
z : for the fun only , give it a value of 0 or 1 to get a stereo scene z = Rnd(0,1), or give it a value z = 0 to get one curve.
in fact i have used older code (shark equation), the only trouble is in simplifying the Mystery curve formula.
hope this page is of value to who may have trouble in plotting Exp(it) – Exp(6it)/2 + i Exp(-14it)/3

```Uses "TBGL"
Uses "math"
Function TBMain()
Local hWnd      As DWord
Local FrameRate As Double
' -- Create and show window
hWnd = TBGL_CreateWindowEx("Mystery Curve using GBuffers - press ESC to quit", 600, 600, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX)
TBGL_ShowWindow
TBGL_BackColor 255,255,255
TBGL_SetDrawDistance 250
' -- Create 3D points buffer
Dim  gbPoints As DWord = TBGL_GBufferCreate(%TBGL_POINTS, %TBGL_3D)
'Dim  gbPoints As DWord = TBGL_GBufferCreate(%TBGL_LINES, %TBGL_3D)
Global Nb As DWord = 30159 '10053 '30159 '62831
' -- Define data for it
Global VertexA(Nb) As TBGL_TVECTOR3F
Global ColorA(Nb)  As TBGL_TRGB

FillArrays ' call the sub to fill VertexA , ColorA  arrays

' -- Create buffer dynamically linked to the arrays above
TBGL_GBufferDefineFromArray(gbPoints, %TBGL_DYNAMIC, CountOf(VertexA), VertexA(1), ColorA(1))
' -- Resets status of all keys
TBGL_ResetKeyState()
'TBGL_PointSize 2 'if you want thick points uncomment this line
' -- Main loop
While TBGL_IsWindow(hWnd)
'init
FrameRate = TBGL_GetFrameRate
TBGL_ClearFrame
TBGL_Camera(0, 0, 50, 0, 0, 0)
' -- Turn triangle
TBGL_Rotate GetTickCount/50, 0, 1, 0
'TBGL_Scale 0.6, 0.6, 0.6
' -- Render it
TBGL_GBufferRender(gbPoints)
TBGL_DrawFrame
' -- ESCAPE key to exit application
If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While
Wend
' -- Destroying the buffer is not necessary,
' -- the garbage collector will take care of it

' -- Destroy window
TBGL_DestroyWindow
End Function

Sub FillArrays()
Dim x, y, z, t As Single
Dim N As DWord = 1
While t <= 2*Pi
'Exp(it) – Exp(6it)/2 + i Exp(-14it)/3
x = Cos(t) - Cos(6* t)/2 + Sin(14* t)/3
y = Cos(14* t)/3 + Sin(t)- Sin(6* t)/2
z = Rnd(0,1)
VertexA(N).x = x*6
VertexA(N).y = y*6
VertexA(N).z = z*3
'ColorA(N).r = 255 :ColorA(N).g = 0 :ColorA(N).b = 0
If z = 1 Then
ColorA(N).r = 255 :ColorA(N).g = 0 :ColorA(N).b = 0
Else
ColorA(N).r = 0 :ColorA(N).g = 0 :ColorA(N).b = 255
End If

t + 0.0003 : N + 1
Wend

End Sub
```

2. thank you primo, nice example.
I looked at the python code, it's so compact due to the use of the libraries.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•