Spirale en mouvement

Partagez votre expérience de PureBasic avec les autres utilisateurs.
Avatar de l’utilisateur
threedslider
Messages : 479
Inscription : dim. 01/juil./2018 22:38

Re: Spirale en mouvement

Message par threedslider »

Une autre version, cette fois ci un peu plus long mais toujours passionnant de voir de trou noir 8O :mrgreen:

Version 2 :

Code : Tout sélectionner

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Coded with Purebasic v.6.0 by threedslider 24/07/2022
;;
;; Update to my little code for experimentation :) 
;; (30/07/2026) with Purebasic v. 6.40
;;
;; Inspired by Idle suggestion about my code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

InitSprite()
InitKeyboard()

OpenWindow(1, 0,0,800,600,"Spiral in moving", #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(1),0,0,800,600,0,0,0)
SetFrameRate(30)

Repeat
  ExamineKeyboard()
  event = WindowEvent()
  ClearScreen(RGB(0,0,0))
  
  StartDrawing(ScreenOutput())
  For x = 0 To 3600
    
    move.f  +  1/10 * Exp(1/1000*move-x) 
    
      spiral_x.f =  100 * Exp((move-x)/200)*Cos(move+x)
      
      spiral_y.f =  100 * Exp((move-x)/200)*Sin(move+x)
     
    Line(spiral_x+400, spiral_y+300, 3, 5,  RGB(Random(255),Random(255),Random(255)))
      
  Next
    
  StopDrawing()
  
  Delay(1) : FlipBuffers()
  
Until event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
End
Avatar de l’utilisateur
threedslider
Messages : 479
Inscription : dim. 01/juil./2018 22:38

Re: Spirale en mouvement

Message par threedslider »

Allez une 3e version toute aussi impressionnante ! 8O :mrgreen:

Version 3 :

Code : Tout sélectionner

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Coded with Purebasic v.6.0 by threedslider 24/07/2022
;;
;; Update to my little code for experimentation :) 
;; (30/07/2026) with Purebasic v. 6.40
;;
;; Inspired by Idle suggestion about my code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

InitSprite()
InitKeyboard()

OpenWindow(1, 0,0,800,600,"Spiral in moving", #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(1),0,0,800,600,0,0,0)
SetFrameRate(30)

Repeat
  ExamineKeyboard()
  event = WindowEvent()
  ClearScreen(RGB(0,0,0))
  
  StartDrawing(ScreenOutput())
  For x = 0 To 3600
    
    move.f  +  Exp(1/10000*move-x)
    
      spiral_x.f =  100 * Exp((move-x)/600)*Cos(move+x)
      
      spiral_y.f =  100 * Exp((move-x)/600)*Sin(move+x)
     
    Line(spiral_x+400, spiral_y+300, 3, 5,  RGB(Random(255),Random(255),Random(255)))
      
  Next
    
  StopDrawing()
  
  Delay(1) : FlipBuffers()
  
Until event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
End
Avatar de l’utilisateur
kernadec
Messages : 1634
Inscription : ven. 25/avr./2008 11:14

Re: Spirale en mouvement

Message par kernadec »

bsr threedslider
Tout d 'abord Merci pour ces nouveaux codes intéressants
Voici une vidéo intéressante qui parle du cosmos
https://www.youtube.com/watch?v=M1Jkpr21UxE

la photographie de l électron réussie
https://share.google/JAA7zmxnNC6iVVy86

Cordialement
Avatar de l’utilisateur
threedslider
Messages : 479
Inscription : dim. 01/juil./2018 22:38

Re: Spirale en mouvement

Message par threedslider »

Bonjour kernadec,

De rien pour ça :D

Merci pour ton lien du cosmos, très intéressant !

Pour l'image de l'électron j'ai pas vu l'image mais j'ai cherché par moi même 8O , IBM avait pris l'image du molécule en 2009 sur cette vidéo : https://www.youtube.com/watch?v=jnLRl_74BZs&t=1s

Et puis l'électron pris en 2013 par Aneta Stodolna : https://www.youtube.com/shorts/Tb8amuZXupU
Avatar de l’utilisateur
kernadec
Messages : 1634
Inscription : ven. 25/avr./2008 11:14

Re: Spirale en mouvement

Message par kernadec »

bjr threedslider
pour tes codes spirale, j ai essayer plein de trucs graphiques les valeurs absolues etc.
mais le trou noir est toujours de retour... C'est ouf impossible de savoir d ou il sors :?:
merci pour les liens intéressants.
photographier l'électron en temps réel est quand même ouf.. 8O
Cordialement
Avatar de l’utilisateur
threedslider
Messages : 479
Inscription : dim. 01/juil./2018 22:38

Re: Spirale en mouvement

Message par threedslider »

Hello kernadec :D

si tu veux modifier le trou noir tu peux inverser le move dans Exponentiel :mrgreen:

Tu verras les effets inverse ^^

Voici le code :

Code : Tout sélectionner

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Coded with Purebasic v.6.0 by threedslider 24/07/2022
;;
;; Update to my little code for experimentation :) 
;; (30/07/2026) with Purebasic v. 6.40
;;
;; Inspired by Idle suggestion about my code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

InitSprite()
InitKeyboard()

OpenWindow(1, 0,0,800,600,"Spiral in moving", #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(1),0,0,800,600,0,0,0)
SetFrameRate(30)

Repeat
  ExamineKeyboard()
  event = WindowEvent()
  ClearScreen(RGB(0,0,0))
  
  StartDrawing(ScreenOutput())
  For x = 0 To 3600
    
    move.f  +  1/1000
    
      spiral_x.f =  100 * Exp((-move+x)/600)*Cos(move+x)
      
      spiral_y.f =  100 * Exp((-move+x)/600)*Sin(move+x)
     
    Line(spiral_x+400, spiral_y+300, 3, 5,  RGB(Random(255),Random(255),Random(255)))
      
  Next
    
  StopDrawing()
  
  Delay(1) : FlipBuffers()
  
Until event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
End
Oui photographier les atomes c'est un truc de ouf ! Maintenant on aimerait voir en mouvement !! ?

Je pense que l’antimatière c'est hors d'espace mais personne n'a jamais vu encore 8O
Avatar de l’utilisateur
kernadec
Messages : 1634
Inscription : ven. 25/avr./2008 11:14

Re: Spirale en mouvement

Message par kernadec »

bjr threedslider
eh ben la c est wouaaaoouuu 8O super code
c est remarquable cela pourrait etre un truc comme ca
car ce code est l' effet inverse de ce que pourrait donner
le big bang, il part d'un atome qui passe par la spirale
jusqu'au trou noir qui doit être cette matière noire
qui absorbe toute la lumière et qui la concentre
en un point quelques part et qui recommence son expension
de cette manière à l"infini.

ps: pour info je ne suis pas physicien :mrgreen:

au fait, ton code chez moi fonctionne pas sur PB 6.40
mais avec la version PB5.73

cordialement
Avatar de l’utilisateur
threedslider
Messages : 479
Inscription : dim. 01/juil./2018 22:38

Re: Spirale en mouvement

Message par threedslider »

Bonjour kernadec,

Oui c'est une idée géniale comme simulation, il faudrait une constante qui permet de simuler la notion du temps inverse général car tout local comme nébuleuse, galaxies ou même amas de galaxies, trou noir qui simulent spécifiquement en un point blanc et puis le big bang qui re explose à l'infini sa demande de réglage finement !! 8O :mrgreen:

Moi aussi je suis pas astrophysicien non plus mais c'est passionnant de faire sois même :D

Tiens ! Bizarre mon PB 6.40 marche bien ici :roll:

La je suis en train de faire la simulation comme prototype de l'explosion d'une nova.... c'est beaucoup de technique sa 8O 8)
Avatar de l’utilisateur
threedslider
Messages : 479
Inscription : dim. 01/juil./2018 22:38

Re: Spirale en mouvement

Message par threedslider »

Bon j'ai simplifié et assez moche comme une explosion d'une nova :D

Voici le code :

Code : Tout sélectionner

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Coded with Purebasic v.6.40 by threedslider 01/08/2026
;;
;; Based by Idle idea about my code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

InitSprite()
InitKeyboard()

OpenWindow(1, 0,0,800,600,"Nova explosion", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(1),0,0,800,600,0,0,0)
SetFrameRate(60)

#Particles = 1200

Global move.f = 0.0
Global angle.f = 0.0
Global size_ball.f = 0.0
Global size_point_zero.f = 80.0
Global result.f = 0.0


Global veloc_parti.f = 0.0

Structure Particle
  x.f
  y.f
  vx.f
  vy.f
  life.f
  size.f
  color.i
EndStructure

Global Dim p.Particle(#Particles)


Procedure ResetParticle(*p.Particle)
  
  angle.f = Random(6283)/1000.0
  speed.f = Random(300)/10 + 2
  
  *p\x = 400
  *p\y = 300
  
  *p\vx = Cos(angle)*speed
  *p\vy = Sin(angle)*speed
  
  *p\life = Random(1000)/1000 + 0.5
  *p\size = Random(3)+1
  
EndProcedure

Procedure Nova_Explosion()
  
   
  
   ClearScreen(RGB(0,0,0))
  
  
   StartDrawing(ScreenOutput())
;   
   For i=0 To #Particles-1
     ;    
     
     If result >= 0 And result <= 80.0
       ; mouvement explosion
      p(i)\x + p(i)\vx
      p(i)\y + p(i)\vy
    Else
      p(i)\x + 0.0
      p(i)\y + 0.0
    EndIf
      
    ; ralentissement espace interstellaire
    p(i)\vx * 0.992
    p(i)\vy * 0.992
    
     
    p(i)\life - 0.004
    
    
    ; couleur selon durée de vie
    If p(i)\life > 0.66
      
      col = RGB(255,255,200)
      
    ElseIf p(i)\life > 0.33
      
      col = RGB(255,120,20)
      
    Else
      
      col = RGB(180,20,0)
      
    EndIf
    
    Circle(400,300,result,RGB(150,150,255))
    
    Line(p(i)\x,p(i)\y,3, 5 ,col)

    ; nouvelle explosion quand morte
    If p(i)\life <= 0 Or p(i)\x<0 Or p(i)\x>800 Or p(i)\y<0 Or p(i)\y>600
      ResetParticle(@p(i))
    EndIf
    
  Next
  
  StopDrawing()
  
EndProcedure

  For i=0 To #Particles-1
    ResetParticle(@p(i))
  Next
  


Repeat
  
  ExamineKeyboard()
  event = WindowEvent()
  
  ;ClearScreen(RGB(0,0,0))
  
  size_ball + 1/10
  
  result = size_point_zero-size_ball
  

  Nova_Explosion()
  
  If result = 0
    veloc_parti + 1/10000
  EndIf
  
  If veloc_parti < 0.993
    veloc_parti = 0.992
  EndIf
  

  
  Delay(1)
  FlipBuffers()
  
Until event=#PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)

End
Enjoy !
Avatar de l’utilisateur
threedslider
Messages : 479
Inscription : dim. 01/juil./2018 22:38

Re: Spirale en mouvement

Message par threedslider »

A black hole simulé approximativement :)

Code : Tout sélectionner

; ============================================================
; BLACK HOLE SIMULATION - INTERPOLATED CIRCULAR LENS
; ============================================================
;   - Black hole moving to the right
;   - Stars scrolling to the left
;   - Circular gravitational lens
;   - Gradual interpolation at entry
;   - Progressive attraction toward the center
;   - Maximum deformation near the horizon
;   - Gradual interpolation at exit
;   - Radial + tangential deformation
;   - Dynamic light flow
;   - Perfectly black horizon
; ============================================================

EnableExplicit

; ============================================================
; CONFIGURATION
; ============================================================

#WIDTH = 1000
#HEIGHT = 700
#STARS = 700

#BLACK_HOLE_X = 180
#BLACK_HOLE_Y = 350

#HORIZON_X = 90
#HORIZON_Y = 55

#DISK_INNER = 95
#DISK_OUTER = 240

#BLACK_HOLE_SPEED = 65.0
#BACKGROUND_SPEED = 28.0

#LENS_RADIUS = 300.0
#LENS_STRENGTH = 1.35

#ATTRACTION_STRENGTH = 0.42

#TANGENTIAL_STRENGTH = 28.0

; ============================================================
; STAR STRUCTURE
; ============================================================

Structure Star
x.f
y.f
size.f
brightness.f
EndStructure

; ============================================================
; GLOBAL VARIABLES
; ============================================================

Global Dim Stars.Star(#STARS - 1)

Global Running = #True
Global Time.f = 0.0

Global HoleX.f = #BLACK_HOLE_X
Global HoleY.f = #BLACK_HOLE_Y

Global BackgroundOffset.f = 0.0

Define i

; ============================================================
; MINIMUM FUNCTION
; ============================================================

Procedure.i Min(a.i, b.i)

If a < b
ProcedureReturn a
EndIf

ProcedureReturn b

EndProcedure

; ============================================================
; MAXIMUM FUNCTION
; ============================================================

Procedure.i Max(a.i, b.i)

If a > b
ProcedureReturn a
EndIf

ProcedureReturn b

EndProcedure

; ============================================================
; FLOAT MINIMUM
; ============================================================

Procedure.f MinF(a.f, b.f)

If a < b
ProcedureReturn a
EndIf

ProcedureReturn b

EndProcedure

; ============================================================
; FLOAT MAXIMUM
; ============================================================

Procedure.f MaxF(a.f, b.f)

If a > b
ProcedureReturn a
EndIf

ProcedureReturn b

EndProcedure

; ============================================================
; SMOOTHSTEP INTERPOLATION
; ============================================================

Procedure.f SmoothStep(value.f)

Protected v.f

v = MinF(1.0, MaxF(0.0, value))

ProcedureReturn v * v * (3.0 - 2.0 * v)

EndProcedure

; ============================================================
; STAR INITIALIZATION
; ============================================================

RandomSeed(12345)

For i = 0 To #STARS - 1

Stars(i)\x = Random(#WIDTH - 1)
Stars(i)\y = Random(#HEIGHT - 1)
Stars(i)\size = 1.0 + Random(2)
Stars(i)\brightness = 0.35 + Random(65) / 100.0

Next

; ============================================================
; WINDOW CREATION
; ============================================================

If OpenWindow(0, 0, 0, #WIDTH/DesktopResolutionX(), #HEIGHT/DesktopResolutionY(), "Black Hole - Dynamic Gravitational Lens", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

CanvasGadget(0, 0, 0, #WIDTH, #HEIGHT)

Else

MessageRequester("Error", "Unable to create the window.")

End

EndIf

; ============================================================
; STARS + GRAVITATIONAL LENS
; ============================================================

Procedure DrawStars()

Protected i
Protected c

Protected starX.f
Protected starY.f

Protected dx.f
Protected dy.f

Protected distance.f

Protected lensStart.f
Protected lens.f

Protected attraction.f
Protected attractionCore.f

Protected exitInterpolation.f

Protected angle.f
Protected distortedAngle.f

Protected radial.f
Protected radialWarp.f

Protected tangentialWarp.f
Protected tangentialAngle.f

Protected cycle.f
Protected cycle2.f
Protected glass.f

Protected warpedX.f
Protected warpedY.f

; ----------------------------------------------------------
; STAR LOOP
; ----------------------------------------------------------

For i = 0 To #STARS - 1

; --------------------------------------------------------
; BACKGROUND SCROLLING TO THE LEFT
; --------------------------------------------------------

starX = Stars(i)\x - BackgroundOffset

If starX < -20

starX = starX + #WIDTH

EndIf

starY = Stars(i)\y

; --------------------------------------------------------
; DISTANCE FROM THE BLACK HOLE
; --------------------------------------------------------

dx = starX - HoleX
dy = starY - HoleY

distance = Sqr(dx * dx + dy * dy)

; --------------------------------------------------------
; ORIGINAL POSITION
; --------------------------------------------------------

warpedX = starX
warpedY = starY

; ========================================================
; GRAVITATIONAL LENS
; ========================================================

If distance < #LENS_RADIUS And distance > #HORIZON_X

; ------------------------------------------------------
; STAR ANGLE
; ------------------------------------------------------

angle = ATan2(dy, dx)

; ------------------------------------------------------
; ENTRY PROGRESSION
; ------------------------------------------------------
;
; 0.0 = outside the lens
; 1.0 = horizon
;
; ------------------------------------------------------

lensStart = (#LENS_RADIUS - distance) / (#LENS_RADIUS - #HORIZON_X)

lensStart = MinF(1.0, MaxF(0.0, lensStart))

; ------------------------------------------------------
; SMOOTH ENTRY INTERPOLATION
; ------------------------------------------------------

lens = SmoothStep(lensStart)

; ------------------------------------------------------
; PROGRESSIVE ACCENTUATION
; ------------------------------------------------------

lens = Pow(lens, 1.65)

; ======================================================
; ATTRACTION TOWARD THE CENTER
; ======================================================
;
; The attraction starts weak and progressively increases
; as the star approaches the horizon.
;
; ======================================================

attraction = lens * lens

; ------------------------------------------------------
; STRENGTHENING NEAR THE HORIZON
; ------------------------------------------------------

If distance < #HORIZON_X * 2.5

attractionCore = (#HORIZON_X * 2.5 - distance) / (#HORIZON_X * 1.5)

attractionCore = MinF(1.0, MaxF(0.0, attractionCore))

attractionCore = SmoothStep(attractionCore)

attraction = attraction * 0.65 + attractionCore * 0.35

EndIf

; ======================================================
; EXIT INTERPOLATION
; ======================================================
;
; When the star leaves the area near the black hole,
; the deformation is gradually released.
;
; ======================================================

exitInterpolation = distance / #LENS_RADIUS

exitInterpolation = MinF(1.0, MaxF(0.0, exitInterpolation))

exitInterpolation = SmoothStep(exitInterpolation)

; ------------------------------------------------------
; FINAL LENS PROFILE
; ------------------------------------------------------

lens = lens * (1.0 - exitInterpolation * 0.28)

; ------------------------------------------------------
; FINAL ATTRACTION
; ------------------------------------------------------

attraction = attraction * (1.0 - exitInterpolation * 0.35)

attraction = attraction * #ATTRACTION_STRENGTH

; ======================================================
; ANGULAR DEFORMATION
; ======================================================

cycle = Sin(angle * 2.0 + Time * 0.35)

cycle = cycle * lens

cycle = cycle * #LENS_STRENGTH

; ------------------------------------------------------
; SECOND WAVE
; ------------------------------------------------------

cycle2 = Sin(angle * 5.0 - Time * 0.55 + distance * 0.018)

cycle2 = cycle2 * lens * 0.28

; ------------------------------------------------------
; FINAL ANGLE
; ------------------------------------------------------

distortedAngle = angle + cycle + cycle2

; ======================================================
; RADIAL DEFORMATION
; ======================================================

radialWarp = lens * lens * 125.0

radial = distance + radialWarp

; ======================================================
; ATTRACTION TOWARD THE CENTER
; ======================================================

radial = radial * (1.0 - attraction)

; ------------------------------------------------------
; HORIZON PROTECTION
; ------------------------------------------------------

If radial < #HORIZON_X + 1.0

radial = #HORIZON_X + 1.0

EndIf

; ------------------------------------------------------
; DEFORMED RADIAL POSITION
; ------------------------------------------------------

warpedX = HoleX + Cos(distortedAngle) * radial

warpedY = HoleY + Sin(distortedAngle) * radial

; ======================================================
; TANGENTIAL DEFORMATION
; ======================================================

tangentialAngle = distortedAngle + 1.5707963

glass = Sin(angle * 4.0 - Time * 0.75 + distance * 0.025)

glass = glass * lens

tangentialWarp = glass * #TANGENTIAL_STRENGTH

warpedX = warpedX + Cos(tangentialAngle) * tangentialWarp

warpedY = warpedY + Sin(tangentialAngle) * tangentialWarp

; ======================================================
; SECOND TANGENTIAL DEFORMATION
; ======================================================

glass = Sin(angle * 7.0 + Time * 0.42 + distance * 0.035)

glass = glass * lens * lens

warpedX = warpedX + Cos(tangentialAngle) * glass * 16.0

warpedY = warpedY + Sin(tangentialAngle) * glass * 16.0

; ======================================================
; RELEASE ZONE AFTER THE HORIZON
; ======================================================
;
; This zone gradually releases the attraction
; as the star emerges.
;
; ======================================================

If distance > #HORIZON_X * 1.2 And distance < #HORIZON_X * 3.0

exitInterpolation = (distance - #HORIZON_X * 1.2) / (#HORIZON_X * 1.8)

exitInterpolation = MinF(1.0, MaxF(0.0, exitInterpolation))

exitInterpolation = SmoothStep(exitInterpolation)

; ------------------------------------------------------
; RADIAL RELEASE
; ------------------------------------------------------

radialWarp = (1.0 - exitInterpolation) * lens * 18.0

warpedX = warpedX + Cos(distortedAngle) * radialWarp

warpedY = warpedY + Sin(distortedAngle) * radialWarp

; ------------------------------------------------------
; TANGENTIAL RELEASE
; ------------------------------------------------------

glass = (1.0 - exitInterpolation) * lens

warpedX = warpedX + Cos(tangentialAngle) * glass * 10.0

warpedY = warpedY + Sin(tangentialAngle) * glass * 10.0

EndIf

; ======================================================
; EXTREME DEFORMATION AROUND THE HORIZON
; ======================================================

If distance < #HORIZON_X * 2.0

lensStart = (#HORIZON_X * 2.0 - distance) / #HORIZON_X

lensStart = MinF(1.0, MaxF(0.0, lensStart))

lensStart = SmoothStep(lensStart)

radialWarp = lensStart * lensStart * 24.0

warpedX = warpedX + Cos(distortedAngle) * radialWarp

warpedY = warpedY + Sin(distortedAngle) * radialWarp

EndIf

EndIf

; ========================================================
; OCCULTATION BY THE HORIZON
; ========================================================

If distance > #HORIZON_X

; ------------------------------------------------------
; NORMAL BRIGHTNESS
; ------------------------------------------------------

c = Int(255 * Stars(i)\brightness)

; ------------------------------------------------------
; BRIGHTNESS INSIDE THE LENS
; ------------------------------------------------------

If distance < #LENS_RADIUS

lensStart = (#LENS_RADIUS - distance) / (#LENS_RADIUS - #HORIZON_X)

lensStart = MinF(1.0, MaxF(0.0, lensStart))

lens = SmoothStep(lensStart)

c = Int(c * (1.0 + lens * 0.55))

c = Min(255, Max(0, c))

EndIf

; ------------------------------------------------------
; DRAW THE STAR
; ------------------------------------------------------

If warpedX > -20 And warpedX < #WIDTH + 20 And warpedY > -20 And warpedY < #HEIGHT + 20

Circle(Int(warpedX), Int(warpedY), Int(Stars(i)\size), RGB(c, c, c))

EndIf

EndIf

Next

EndProcedure

; ============================================================
; DYNAMIC ACCRETION DISK
; ============================================================

Procedure DrawAccretionDisk()

Protected x
Protected y

Protected dx.f
Protected dy.f

Protected distance.f
Protected normalized.f

Protected angle.f
Protected rotation.f

Protected wave.f
Protected plasma.f
Protected brightness.f

Protected red
Protected green
Protected blue

Protected noise.f

; ----------------------------------------------------------
; PLASMA ROTATION
; ----------------------------------------------------------

rotation = Time * 0.75

; ----------------------------------------------------------
; DISK LOOP
; ----------------------------------------------------------

For y = Int(HoleY) - #DISK_OUTER To Int(HoleY) + #DISK_OUTER

For x = Int(HoleX) - #DISK_OUTER To Int(HoleX) + #DISK_OUTER

dx = x - HoleX
dy = y - HoleY

; ------------------------------------------------------
; ELLIPTICAL DISTANCE
; ------------------------------------------------------

distance = Sqr(dx * dx + (dy * 2.5) * (dy * 2.5))

If distance > #DISK_INNER And distance < #DISK_OUTER

; ----------------------------------------------------
; ANGLE
; ----------------------------------------------------

angle = ATan2(dy, dx)

angle = angle + rotation

; ----------------------------------------------------
; RADIAL POSITION
; ----------------------------------------------------

normalized = (distance - #DISK_INNER) / (#DISK_OUTER - #DISK_INNER)

; ----------------------------------------------------
; FIRST PLASMA LAYER
; ----------------------------------------------------

plasma = Sin(angle * 8.0 + Time * 3.0)

plasma = (plasma + 1.0) * 0.5

; ----------------------------------------------------
; SECOND LAYER
; ----------------------------------------------------

wave = Sin(angle * 17.0 - Time * 5.0 + distance * 0.035)

wave = (wave + 1.0) * 0.5

; ----------------------------------------------------
; MIX
; ----------------------------------------------------

plasma = plasma * 0.65 + wave * 0.35

; ----------------------------------------------------
; RADIAL BRIGHTNESS
; ----------------------------------------------------

brightness = 1.0 - normalized

brightness = Pow(brightness, 1.8)

; ----------------------------------------------------
; PLASMA MOTION
; ----------------------------------------------------

brightness = brightness * (0.65 + plasma * 0.55)

; ----------------------------------------------------
; PULSATION
; ----------------------------------------------------

brightness = brightness * (0.88 + Sin(Time * 2.0) * 0.12)

; ----------------------------------------------------
; TURBULENCE
; ----------------------------------------------------

noise = Random(100) / 100.0

brightness = brightness * (0.90 + noise * 0.10)

; ----------------------------------------------------
; COLOR
; ----------------------------------------------------

red = 255

green = Int(35 + 220 * brightness)

blue = Int(4 + 45 * brightness)

; ----------------------------------------------------
; INTENSITY
; ----------------------------------------------------

red = Int(red * brightness)

green = Int(green * brightness)

blue = Int(blue * brightness)

; ----------------------------------------------------
; CLAMPING
; ----------------------------------------------------

red = Min(255, Max(0, red))

green = Min(255, Max(0, green))

blue = Min(255, Max(0, blue))

; ----------------------------------------------------
; DRAW
; ----------------------------------------------------

If brightness > 0.015

Plot(x, y, RGB(red, green, blue))

EndIf

EndIf

Next

Next

EndProcedure

; ============================================================
; DYNAMIC LIGHT FLOW
; ============================================================

Procedure DrawLensGlow()

Protected i
Protected j

Protected angle.f
Protected radius.f

Protected wave.f
Protected wave2.f

Protected intensity.f

Protected x.f
Protected y.f

Protected distortion.f

Protected red
Protected green
Protected blue

; ----------------------------------------------------------
; LIGHT RING
; ----------------------------------------------------------

For i = 0 To 260

angle = (i / 260.0) * 6.2831853

angle = angle + Time * (0.18 + Sin(i * 0.37) * 0.025)

For j = 0 To 9

radius = #HORIZON_X + 4.0 + j * 7.0

; ----------------------------------------------------
; MAIN WAVE
; ----------------------------------------------------

wave = Sin(angle * 7.0 + Time * 2.4 + radius * 0.055)

; ----------------------------------------------------
; SECOND WAVE
; ----------------------------------------------------

wave2 = Sin(angle * 13.0 - Time * 3.6 + radius * 0.09)

; ----------------------------------------------------
; INTENSITY
; ----------------------------------------------------

intensity = (wave + 1.0) * 0.5

intensity = intensity * 0.65 + ((wave2 + 1.0) * 0.5) * 0.35

; ----------------------------------------------------
; LIGHT FLOW DEFORMATION
; ----------------------------------------------------

distortion = Sin(angle * 3.0 + Time * 0.45) * 7.0

x = HoleX + Cos(angle) * (radius + distortion * intensity)

y = HoleY + Sin(angle) * (radius + distortion * intensity) * 0.48

; ----------------------------------------------------
; RADIAL ATTENUATION
; ----------------------------------------------------

intensity = intensity * (1.0 - j / 13.0)

; ----------------------------------------------------
; PULSATION
; ----------------------------------------------------

intensity = intensity * (0.65 + Sin(Time * 2.0 + i * 0.1) * 0.35)

; ----------------------------------------------------
; COLOR
; ----------------------------------------------------

red = 255

green = Int(45 + intensity * 210)

blue = Int(3 + intensity * 35)

; ----------------------------------------------------
; DRAW
; ----------------------------------------------------

If intensity > 0.32

Plot(Int(x), Int(y), RGB(red, green, blue))

EndIf

Next

Next

EndProcedure

; ============================================================
; BLACK HOLE HORIZON
; ============================================================

Procedure DrawBlackHole()

; ----------------------------------------------------------
; DARK HALO
; ----------------------------------------------------------

Circle(Int(HoleX), Int(HoleY), #HORIZON_X + 4, RGB(12, 2, 0))

; ----------------------------------------------------------
; HORIZON
; ----------------------------------------------------------

Circle(Int(HoleX), Int(HoleY), #HORIZON_X, RGB(0, 0, 0))

; ----------------------------------------------------------
; PERFECTLY BLACK CENTER
; ----------------------------------------------------------

Circle(Int(HoleX), Int(HoleY), #HORIZON_X - 8, RGB(0, 0, 0))

EndProcedure

; ============================================================
; SCENE
; ============================================================

Procedure DrawScene()

StartDrawing(CanvasOutput(0))

; ----------------------------------------------------------
; BACKGROUND
; ----------------------------------------------------------

Box(0, 0, #WIDTH, #HEIGHT, RGB(1, 1, 5))

; ----------------------------------------------------------
; STARS + LENS
; ----------------------------------------------------------

DrawStars()

; ----------------------------------------------------------
; ACCRETION DISK
; ----------------------------------------------------------

DrawAccretionDisk()

; ----------------------------------------------------------
; LIGHT FLOW
; ----------------------------------------------------------

DrawLensGlow()

; ----------------------------------------------------------
; BLACK HOLE
; ----------------------------------------------------------

DrawBlackHole()

StopDrawing()

EndProcedure

; ============================================================
; MAIN LOOP
; ============================================================

Define LastTime = ElapsedMilliseconds()

Define CurrentTime
Define Delta.f

Repeat

; ----------------------------------------------------------
; EVENT HANDLING
; ----------------------------------------------------------

Select WindowEvent()

Case #PB_Event_CloseWindow

Running = #False

EndSelect

; ----------------------------------------------------------
; TIME CALCULATION
; ----------------------------------------------------------

CurrentTime = ElapsedMilliseconds()

Delta = (CurrentTime - LastTime) / 1000.0

LastTime = CurrentTime

; ----------------------------------------------------------
; ANIMATION
; ----------------------------------------------------------

Time = Time + Delta

; ========================================================
; MOVE BLACK HOLE TO THE RIGHT
; ========================================================

HoleX = HoleX + #BLACK_HOLE_SPEED * Delta

If HoleX > #WIDTH + #HORIZON_X

HoleX = -#HORIZON_X

EndIf

HoleY = #BLACK_HOLE_Y

; ========================================================
; MOVE STARS TO THE LEFT
; ========================================================

BackgroundOffset = BackgroundOffset + #BACKGROUND_SPEED * Delta

If BackgroundOffset > #WIDTH

BackgroundOffset = BackgroundOffset - #WIDTH

EndIf

; ========================================================
; RENDER
; ========================================================

DrawScene()

; ========================================================
; APPROXIMATE 60 FPS LIMIT
; ========================================================

Delay(8)

Until Running = #False
Amusez vous bien !
Répondre