Fortraneries/GravityField/animation.f90

117 lines
3.6 KiB
Fortran
Raw Normal View History

2022-12-03 12:25:37 +11:00
!-----------------------------------------------------------------------
!-
! Project "gravity field" - Firts renderer
!-
!-----------------------------------------------------------------------
program animation
use realfield
use spitpgm
implicit none
! some configuration constants
2022-12-04 06:42:29 +11:00
integer, parameter :: S_WIDTH = 1024
integer, parameter :: S_HEIGHT = 1024
2022-12-11 19:25:23 +11:00
integer, parameter :: NB_BODY = 70
2022-12-03 12:25:37 +11:00
2022-12-11 19:25:23 +11:00
!!! WARNING : global variable !!!
2022-12-03 12:25:37 +11:00
type(massbody) :: planets(NB_BODY)
call init_random()
2022-12-11 19:25:23 +11:00
call create_some_planets(planets, 1664e3, S_WIDTH , S_HEIGHT)
2022-12-05 23:10:40 +11:00
call print_barycentre_bodies(planets)
! STOP 'BEFORE CRASH'
2022-12-04 06:42:29 +11:00
call la_grande_boucle(0, 2000, planets)
STOP ': YOLO TIME *NOW*'
!-----------------------------------------------------------------------
contains
!-
! fabrication d'une de la sequence complete
!-
subroutine la_grande_boucle(start, nbre, moons)
integer, intent(in) :: start, nbre
type(massbody), intent(inout) :: moons(:)
character(len=100) :: filename
integer :: pass
do pass=start, start+nbre-1
2022-12-05 23:10:40 +11:00
! if second parameter is TRUE, use clipping,
! else use ?????ing
call deplace_les_planetes(moons, .TRUE.)
2022-12-04 06:42:29 +11:00
write (filename, "(a, i5.5, a)") 'WS/nanim/', pass, '.pgm'
2022-12-05 23:10:40 +11:00
write(0, '(3I5, " * ", a20)') start, nbre, pass, filename
2022-12-04 06:42:29 +11:00
call build_and_write_a_field(S_WIDTH, S_HEIGHT, moons, filename)
2022-12-11 19:25:23 +11:00
write (filename, "(a, i5.5, a)") 'WS/data/', pass, '.txt'
call save_bodies_to_txt_file (planets, filename)
2022-12-04 06:42:29 +11:00
enddo
2022-12-03 12:25:37 +11:00
2022-12-05 23:10:40 +11:00
call print_barycentre_bodies(moons)
2022-12-04 06:42:29 +11:00
end subroutine
2022-12-03 12:25:37 +11:00
2022-12-04 06:42:29 +11:00
!-----------------------------------------------------------------------
2022-12-05 23:10:40 +11:00
!-
! C'est ici que se passe le deplacement des choses mouvantes
!-
! Il y a deux manieres d'aborder les bords de l'univers (non, le combo
! segfault/coredump n'en fait pas partie).
!-
subroutine deplace_les_planetes(moons, clipit)
2022-12-04 06:42:29 +11:00
type(massbody), intent(inout) :: moons(:)
2022-12-05 23:10:40 +11:00
logical, intent(in) :: clipit
2022-12-04 06:42:29 +11:00
integer :: foo
real :: depx, depy
2022-12-05 23:10:40 +11:00
integer, parameter :: EE = 45
integer :: SW = S_WIDTH - EE
integer :: SH = S_HEIGHT - EE
2022-12-04 06:42:29 +11:00
do foo=1, ubound(moons, 1)
! print *, "----- deplace ",foo, "serial ", moons(foo)%serial
depx = moons(foo)%speed * sin(moons(foo)%heading)
depy = moons(foo)%speed * cos(moons(foo)%heading)
moons(foo)%posx = moons(foo)%posx + depx
moons(foo)%posy = moons(foo)%posy + depy
!-
! ici se pose une question pertinente sur la gestion des
2022-12-05 23:10:40 +11:00
! bords du chanmp. Clipping, Toring or Boucing ?
2022-12-04 06:42:29 +11:00
!-
2022-12-05 23:10:40 +11:00
if (clipit) then
if (moons(foo)%posx .GT. SW) moons(foo)%posx = SW
if (moons(foo)%posy .GT. SH) moons(foo)%posy = SH
if (moons(foo)%posx .LT. EE) moons(foo)%posx = EE
if (moons(foo)%posy .LT. EE) moons(foo)%posy = EE
! STOP 'BECAUSE WE ARE TOTALY FUCKED'
else
if (moons(foo)%posx .GT. SW) moons(foo)%posx = EE
if (moons(foo)%posy .GT. SH) moons(foo)%posy = EE
if (moons(foo)%posx .LT. EE) moons(foo)%posx = SW
if (moons(foo)%posy .LT. EE) moons(foo)%posy = SH
endif
2022-12-11 19:25:23 +11:00
moons(foo)%heading = moons(foo)%heading + (0.71*(rand()-0.50))
2022-12-04 06:42:29 +11:00
if (moons(foo)%heading .GT. 6.2831853) moons(foo)%heading = 0.0
2022-12-05 23:10:40 +11:00
if (moons(foo)%heading .LT. 0.0000001) moons(foo)%heading = 0.0
2022-12-04 06:42:29 +11:00
enddo
end subroutine
!-----------------------------------------------------------------------
!-----------------------------------------------------------------------
2022-12-03 12:25:37 +11:00
end program
2022-12-04 06:42:29 +11:00