2022-11-30 12:52:16 +11:00
|
|
|
!-----------------------------------------------------------------------
|
2022-11-30 13:24:24 +11:00
|
|
|
!-
|
|
|
|
! test program for the project "gravity field"
|
|
|
|
!-
|
2022-11-30 12:52:16 +11:00
|
|
|
!-----------------------------------------------------------------------
|
2022-11-24 10:52:13 +11:00
|
|
|
program essai
|
2022-12-17 06:37:52 +11:00
|
|
|
use realfield
|
|
|
|
use spitpgm ! XXX
|
|
|
|
use pixrgb
|
2022-11-30 12:52:16 +11:00
|
|
|
|
2022-11-24 10:52:13 +11:00
|
|
|
implicit none
|
|
|
|
|
2022-12-01 08:46:44 +11:00
|
|
|
call init_random()
|
2022-11-24 10:52:13 +11:00
|
|
|
|
2022-12-17 07:16:02 +11:00
|
|
|
call essai_near_planet(1024, 1024)
|
2022-11-28 23:47:44 +11:00
|
|
|
|
2022-12-01 08:46:44 +11:00
|
|
|
STOP 'BECAUSE YOLO'
|
2022-11-24 10:52:13 +11:00
|
|
|
|
2022-11-30 12:52:16 +11:00
|
|
|
contains
|
|
|
|
!-----------------------------------------------------------------------
|
|
|
|
!-
|
2022-12-12 10:57:00 +11:00
|
|
|
! computation of thr nearest planet
|
2022-12-01 08:46:44 +11:00
|
|
|
!-
|
2022-12-12 10:57:00 +11:00
|
|
|
subroutine essai_near_planet(nbplanets, szfield)
|
|
|
|
integer, intent(in) :: nbplanets, szfield
|
|
|
|
|
2022-12-17 06:37:52 +11:00
|
|
|
type(t_pixrgb), dimension(:,:), allocatable :: cmap
|
|
|
|
integer :: ix, iy
|
|
|
|
real :: fx, fy, dx, dy
|
|
|
|
integer :: near, ipl, errcode
|
|
|
|
real :: curdist, smalldist
|
|
|
|
type(massbody) :: planets(nbplanets)
|
2022-12-12 10:57:00 +11:00
|
|
|
|
|
|
|
print *, "near planets test", nbplanets, szfield
|
2022-12-01 08:46:44 +11:00
|
|
|
|
2022-12-17 06:37:52 +11:00
|
|
|
allocate(cmap(szfield, szfield), stat=errcode)
|
|
|
|
! map = -1
|
2022-12-12 10:57:00 +11:00
|
|
|
|
|
|
|
! create some random bodies
|
|
|
|
do ipl=1, nbplanets
|
|
|
|
planets(ipl)%posx = rand() * szfield
|
|
|
|
planets(ipl)%posy = rand() * szfield
|
|
|
|
planets(ipl)%serial = ipl
|
|
|
|
end do
|
|
|
|
! call save_bodies_to_txt_file(planets, "planets.txt")
|
|
|
|
|
|
|
|
! loop over all the location of the field
|
|
|
|
do ix=1, szfield
|
|
|
|
fx = real(ix)
|
|
|
|
do iy=1, szfield
|
|
|
|
fy = real(iy)
|
|
|
|
|
|
|
|
near = -1
|
|
|
|
smalldist = 1e37
|
|
|
|
! loop over all the planet's bodies
|
|
|
|
do ipl=1, nbplanets
|
|
|
|
! compute the "fake" distance
|
|
|
|
dx = fx - planets(ipl)%posx
|
|
|
|
dy = fy - planets(ipl)%posy
|
|
|
|
curdist = (dx*dx) + (dy*dy)
|
|
|
|
if (curdist .LT. smalldist) then
|
|
|
|
near = ipl
|
|
|
|
smalldist = curdist
|
|
|
|
endif
|
|
|
|
end do ! loop on ipl
|
|
|
|
|
2022-12-17 07:16:02 +11:00
|
|
|
cmap(ix, iy)%r = mod(near*4, 255)
|
|
|
|
cmap(ix, iy)%g = mod(near*7, 255)
|
|
|
|
cmap(ix, iy)%b = mod(near*11, 255)
|
2022-12-12 10:57:00 +11:00
|
|
|
|
|
|
|
enddo
|
|
|
|
|
|
|
|
write(0, *) "row", ix, " on", szfield
|
2022-12-01 08:46:44 +11:00
|
|
|
|
|
|
|
enddo
|
2022-11-24 10:52:13 +11:00
|
|
|
|
2022-12-17 06:37:52 +11:00
|
|
|
call rgbpix_spit_as_pnm(cmap, "rgb.pnm")
|
2022-11-24 10:52:13 +11:00
|
|
|
|
2022-11-28 23:47:44 +11:00
|
|
|
end subroutine
|
2022-11-30 12:52:16 +11:00
|
|
|
!-----------------------------------------------------------------------
|
2022-11-24 10:52:13 +11:00
|
|
|
|
|
|
|
end program
|