EnableExplicit

#LEDMode = $ff00

#CustomPeakRender = #True
#CustomPeakInnerSize = #False
#CustomPeakSizeMul = 6
#CustomPeakSizeDiv = 8
#CustomPeakSizePlus = 0
#ClearOldInfoBmp = #True
#OnPicRender = $680000 ; misuse $00xxxx / $000001 for full trans, $ff0000 for full black
#AlphaBackColor = $160500
#MMonitor = 1
#WarnMsg = #False
#WallBmpWidth = 1920
#WallBmpHeight = 1080
#PicSizeYOX = 300
#PicPos = 5
#PartID = 51885 ; stars/encircle
#MaxTick = $8000
#BarPos = 4
#BarOffset = 0
#BlackenTextBack = #True
Global MaxSize.l

#ProgressColorCur = $D1B098
#ProgressColorTot = $706040


#LargePeaks = 1
#PeaksCountMax = 20 ;1024;256
#PeaksCountMaxX = #PeaksCountMax - 1
#PeaksCountMaxP = #PeaksCountMax + 1
#PeaksCountMaxStereoAS = #PeaksCountMax * 2 - 1

#ParticleRenderCountMax = #PeaksCountMax * 2
#ParticleRenderCountMaxX = #ParticleRenderCountMax - 1


#LargeRects = 1



;#RenderMainInfoMySelf = 2 ; 1 = yes, 2=yes with transparency!!!
;CompilerIf #RenderMainInfoMySelf = 2
  ;Global TransparentCenterMul.f = 0.66
  ;CompilerEndIf

;#PI2 = 2 * #PI ;3.1415926536 * 2
Global Dim xCurSpec.f(#PeaksCountMaxStereoAS)
Global Dim xCurBeat.f(1)
Global Dim PreX.l(#PeaksCountMax)
Global Dim PreY.l(#PeaksCountMaxX)

Declare RenderSelfPart(SkipFrame.l, xElapsedTicks.l)
Declare InitCircles()
Global Dim DefColors(#PeaksCountMaxX)
InitCircles()

IncludeFile "LSDemo (Wallpaper).pb"

Procedure InitColorsFadingEx(VersionMode.i, IDFrom, IDWidth, Color1, Color2)
  Define.i ICFE_Width = IDWidth
  Define.i ICFE_WidthX = IDWidth - 1
  Define.i ICFE_xCounter

  Define.i ICFE_Red1 =  Color1 >> 16
  Define.i ICFE_Grn1 = (Color1 & $ff00)
  Define.i ICFE_Blu1 = (Color1 & $ff) << 16

  Define.i ICFE_Red2 =  Color2 >> 16
  Define.i ICFE_Grn2 = (Color2 & $ff00)
  Define.i ICFE_Blu2 = (Color2 & $ff) << 16
  Define.i ICFE_Pointer

  If VersionMode = 2
    ;Define.f RGBMixCodeVar1_#ID = $ff / ICFE_WidthX / Sqr(Sqr(ICFE_WidthX))
    Define.f IFCE_MixDiv = $ff / ICFE_WidthX / Sqr(Sqr(ICFE_WidthX))
    EndIf


  For ICFE_xCounter = 0 To ICFE_WidthX
    If VersionMode = 2
      Define.i ICFE_MixFactor1 = (ICFE_xCounter * Sqr(Sqr(ICFE_xCounter)) * IFCE_MixDiv)
      Else
      Define.i ICFE_MixFactor1 = (ICFE_xCounter * 255) / ICFE_WidthX
      EndIf
    Define.i ICFE_MixFactor2 = 255 - ICFE_MixFactor1

    Define.i ICFE_xCol.i = (((ICFE_Red1 * ICFE_MixFactor2 + ICFE_Red2 * ICFE_MixFactor1) / 255) & $ff)
             ICFE_xCol   | (((ICFE_Grn1 * ICFE_MixFactor2 + ICFE_Grn2 * ICFE_MixFactor1) / 255) &   $ff00)
             ICFE_xCol   | (((ICFE_Blu1 * ICFE_MixFactor2 + ICFE_Blu2 * ICFE_MixFactor1) / 255) &     $ff0000)
    DefColors(IDFrom) = ICFE_xCol
    IDFrom + 1
    Next
  EndProcedure

Macro InitColorsBy3Colors(Mode, Color1, Color2, Color3)
  Define.i SpecSizeHalf

  #ICFE_Color1#MacroExpandedCount = Color1
  #ICFE_Color2#MacroExpandedCount = Color2
  #ICFE_Color3#MacroExpandedCount = Color3
  SpecSizeHalf = (#PeaksCountMax + 1) >> 1
  InitColorsFadingEx(Mode, 0, SpecSizeHalf, #ICFE_Color1#MacroExpandedCount, #ICFE_Color2#MacroExpandedCount)
  InitColorsFadingEx(Mode, SpecSizeHalf, SpecSizeHalf, #ICFE_Color2#MacroExpandedCount, #ICFE_Color3#MacroExpandedCount)
  EndMacro

Procedure InitCircles()
  InitColorsBy3Colors(2, $0000ff, $00ff00, $ff0000)
  ;InitColorsBy3Colors(2, $5050ff, $50ff50, $ff5050)
  ;InitColorsBy3Colors(2, $275499, $00A843, $E02424)
  EndProcedure







Procedure RenderSelfPart(SkipFrame.l, xElapsedTicks.l)
  Define.l xLong1
  Define.i hxBrush
  Define.i hBrushOrg
  Define.i hBrushOld
  Define.i hxPen
  Define.i hPenOrg
  Define.i hPenOld
  Define.i MyMaxSize
  Define.i OffX
  Define.i OffY

  Define.f Boost = 1.5 ; 1.5;00
  If SetWaveData(0)
    GetFullSpectrumStereoOpt(0)
    SpectrumCompactStereo(0, 1024, @xCurSpec(0), #PeaksCountMax)
    SpectrumCompactStereo(@xCurSpec(0), #PeaksCountMax, @xCurBeat(0), 1)
    For xLong1 = 0 To #PeaksCountMaxX
      xCurSpec(xLong1) = 0.25 + 0.75 * xCurSpec(xLong1) ;+ 0.15 * xCurBeat(0)
      xCurSpec(xLong1 + #PeaksCountMax) = 0.25 + 0.75 * xCurSpec(xLong1 + #PeaksCountMax) ;+ 0.15 * xCurBeat(1)
      Next
    EndIf

  hPenOrg = GetCurrentObject_(hDCTemp3, #OBJ_PEN)
  hBrushOrg = GetCurrentObject_(hDCTemp3, #OBJ_BRUSH)
  PreX(#PeaksCountMax) = PreX(0)
  ;hxPen = CreatePen_(#PS_NULL, 0, $000000)
  hPenOld = CreatePen_(#PS_SOLID, 1, $000000)
  hBrushOld = CreateSolidBrush_($000000)
  MyMaxSize = MaxSize / 3
  If hBrushOld
    If hPenOld
      ;hPenOrg = SelectObject_(hDCTemp3, hxPen)
      ;SetArcDirection_(hDCTemp3, #AD_CLOCKWISE)
      SetArcDirection_(hDCTemp3, #AD_COUNTERCLOCKWISE)
      xLong1 = (GetTickCount_() & $3fff)
      Define.f xFloat1 = Sin(xLong1 * #PI * 2 / $4000)
      If xFloat1 < 0
        Define.i xXRot = Sqr(-xFloat1) * xFloat1 * #PeaksCountMaxP * 2
        Else
        Define.i xXRot = Sqr(xFloat1) * xFloat1 * #PeaksCountMaxP * 2
        EndIf
;xXRot = 0
      For xLong1 = 0 To #PeaksCountMaxX
        hxBrush = CreateSolidBrush_(DefColors(xLong1))
;If (xLong1 & 3) = 0
        ;hxBrush = CreateSolidBrush_((DefColors(xLong1) & $fefefe) >> 1)
        If hxBrush
          ;hxPen = CreatePen_(#PS_SOLID, 1, ((DefColors(xLong1) & $fefefe) >> 1) + ((DefColors(xLong1) & $fcfcfc) >> 2))
          hxPen = CreatePen_(#PS_SOLID, 1, (DefColors(xLong1) & $fefefe) >> 1)
          ;hxPen = CreatePen_(#PS_SOLID, 1, DefColors(xLong1))
          If hxPen
            SelectObject_(hDCTemp3, hxBrush)
            SelectObject_(hDCTemp3, hxPen)
            OffX = ParticleCenterX
            OffY = ParticleCenterY
            If xCurSpec(xLong1) > 0.25
              OffX - Cos((xXRot + xLong1 + 1) * #PI / #PeaksCountMaxP) * (xCurSpec(xLong1) - 0.25) * MyMaxSize / 2
              OffY - Sin((xXRot + xLong1 + 1) * #PI / #PeaksCountMaxP) * (xCurSpec(xLong1) - 0.25) * MyMaxSize / 2
              EndIf
            Pie_(hDCTemp3, OffX - MyMaxSize * xCurSpec(               xLong1), OffY - MyMaxSize * xCurSpec(               xLong1), OffX + MyMaxSize * xCurSpec(               xLong1), OffY + MyMaxSize * xCurSpec(               xLong1), OffX - Cos((xXRot + xLong1 +                                        2) * #PI / #PeaksCountMaxP) * MyMaxSize * 2, OffY - Sin((xXRot + xLong1 +                                        2) * #PI / #PeaksCountMaxP) * MyMaxSize * 2, OffX - Cos((xXRot + xLong1                                       ) * #PI / #PeaksCountMaxP) * MyMaxSize * 2, OffY - Sin((xXRot + xLong1                                       ) * #PI / #PeaksCountMaxP) * MyMaxSize * 2)
            OffX = ParticleCenterX
            OffY = ParticleCenterY
            If xCurSpec(xLong1 + #PeaksCountMax) > 0.25
              OffX - Cos((xXRot + #PeaksCountMaxX - xLong1 + #PeaksCountMax + 1) * #PI / #PeaksCountMaxP) * (xCurSpec(xLong1 + #PeaksCountMax) - 0.25) * MyMaxSize / 2
              OffY - Sin((xXRot + #PeaksCountMaxX - xLong1 + #PeaksCountMax + 1) * #PI / #PeaksCountMaxP) * (xCurSpec(xLong1 + #PeaksCountMax) - 0.25) * MyMaxSize / 2
              EndIf
            Pie_(hDCTemp3, OffX - MyMaxSize * xCurSpec(#PeaksCountMax+xLong1), OffY - MyMaxSize * xCurSpec(#PeaksCountMax+xLong1), OffX + MyMaxSize * xCurSpec(#PeaksCountMax+xLong1), OffY + MyMaxSize * xCurSpec(#PeaksCountMax+xLong1), OffX - Cos((xXRot + #PeaksCountMaxX - xLong1 + #PeaksCountMax+1.0 + 2) * #PI / #PeaksCountMaxP) * MyMaxSize * 2, OffY - Sin((xXRot + #PeaksCountMaxX - xLong1 + #PeaksCountMax+1.0 + 2) * #PI / #PeaksCountMaxP) * MyMaxSize * 2, OffX - Cos((xXRot + #PeaksCountMaxX - xLong1 + #PeaksCountMax+1.0) * #PI / #PeaksCountMaxP) * MyMaxSize * 2, OffY - Sin((xXRot + #PeaksCountMaxX - xLong1 + #PeaksCountMax+1.0) * #PI / #PeaksCountMaxP) * MyMaxSize * 2)
            DeleteObject_(hBrushOld)
            DeleteObject_(hPenOld)
            hBrushOld = hxBrush
            hPenOld = hxPen
            Else
            DeleteObject_(hxBrush)
            EndIf
          EndIf
;EndIf
        Next
      SelectObject_(hDCTemp3, hPenOrg)
      DeleteObject_(hxPen)
      SelectObject_(hDCTemp3, hBrushOrg)
      DeleteObject_(hBrushOld)
      Else
      DeleteObject_(hBrushOld)
      EndIf
    EndIf
  EndProcedure


; IDE Options = PureBasic 5.22 LTS (Windows - x64)
; CursorPosition = 23
; Folding = -
; EnableAsm
; Executable = Simple spectrum x4.lpanim.dll
; DisableDebugger
; CompileSourceDirectory
; IncludeVersionInfo
; AddResource = Wallpaper Ex - Encircle deluxe.rc