CERN

Share your advanced PureBasic knowledge/code with the community.
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

CERN

Post by Hroudtwolf »

Hi,

My phantasie about the look of black holes. ^^

Best regards

Wolf

Code: Select all

; Hroudtwolf
; 09/10/2008
; PureBasic 4.2x
; Linux, OS X, Windows
#D3DBLEND_ONE             = 2
#D3DBLEND_SRCALPHA        = 5

#UPDATETIME               = 25

Structure tParticle
   lRadius  .l
   fAngle   .f
   lPartSize.l
EndStructure

Structure tParticleSprite
   *Sprite2D
   *Sprite3D
EndStructure

Declare.f gSin                   ( fAngle.f )
Declare.f gCos                   ( fAngle.f )
Declare.l CreateBlackHole        ( Particles.tParticle () , lAmount.l )
Declare.l DisplayBlackHole       ( lX.l , lY.l , *ParticleSprite.tParticleSprite , Particles.tParticle () )
Declare.l CreateParticleSprite   ()

Define.LONG *Window
Define      *Particle
Define      lStartTime  .l
Define      lLatencyTime.l

NewList Particles.tParticle ()

If Not InitSprite () Or Not InitSprite3D ()
   End
EndIf

*Window = OpenWindow ( #PB_Any , #PB_Ignore , #PB_Ignore , 800 , 600 , "CERN :: By Marc-Sven Rudolf 2008 (c) (Hroudtwolf)" , #PB_Window_ScreenCentered | #PB_Window_SystemMenu )
If Not *Window
   End
EndIf

; Just for demonstrative purpose
CompilerSelect #PB_Compiler_OS
   CompilerCase #PB_OS_Windows
   OpenWindowedScreen ( *Window\l , 0 , 0 , 800 , 600 , #False , 0 , 0 )
   CompilerDefault
   OpenWindowedScreen ( WindowID ( *Window ) , 0 , 0 , 800 , 600 , #False , 0 , 0 )
CompilerEndSelect

CreateBlackHole ( Particles () , 600 )
*Particle = CreateParticleSprite  ()

Repeat
   lStartTime = ElapsedMilliseconds ()
   
   Repeat
      Select WindowEvent ()      
         Case #PB_Event_CloseWindow 
         End
         
         Case #Null
         Break 1
      EndSelect
   ForEver
   
   FlipBuffers ()
   ClearScreen ( $000000 )
 
   DisplayBlackHole ( 380 , 290 , *Particle , Particles () )
 
   If lLatencyTime < #UPDATETIME
      Delay ( #UPDATETIME - lLatencyTime )
   EndIf    
ForEver

Procedure.f gSin ( fAngle.f )

   ProcedureReturn Sin ( fAngle * ( 2 * 3.14159265 / 360 ) )
EndProcedure

Procedure.f gCos ( fAngle.f )

   ProcedureReturn Cos ( fAngle * ( 2 * 3.14159265 / 360 ) )
EndProcedure

Procedure.l CreateParticleSprite  ()
   Protected *ParticleSprite  .tParticleSprite = AllocateMemory ( SizeOf ( tParticleSprite ) )
   Protected fD               .f
   Protected lX               .l
   Protected lY               .l
   
   *ParticleSprite\Sprite2D = CreateSprite   ( #PB_Any , 16 , 16 , #PB_Sprite_Texture )
   *ParticleSprite\Sprite3D = CreateSprite3D ( #PB_Any , *ParticleSprite\Sprite2D )
   
   If Not StartDrawing( SpriteOutput ( *ParticleSprite\Sprite2D ) )
      ProcedureReturn #Null
   EndIf
   For lY = -7 To 7
      For lX = -7 To 7
         fD = Sqr( lX * lX + lY * lY )
         If fD < 7.0
            fD = 7.0 - fD
            Plot( 7 + lX , 7 + lY , RGB ( 16 * fD , 16 * fD , 32 * fD ) )
         EndIf
      Next
   Next
   StopDrawing()
 
   ProcedureReturn *ParticleSprite
EndProcedure

Procedure.l CreateBlackHole  ( Particles.tParticle () , lAmount.l )
   Protected lI.l
   
   For lI = 0 To lAmount
      AddElement ( Particles () )
      Particles ()\lRadius   = 100 + Random ( 300 )
      Particles ()\fAngle    = Random ( 359 )
      Particles ()\lPartSize = 48 + Random ( 48 )
   Next lI
   
   ProcedureReturn #Null
EndProcedure

Procedure.l DisplayBlackHole  ( lX.l , lY.l , *ParticleSprite.tParticleSprite , Particles.tParticle () )
   Protected lI.l
   
   Start3D ()
      Sprite3DBlendingMode ( #D3DBLEND_SRCALPHA , #D3DBLEND_ONE )
           
      ForEach Particles ()
         ZoomSprite3D ( *ParticleSprite\Sprite3D , Particles ()\lPartSize , Particles ()\lPartSize )
         DisplaySprite3D ( *ParticleSprite\Sprite3D , lX + gSin ( Particles ()\fAngle ) * Particles ()\lRadius , lY + GCos( Particles ()\fAngle ) * Particles ()\lRadius , 255 - ( Particles ()\lRadius / 2 ) )
         Particles ()\fAngle + ( ( 400 / Particles ()\lRadius ) + 1 )
         If Particles ()\fAngle > 359
            Particles ()\fAngle = 0
            Particles ()\lRadius - 1
         EndIf
         If Particles ()\lRadius < 50
            Particles ()\lRadius = 400
         EndIf
      Next
   Stop3D ()
   
   ProcedureReturn #Null
EndProcedure
Last edited by Hroudtwolf on Thu Sep 11, 2008 2:39 pm, edited 1 time in total.
zikitrake
Addict
Addict
Posts: 868
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Post by zikitrake »

:shock: Really nice! The end of world is here! :lol:
PB 6.21 beta, PureVision User
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

Awsome, Hroudtwolf! I love it. :D

I'm going to leave this running all night just for fun.
User avatar
idle
Always Here
Always Here
Posts: 5839
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Post by idle »

very cool
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post by Rook Zimbabwe »

Much REPs to you buddy!

I saw this outside my window this morning... should I be concerned? :shock:

{{EDIT: }} Hurricane Ike is what is outside my window... coming right at me... Mommy! :shock:
Last edited by Rook Zimbabwe on Fri Sep 12, 2008 3:16 am, edited 1 time in total.
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
Thalius
Enthusiast
Enthusiast
Posts: 711
Joined: Thu Jul 17, 2003 4:15 pm
Contact:

Post by Thalius »

outside YOUR Window ??? Wait is there actually ANYTHING outside the Screen ??? :shock:

Heck .. CERN is like a few Kilometres away from me .. what should i say ? =P ( I swear i saw a Ghoa'Ould Glider this morning at the Mc'Donalds drive-in ... ) :lol:

Tho back to Topic ! This Blackhole looks cool ! Vewwy ncie Effect :)
"In 3D there is never enough Time to do Things right,
but there's always enough Time to make them *look* right."
"psssst! i steal signatures... don't tell anyone! ;)"
Heathen
Enthusiast
Enthusiast
Posts: 498
Joined: Tue Sep 27, 2005 6:54 pm
Location: At my pc coding..

Post by Heathen »

Pretty cool. That would make a nice screensaver.
I love Purebasic.
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Post by Hroudtwolf »

Thanks for the homages @all ^^

I made a little screensaver with the black hole fx.
http://www.file-upload.net/download-110 ... n.scr.html *UPDATED (TIME 23:50)
(VISTA compatible)

Best regards

Wolf
Last edited by Hroudtwolf on Fri Sep 12, 2008 12:31 pm, edited 2 times in total.
MrMat
Enthusiast
Enthusiast
Posts: 762
Joined: Sun Sep 05, 2004 6:27 am
Location: England

Post by MrMat »

That is beautiful :)
Mat
byo
Enthusiast
Enthusiast
Posts: 635
Joined: Mon Apr 02, 2007 1:43 am
Location: Brazil

Post by byo »

Very beautiful indeed for such a small code.
Proud registered Purebasic user.
Because programming should be fun.
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post by djes »

Very nice :D
Pantcho!!
Enthusiast
Enthusiast
Posts: 538
Joined: Tue Feb 24, 2004 3:43 am
Location: Israel
Contact:

Post by Pantcho!! »

i got a new screen saver... i did not had a screen saver since 4+ years!

thanks
Wolf
Enthusiast
Enthusiast
Posts: 232
Joined: Sat Apr 03, 2004 12:00 pm
Location: S.T

Post by Wolf »

Image
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

Very hypnotic. Me likes. :)
yrreti
Enthusiast
Enthusiast
Posts: 546
Joined: Tue Oct 31, 2006 4:34 am

Post by yrreti »

Nice scr Hroudtwolf
I have a question though. Just what do you have to do to your program to make your program run as an scr?
I've searched on this site before and found screen savers. But I never found any examples of how to do it.
citystate gave the most info, but not enough for me to understand. Could you please show me some code or
give me some understanding of how to do it.
I really would appreciate it, and thank you for any help you can give me.
Post Reply