first video -> big commit :)

This commit is contained in:
tTh
2022-12-03 02:25:37 +01:00
parent 8607ff35b7
commit 3c3d1c8906
9 changed files with 315 additions and 99 deletions

View File

@@ -9,21 +9,30 @@ program essai
implicit none
type(massbody) :: planets(60)
! some configuration constants
integer, parameter :: S_WIDTH = 800
integer, parameter :: S_HEIGHT = 600
integer, parameter :: NB_BODY = 51
type(massbody) :: planets(NB_BODY)
integer :: foo
character(len=100) :: filename
call init_random()
call create_some_planets(planets, 45e5, S_WIDTH, S_HEIGHT)
call create_some_planets(planets, 45e5)
do foo=0, 72
write (filename, "(a, i5.5, a)") 'WS/A', foo, '.pgm'
call build_and_write_a_field(640, 480, planets, filename)
print *, trim(filename)
do foo=0, 1999
write (filename, "(a, i5.5, a)") 'WS/', foo, '.pgm'
call build_and_write_a_field(S_WIDTH, S_HEIGHT, planets, filename)
! print *, trim(filename)
! OMG! two magic numbers, wtf?
planets(1)%posx = planets(1)%posx + 8.08
planets(1)%posy = planets(1)%posy + 6.42
planets(1)%posx = planets(1)%posx + 3 + (4.5*rand())
planets(1)%posy = planets(1)%posy + 3 + (2.1*rand())
if (planets(1)%posx .GT. S_WIDTH) planets(1)%posx = 0.0
if (planets(1)%posy .GT. S_HEIGHT) planets(1)%posy = 0.0
call boulegue_les_astres(planets, 2.21)
enddo
STOP 'BECAUSE YOLO'
@@ -31,98 +40,21 @@ program essai
contains
!-----------------------------------------------------------------------
!-
! Yes, I know, this is a disturbing kluge, but I like it :}
! May be, it's time to read the doc of modern Fortran
! Et si on bougeait un peu tous ces corps planétaires ?
!-
subroutine init_random()
subroutine boulegue_les_astres(astres, factor)
type(massbody), intent(inout) :: astres(:)
real, intent(in) :: factor
integer, dimension(3) :: tarray
integer :: t3
real :: dummy
call itime(tarray)
t3 = 8971*tarray(1) + 443*tarray(2) + tarray(3)
write(0, '(A,3I3,A,I6)') "sranding: ", tarray, " --> ", t3
call srand(t3)
! after initializing the random generator engine,
! you MUST use it for initializing the initializer
dummy = rand()
write(0, *) 'dummy was ', dummy
end subroutine
!-----------------------------------------------------------------------
!-
! make a few solid body to play with...
!-
subroutine create_some_planets(planets, coef)
type(massbody), intent(inout) :: planets(:)
real, intent(in) :: coef
integer :: foo
! real :: quux, quuy
character(100) :: fmt
fmt = "(I4, ' : ', 2(F9.2, ' '), e11.3, I7)"
do foo=1, ubound(planets, 1)
if (foo .EQ. 1) then
planets(1)%posx = 20
planets(1)%posy = 20
planets(1)%mass = 9e8
planets(1)%serial = 1337
else
planets(foo)%posx = rand() * 639.999
planets(foo)%posy = rand() * 479.999
planets(foo)%mass = 7e6 + coef*foo
planets(foo)%serial = foo
endif
write (*, fmt) foo, planets(foo)
do foo = 2, ubound(astres, 1)
astres(foo)%posx = astres(foo)%posx + factor*(rand() - 0.5)
astres(foo)%posy = astres(foo)%posy + factor*(rand() - 0.5)
enddo
! STOP 'ABEND'
end subroutine
!-----------------------------------------------------------------------
!-
! compute a field with only one body; and write pic file
!-
subroutine build_and_write_a_field(szx, szy, moons, fname)
integer, intent(in) :: szx, szy
type(massbody), intent(in) :: moons(:)
character(len=*), intent(in) :: fname
real :: maxi, mini
integer :: errcode, foo
real, dimension(:,:), allocatable :: field, tmpf
integer, dimension(:,:), allocatable :: greymap
allocate(field(szx, szy), stat=errcode)
allocate(tmpf(szx, szy), stat=errcode)
field = 0.0
do foo=1, ubound(moons, 1)
call compute_a_field(tmpf, moons(foo))
tmpf = tmpf * 0.019
field = field + tmpf
enddo
maxi = maxval(field)
mini = minval(field)
! print *, "field: ", mini, maxi, maxi-mini
allocate(greymap(szx, szy), stat=errcode)
greymap = 0
! convert from real value to 16 bits int values
where (field < 65530.0)
greymap = int(field)
end where
call spit_as_pgm_16(greymap, trim(fname))
! make valgrind happy
deallocate(field)
deallocate(greymap)
end subroutine
!-----------------------------------------------------------------------
!-----------------------------------------------------------------------