EnableExplicit

;#SpectrumArraySize = #WidthPX
#MaxTick = $20000
#GridSpacePX = 1
Global Dim xCurSpec.f(5)











; Copyright (C) 2007-2011 Jan Vorel
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
;
; If you have any questions, suggestions or bug reports about this product,
; contact me: info@ctuser.net; Do not contact me about general B.A.S.I.C.
; language or A.P.I. issues





; Wavedata To spectrum Data conversation is based on a free Visual Basic 6
; example by Ulli "Mühlenweg" <umgedv@yahoo.com>, which can be found at
; http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=65007&lngWId=1

#WidthPX = 48;32
#HeightPX = 24

#AnimPlugin = 2
#RenderSelf = 2
#PSFMode = 0
#FPS=0
#FixedUse = 0
#MMonitor = 1
#WarnMsg = 1
#HAlign = 1
#StereoBMP = 1
#WarnQuit = 0
#OnPicRender = 0
#RenderMainInfoMySelf = 0

Declare PrepGrid(xElapsedTicks.l)
Declare ResizedSelf()
Declare RenderSelf(SkipFrame.l, xElapsedTicks.l)
Global MaxInit.f

#WidthPX_ForDimX = #WidthPX * 2 - 1

Global Dim xDims.l(#WidthPX_ForDimX)

#WidthPX_Loop = #WidthPX - 1
#HeightPX_Loop = #HeightPX - 1
#TotalXY_Loop = #WidthPX * #HeightPX * 2 - 1
Global Dim RenderData.l(#WidthPX * #HeightPX * $28 - 1)

Global xPosP0.l
Global xPosP1.l
Global xPosP1.l
Global xPosP2.l
Global xPosP3.l
Global xPosP4.l
Global xPosP5.l

Global xCurStpTick.l
Global MaxSQRDia.l


MaxInit = 0.05
MaxSQRDia = Sqr(#WidthPX * #WidthPX + #HeightPX * #HeightPX) + 1
IncludeFile "LSDemo.pb"

Procedure ResizedSelf()
  Define.RECT xType1
  GetClientRect_(xMainHWnd, @xType1)
  FillRect_(xMainDC, @xType1, hBrush)
  Define.l FullWindow_H2 = (xType1\Bottom - #PicSizeYOX) / (2 * #HeightPX)
  Define.l FullWindow_HP2 = xType1\Bottom
  Define.l FullWindow_W2 = xType1\Right / #WidthPX
  Define.l FullWindow_H2X = FullWindow_H2 - 1
  Define.l FullWindow_W2X = FullWindow_W2 - 1

  Define.l Row
  Define.l Col
  Define.l DataPtr
  Define.f P1
  Define.l OffX = (xType1\Right - #WidthPX * FullWindow_W2) / 2
  Define.l OffY = (xType1\Bottom - #PicSizeYOX - 2 * #HeightPX * FullWindow_H2) / 2
  
  DataPtr = @RenderData(0)
  For Row = 0 To #HeightPX_Loop
    ;P1 = (Row + 1) / #HeightPX
    ;xDims(Row) = Sqr(2 * P1 - P1*P1)
    ;xDims(Row) = Sin(Row * 2 * #PI / #HeightPX) * 255
    xDims(Row) = Sin((Row + 1) * #PI / (#HeightPX + 1)) * 255
    ;xDims(Row) = Sqr(2 * P1 - P1*P1) * 255
    
    For Col = 0 To #WidthPX_Loop
      PokeL(DataPtr + $04, OffX + Col * FullWindow_W2) ; Left
      PokeL(DataPtr + $08, OffY + Row * FullWindow_H2) ; Top
      PokeL(DataPtr + $0C, OffX + (Col + 1) * FullWindow_W2 - #GridSpacePX) ; Right
      PokeL(DataPtr + $10, OffY + (Row + 1) * FullWindow_H2 - #GridSpacePX) ; Bottom
      PokeL(DataPtr + $18, OffX + Col * FullWindow_W2) ; Left
      PokeL(DataPtr + $1C, FullWindow_HP2 - OffY - (#HeightPX - Row - 1) * FullWindow_H2) ; Top
      PokeL(DataPtr + $20, OffX + (Col + 1) * FullWindow_W2 - #GridSpacePX) ; Right
      PokeL(DataPtr + $24, FullWindow_HP2 - OffY - (#HeightPX - Row) * FullWindow_H2 + #GridSpacePX) ; Bottom
      DataPtr + $28
      Next
    Next
  EndProcedure

Declare GetGridColor(X.l, Y.l, *ColorL, *ColorR)

Procedure RenderSelf(SkipFrame.l, xElapsedTicks.l)
  Define.l Row
  Define.l Col
  Define.l xhBrush
  Define.l xColorL
  Define.l xColorR
  Define.l DataPtr

  If SkipFrame
    If MaxInit < 1.5
      MaxInit + 0.04
      EndIf
    EndIf

  
  xCurStpTick = (xCurStpTick + xElapsedTicks) & #MaxTickAND

  PrepGrid(xElapsedTicks)
  
  DataPtr = @RenderData(0)
  For Row = 0 To #HeightPX_Loop
    For Col = 0 To #WidthPX_Loop
      GetGridColor(Col, Row, DataPtr, DataPtr + $14)
      DataPtr + $28
      Next
    Next
    
  DataPtr = @RenderData(0)
  For Row = 0 To #TotalXY_Loop
    xhBrush = CreateSolidBrush_(PeekL(DataPtr))
    If Not xhBrush = 0
      FillRect_(xMainDC, DataPtr + 4, xhBrush)
      DeleteObject_(xhBrush)
      EndIf
    DataPtr + $14
    Next
  EndProcedure

;IncludeFile "LSDemo_PB_FireBeam.pb"

















;Global Dim xCurSpec.f(#WidthPX_ForDimX)

Procedure PrepGrid(xElapsedTicks.l)
  Define.l xLong1
  
  #MyRotTick = $2000
  #MyRotTickAnd = #MyRotTick - 1
  #MyRotTickDiv = #MyRotTick / 2
  xLong1 = (xCurStpTick & #MyRotTickAnd)
  xPosP0 = (( Sin(xLong1 * #PI / #MyRotTickDiv) * 0.20) + 0.2) * #WidthPX    ;leftx
  xPosP1 = ((-Cos(xLong1 * #PI / #MyRotTickDiv) * 0.27) + 0.5) * #HeightPX ;lecty
  xPosP2 = (( Sin(xLong1 * #PI / #MyRotTickDiv) * 0.30) + 0.5) * #WidthPX    ;centerx
  xPosP3 = (( Cos(xLong1 * #PI / #MyRotTickDiv) * 0.27) + 0.5) * #HeightPX  ;centery
  xPosP4 = ((-Sin(xLong1 * #PI / #MyRotTickDiv) * 0.30) + 0.8) * #WidthPX   ;rightx
  xPosP5 = (( Cos(xLong1 * #PI / #MyRotTickDiv) * 0.27) + 0.5) * #HeightPX  ;righty
  
  LineSpec_GetSpectrum(@xCurSpec(0), 3, 3, 2, @MaxInit)
  EndProcedure

Macro GetByDistColor(xFloat1, RelPos1, RelPos2)
  xFloat1 = Sqr((X - xPosP#RelPos1) * (X - xPosP#RelPos1) + (Y - xPosP#RelPos2) * (Y - xPosP#RelPos2))
  xFloat1 = (1 - xFloat1 * #BlankSpace / MaxSQRDia)
  EndMacro

Macro GetGCToColor(Poker, CIDR, CIDG, CIDB)
  ColorR = ColorRf * 200 * (xCurSpec(CIDR) * 0.8  * 2.9 + 0.23)
  ColorG = ColorGf * 200 * (xCurSpec(CIDG) * 0.9  * 2.9 + 0.23)
  ColorB = ColorBf * 200 * (xCurSpec(CIDB) * 0.95 * 2.9 + 0.23)
  If ColorR < 0: ColorR = 0: EndIf
  If ColorG < 0: ColorG = 0: EndIf
  If ColorB < 0: ColorB = 0: EndIf
  If ColorR > xDims(Y): ColorR = xDims(Y): EndIf
  If ColorG > xDims(Y): ColorG = xDims(Y): EndIf
  If ColorB > xDims(Y): ColorB = xDims(Y): EndIf
  PokeL(Poker, ColorR + ColorG * $100 + ColorB * $10000)
  EndMacro

Procedure GetGridColor(X.l, Y.l, *ColorL, *ColorR)
  Define.l ColorR
  Define.l ColorG
  Define.l ColorB
  Define.f ColorRf
  Define.f ColorGf
  Define.f ColorBf
  
  ;#BlankSpace = 7.0
  #BlankSpace = 1.9
  
  GetByDistColor(ColorBf, 0, 1)
  GetByDistColor(ColorGf, 2, 3)
  GetByDistColor(ColorRf, 4, 5)
  
  GetGCToColor(*ColorL, 2, 1, 0)
  GetGCToColor(*ColorR, 5, 4, 3)
  
;  PokeL(*ColorL, xDims(Y) * $10101)
;  PokeL(*ColorR, xDims(Y) * $10101)
  EndProcedure


; IDE Options = PureBasic 4.51 (Windows - x86)
; CursorPosition = 4
; Folding = --
; EnableAsm
; Executable = C:\Q0501E\USERDATA\DESKTOP\test.exe
; DisableDebugger
; AddResource = D:\DEV\Software\Libraries\LineSpec\Demo applications\source\LSDemo (plasmabeam).rc