Author Topic: Chladni Screensaver  (Read 6390 times)

0 Members and 1 Guest are viewing this topic.

Offline rdc

  • Pentium
  • *****
  • Posts: 1495
  • Karma: 140
  • Yes, it is me.
    • View Profile
    • Clark Productions
Chladni Screensaver
« on: November 21, 2006 »
There seems to be a problem with Jofer's code so I am removing this for the moment.
« Last Edit: November 21, 2006 by rdc »

Offline rdc

  • Pentium
  • *****
  • Posts: 1495
  • Karma: 140
  • Yes, it is me.
    • View Profile
    • Clark Productions
Re: Chladni Screensaver
« Reply #1 on: November 21, 2006 »
There is some sort of bug in Jofer's kit, that I need to track down. In case you want to look at the program, here it is as a standard exe. This is not a screensaver. Press any key to exit program.



Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: Chladni Screensaver
« Reply #2 on: November 21, 2006 »
@rdc:

Don't know if you know. But a .scr-file is a simple executable checking for some arguments passed
to (e.g. to show a configuration). If your app checks for key-presses and/or mousemovements, just
rename it to .scr and you can put it in the system32-folder and there you have an almost complete
screensaver (missing parts is the preview / configuration part of course) !
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline rdc

  • Pentium
  • *****
  • Posts: 1495
  • Karma: 140
  • Yes, it is me.
    • View Profile
    • Clark Productions
Re: Chladni Screensaver
« Reply #3 on: November 21, 2006 »
Ah, thanks for the info. I am not sure what the problem is, the kit code or mine, but I can probably just create my own framework for it. I'll give Mr. Google a call. :)

Edit: I guess this should be moved over to works-in-progress, since it isn't quite there. I apologiize for taking up space with this.

« Last Edit: November 21, 2006 by rdc »

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: Chladni Screensaver
« Reply #4 on: November 21, 2006 »
@rdc:

I coded a little screensaver fx two/three years ago :

http://www.weltenkonstrukteur.de/?site=works&prd=TVNoise

It is written in PureBasic - but it uses of course a lot of WinApi for the
screensaver part. I post the source maybe it is of some use for you.

Some points about the source

- the "Common.pb" include isn't import - it just contains some gui-stuff for the
configuration window

- the "ExecutePreview" is a bit faked - I just show a screenshot of the fx here

- check the "deal with the Parameters passed to this program" - part to see
 which arguments are passed to the screensaver ( -> configuration, ->run etc.)


Code: [Select]
IncludeFile "Common.pb"

;===========================================================================
;-ONLY START ONE INSTANCE
;===========================================================================

Global ScreensaverName.s
ScreensaverName = "TV-Noise Screensaver"
;The next function call uses the AppRunning User Library
If AppRunning(ScreensaverName) : End : EndIf

;===========================================================================
;-CONSTANTS
;===========================================================================

#SCREEN_X     = 800
#SCREEN_Y     = 600

#LOOPTIME   = 1000/40  ; 40 Frames in 1000ms (1second)

;===========================================================================
;-GLOBAL FLAGS / VARIABLES / STRUCTURES / ARRAYS
;===========================================================================

Global Parameter.s
Global PrevWinHndlString.s
Global PrevWinHndl.l

Parameter = UCase(ProgramParameter())
If Len(Parameter) > 2
    PrevWinHndlString = RemoveString(Parameter, Left(Parameter, 3), 1)
    Parameter = RemoveString(Parameter, Left(Parameter, 1), 1)
    Parameter = Left(Parameter, 1)
Else
    Parameter = RemoveString(Parameter, Left(Parameter, 1), 1)
    PrevWinHndlString = ProgramParameter()
    If FindString(PrevWinHndlString, "-", 0) <> 0 : PrevWinHndlString = RemoveString(PrevWinHndlString, "-", 1) : EndIf
    If FindString(PrevWinHndlString, "/", 0) <> 0 : PrevWinHndlString = RemoveString(PrevWinHndlString, "/", 1) : EndIf
EndIf
PrevWinHndl = Val(PrevWinHndlString)


;===========================================================================
;-PROCEDURES
;===========================================================================

;simple error checking
Procedure HandleError(result, text.s)
    If result = 0 : MessageRequester("Error", text, #PB_MessageRequester_Ok) : End : EndIf
EndProcedure

;preview window callback
Procedure PreviewCallback(hWnd, Message, wParam, lParam)
    Select Message
        Case #WM_CLOSE
            UnregisterClass_("PreviewWindowClass", GetModuleHandle_(#NULL))
            DestroyWindow_(hWnd)
            End
    EndSelect
    Result = DefWindowProc_(hWnd, Message, wParam, lParam)
    ProcedureReturn Result
EndProcedure

;execute the preview in the little mini monitor in 'Display Properties'
Procedure ExecutePreview()
    PreviewWindowSize.RECT
    GetClientRect_(PrevWinHndl, @PreviewWindowSize)
    PreviewWindowClass.WNDCLASS
    Classname.s = "PreviewWindowClass"
    PreviewWindowClass\style = #CS_HREDRAW | #CS_VREDRAW
    PreviewWindowClass\lpfnWndProc = @PreviewCallback()
    PreviewWindowClass\cbClsExtra = 0
    PreviewWindowClass\cbWndExtra = 0
    PreviewWindowClass\hInstance = GetModuleHandle_(#NULL)
    PreviewWindowClass\hIcon = 0
    PreviewWindowClass\hCursor = 0
    PreviewWindowClass\hbrBackground = 0
    PreviewWindowClass\lpszMenuName = 0
    PreviewWindowClass\lpszClassName = @Classname
    RegisterClass_(PreviewWindowClass)
    hWnd.l = CreateWindowEx_(0, "PreviewWindowClass", "", #WS_CHILD | #WS_VISIBLE, 0, 0, PreviewWindowSize\right, PreviewWindowSize\bottom, PrevWinHndl, 0, GetModuleHandle_(#NULL), 0)
    If hWnd
        CatchImage(1, ?PreviewImage)
        HandleError(CreateGadgetList(hWnd), "Gadget list in preview window could not be created!")
        ImageGadget(1, 0, 0, PreviewWindowSize\right, PreviewWindowSize\bottom, UseImage(1))
        While GetMessage_(Message.MSG, 0, 0, 0)
            TranslateMessage_(Message)
            DispatchMessage_(Message)
        Wend
    EndIf
EndProcedure


; Procedure, die die Farbe in den aktuellen Farbmodus umwandelt.
; (Bei 15-bit bin ich mir nicht sicher ob das so richtig ist, konnte es nicht testen...)
Procedure.l TransformColor(R.b,G.b,b.b)
  Select DrawingBufferPixelFormat()
    Case #PB_PixelFormat_32Bits_RGB
      ProcedureReturn R+G<<8+b<<16
    Case #PB_PixelFormat_32Bits_BGR
      ProcedureReturn b+G<<8+R<<16
    Case #PB_PixelFormat_24Bits_RGB
      ProcedureReturn R+G<<8+b<<16
    Case #PB_PixelFormat_24Bits_BGR
      ProcedureReturn b+G<<8+R<<16
    Case #PB_PixelFormat_16Bits
      ProcedureReturn b>>3+(G&%11111100)<<3+(R&%11111000)<<8
    Case #PB_PixelFormat_15Bits
      ProcedureReturn R&%11111000>>3+(G&%11111000)<<2+(b&%11111000)<<7
  EndSelect
EndProcedure

; For Speed-Optimation - Original by Danilo!

Procedure InitGameTimer()
  ; initialize highres timing function TimeGetTime_()
  Shared _GT_DevCaps.TIMECAPS
  timeGetDevCaps_(_GT_DevCaps,SizeOf(TIMECAPS))
  timeBeginPeriod_(_GT_DevCaps\wPeriodMin)
EndProcedure

Procedure StopGameTimer()
  ; de-initialize highres timing function TimeGetTime_()
  Shared _GT_DevCaps.TIMECAPS
  timeEndPeriod_(_GT_DevCaps\wPeriodMin)
EndProcedure


;run the fullscreen screensaver code
Procedure ExecuteScreenSaver()

    If InitSprite()=0 Or InitMouse()=0 Or InitKeyboard()=0
     MessageRequester("ERROR","Cant init DirectX !",#MB_ICONERROR):End
   EndIf

    If OpenScreen(#SCREEN_X, #SCREEN_Y, 32, "weltenkonstrukteur.de")=0
      MessageRequester("ERROR","Cant open screen !",#MB_ICONERROR):End
    EndIf

    StartDrawing(ScreenOutput())
      Pitch        = DrawingBufferPitch()
    StopDrawing()

    White = TransformColor(255,255,255)
    Noise = 0
    Carry = 0
    Index = 0
    Seed  = $12345
 
;    InitScreenSaver()

    SystemParametersInfo_(#SPI_SCREENSAVERRUNNING, #TRUE, @oldval, 0)
    ShowCursor_(0)

    While quit=0
      FlipBuffers()
      ExamineMouse()
      ExamineKeyboard()

        StartDrawing(ScreenOutput())     
          For y = 0 To #SCREEN_Y -1     
            For x = 0 To #SCREEN_X -1
              noise = seed;
              noise = noise >> 3
              noise = noise ! seed
              carry = noise & 1
              seed = seed >> 1
              seed = seed | ( carry << 30)
              noise = noise & $FF
              *Screen.LONG = DrawingBuffer()
              *Screen + (Pitch * y) +  (x*4) 
              *Screen\l = (noise<<16) | (noise << 8) | noise
            Next x
          Next y
        StopDrawing()

       While ( timeGetTime_()-LoopTimer )<#LOOPTIME : Delay(1) : Wend
        LoopTimer = timeGetTime_()
   
       If KeyboardPushed(#PB_Key_All)
        quit = 2
       EndIf
   
       If MouseDeltaX() <> 0 Or MouseDeltaY() <> 0 Or MouseWheel() <> 0 Or MouseButton(1) <> 0 Or MouseButton(2) <> 0 Or MouseButton(3) <> 0
        quit = 2
       EndIf         
    Wend

    ShowCursor_(1)
    SystemParametersInfo_(#SPI_SCREENSAVERRUNNING, #FALSE, @oldval, 0)
    End
EndProcedure


;configuration window
Procedure ExecuteConfiguration()
;    MessageRequester("Saver - Config", "Nichts einzurichten!"+Chr(13)+"(c)coming art")


  Open_Window_0()

  Repeat
 
    Event = WaitWindowEvent()
 
    If Event = #PB_EventGadget
   
      ;Debug "WindowID: " + Str(EventWindowID())
   
      GadgetID = EventGadgetID()
   
      If GadgetID = #Button_0
        End       
      EndIf
   
    EndIf
 
  Until Event = #PB_EventCloseWindow

  End
EndProcedure

;===========================================================================
;-MAIN
;===========================================================================

;deal with the Parameters passed to this program
Select Parameter
    Case "" ;double clicked
        ExecuteConfiguration()
    Case "A" ;check password
        End
    Case "C" ;'Settings' button clicked in the screensaver dialog
        ExecuteConfiguration()
    Case "P" ;when the preview is requested in the screensaver dialog by selecting this screensaver
        ExecutePreview()
    Case "S" ;launch the main screensaver after an interval or by pressing 'Preview' in the dialog
        ExecuteScreenSaver()
EndSelect

End

;===========================================================================
;-DATA
;===========================================================================

DataSection
    PreviewImage:
        IncludeBinary "Preview.bmp"
EndDataSection
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline rdc

  • Pentium
  • *****
  • Posts: 1495
  • Karma: 140
  • Yes, it is me.
    • View Profile
    • Clark Productions
Re: Chladni Screensaver
« Reply #5 on: November 21, 2006 »
Awesome, man. Thank you. Karma up!

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: Chladni Screensaver
« Reply #6 on: November 21, 2006 »
Awesome, man. Thank you. Karma up!

Hehe ... thanks mate ;)
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17414
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Chladni Screensaver
« Reply #7 on: November 21, 2006 »
Geat job Rick! I am amazed at the variety of images you've managed to get out of this technique!
Shockwave ^ Codigos
Challenge Trophies Won:

Offline rdc

  • Pentium
  • *****
  • Posts: 1495
  • Karma: 140
  • Yes, it is me.
    • View Profile
    • Clark Productions
Re: Chladni Screensaver
« Reply #8 on: November 21, 2006 »
Thanks! I am amazed myself, to be honest. Hopefully I can turn this into a proper screensaver.


Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: Chladni Screensaver
« Reply #9 on: November 22, 2006 »
Ahh ... one more comment to my source. All WinApi functions end with an underscore "_".
There is no need to import or declare them in purebasic. Guess the WinApi-stuff is the stuff
you should look for...

If you have any questions feel free to ask...
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline rdc

  • Pentium
  • *****
  • Posts: 1495
  • Karma: 140
  • Yes, it is me.
    • View Profile
    • Clark Productions
Re: Chladni Screensaver
« Reply #10 on: November 27, 2006 »
I changed my code a bit and now it seems to work correctly with Jofer's screensaver kit. Let me know if you have problems.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17414
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Chladni Screensaver
« Reply #11 on: November 27, 2006 »
Seems to work fine here now Rick :)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline rdc

  • Pentium
  • *****
  • Posts: 1495
  • Karma: 140
  • Yes, it is me.
    • View Profile
    • Clark Productions
Re: Chladni Screensaver
« Reply #12 on: November 27, 2006 »
Ah, good. It seemed okay on my machine, but you never know. :)

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: Chladni Screensaver
« Reply #13 on: November 27, 2006 »
Works like a charme here too ... as I can see you implemented everything like preview and
settings. Well done !!!
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline rdc

  • Pentium
  • *****
  • Posts: 1495
  • Karma: 140
  • Yes, it is me.
    • View Profile
    • Clark Productions
Re: Chladni Screensaver
« Reply #14 on: November 27, 2006 »
Thanks man.