From 7ef447b0d88800a752b5ed347caff4d7d62bc76a Mon Sep 17 00:00:00 2001 From: tTh Date: Tue, 2 Jun 2026 18:20:09 +0200 Subject: [PATCH] first step in revamping --- GravityField/Makefile | 2 +- GravityField/README.md | 14 ++++++++++---- GravityField/animation.f90 | 22 +++++++++++----------- GravityField/encode.sh | 4 ++-- GravityField/essai.f90 | 8 +------- GravityField/plotation.sh | 4 ++++ GravityField/raytrace.sh | 24 +++++++++++++++--------- GravityField/realfield.f90 | 16 +++++++++------- GravityField/runme.sh | 5 ++++- GravityField/vision.pov | 2 +- 10 files changed, 58 insertions(+), 43 deletions(-) diff --git a/GravityField/Makefile b/GravityField/Makefile index 158dd37..ddf19a6 100644 --- a/GravityField/Makefile +++ b/GravityField/Makefile @@ -2,7 +2,7 @@ # Fortraneries by tTh - Gravity Field # -GFOPT = -Wall -Wextra -g -time -I../Modules +GFOPT = -Wall -Wextra -g -I../Modules MODOBJ = ../Modules/spitpgm.o ../Modules/pixrgb.o all: essai animation realdump2png diff --git a/GravityField/README.md b/GravityField/README.md index 29223af..0f306eb 100644 --- a/GravityField/README.md +++ b/GravityField/README.md @@ -4,19 +4,25 @@ _Some crude experiments to make fancy picture of a useless gravity field._ Expect bug party. -## Le module `realfield` +## Le module realfield Les mécaniques sous-jacentes. Sans la moindre rigueur mathématique. +Mais avec un bout de [code](./essai.f90) pour essayer des trucs et +des machins. ## Le commandeur en chef -C'est le logiciel sobrement nommé `animation` qui n'est absolument +C'est le logiciel sobrement nommé [`animation`](./animation.f90) +lequel n'est absolument pas fini. Par exemple, il n'est absolument pas paramétrable sans -passer per une recompilation. +passer par une recompilation. ## Le raytracing -Vous vous en doutez, c'est du POVray. +Vous vous en doutez, c'est du POVray. +Le fichier [vision.pov](./vision.pov), et en particulier l'object +`GravityField` assemblent le `height_field` et l'`image_map` +soigneusement calculés à l'étape précédente. ## Sortie graphique diff --git a/GravityField/animation.f90 b/GravityField/animation.f90 index 60a6be6..942758f 100644 --- a/GravityField/animation.f90 +++ b/GravityField/animation.f90 @@ -13,20 +13,20 @@ program animation implicit none ! some configuration constants - integer, parameter :: S_WIDTH = 2048 - integer, parameter :: S_HEIGHT = 2048 - integer, parameter :: NB_BODY = 666 + integer, parameter :: IMG_WIDTH = 640 + integer, parameter :: IMG_HEIGHT = 640 + integer, parameter :: NB_BODY = 133 !!! WARNING : global variable !!! type(massbody) :: planets(NB_BODY) call init_random() - call create_some_planets(planets, 1664e3, S_WIDTH , S_HEIGHT) + call create_some_planets(planets, 1664.3, IMG_WIDTH , IMG_HEIGHT) call print_barycentre_bodies(planets, 'begin') - call la_grande_boucle(0, 4000, planets) + call la_grande_boucle(0, 667, planets) - STOP ': YOLO TIME *NOW*' + ! STOP ': YOLO TIME *NOW*' !----------------------------------------------------------------------- contains @@ -46,16 +46,16 @@ subroutine la_grande_boucle(start, nbre, moons) call deplace_les_planetes(moons, .TRUE.) ! computing the field (used as a HF in Povray - write (filename, "(a, i5.5, a)") 'WS/nanim/', pass, '.pgm' + write (filename, "(a, i5.5, a)") 'WS/nanim/', pass, '.pnm' write(0, '(3I5, " * ", a20)') start, nbre, pass, filename - call build_and_write_a_field(S_WIDTH, S_HEIGHT, moons, filename) + call build_and_write_a_field(IMG_WIDTH, IMG_HEIGHT, moons, filename) ! save the current bodies positions (can be used in gnuplot) ! write (filename, "(a, i5.5, a)") 'WS/data/', pass, '.txt' ! call save_bodies_to_txt_file (planets, filename) write (filename, "(a, i5.5, a)") 'WS/colmap/', pass, '.pnm' - call make_color_map(planets, filename, S_WIDTH, S_HEIGHT) + call make_color_map(planets, filename, IMG_WIDTH, IMG_HEIGHT) enddo @@ -134,8 +134,8 @@ subroutine deplace_les_planetes(moons, clipit) real :: depx, depy, coef integer, parameter :: EE = 100 - integer :: SW = S_WIDTH - EE - integer :: SH = S_HEIGHT - EE + integer :: SW = IMG_WIDTH - EE + integer :: SH = IMG_HEIGHT - EE do foo=1, ubound(moons, 1) diff --git a/GravityField/encode.sh b/GravityField/encode.sh index 478f6c5..7793395 100755 --- a/GravityField/encode.sh +++ b/GravityField/encode.sh @@ -22,7 +22,7 @@ echo "file type :" $filetype case $filetype in PNG) extension=".png" ;; - Netpbm) extension=".pgm" ;; + Netpbm) extension=".pnm" ;; *) extension=".pnm" ;; esac echo "extension :" $extension @@ -32,7 +32,7 @@ TITLE=$(printf -- '---{ experimental gravity field %d }---' $$) ffmpeg -nostdin \ -loglevel warning \ -y -r 30 -f image2 -i ${SDIR}/%05d${extension} \ - -metadata artist='---{ tTh }---' \ + -metadata artist='tTh des Bourtoulots' \ -metadata title="${TITLE}" \ -c:v libx264 -pix_fmt yuv420p \ $FNAME diff --git a/GravityField/essai.f90 b/GravityField/essai.f90 index 8231e96..3fa6c1e 100644 --- a/GravityField/essai.f90 +++ b/GravityField/essai.f90 @@ -7,10 +7,9 @@ program essai use realfield use spitpgm ! XXX use pixrgb - implicit none - call init_random() + call init_random() ! defined in realfied module call essai_near_planet(2048, 2048) @@ -49,7 +48,6 @@ subroutine essai_near_planet(nbplanets, szfield) fx = real(ix) do iy=1, szfield fy = real(iy) - near = -1 smalldist = 1e37 ! loop over all the planet's bodies @@ -63,15 +61,11 @@ subroutine essai_near_planet(nbplanets, szfield) smalldist = curdist endif end do ! loop on ipl - cmap(ix, iy)%r = mod(near*4, 255) cmap(ix, iy)%g = mod(near*7, 255) cmap(ix, iy)%b = mod(near*11, 255) - enddo - write(0, *) "row", ix, " on", szfield - enddo call rgbpix_spit_as_pnm_8(cmap, "rgb.pnm") diff --git a/GravityField/plotation.sh b/GravityField/plotation.sh index 8ae12c9..1e5312b 100755 --- a/GravityField/plotation.sh +++ b/GravityField/plotation.sh @@ -1,5 +1,9 @@ #!/bin/bash +# +# I don't remember what this scrip is fscking doing +# + set -e SRC=WS/data/00013.txt diff --git a/GravityField/raytrace.sh b/GravityField/raytrace.sh index b505076..9e3babc 100755 --- a/GravityField/raytrace.sh +++ b/GravityField/raytrace.sh @@ -2,11 +2,11 @@ set -e -POVOPT=" -q9 +a -W1280 -H1024 +WT2 -d -v " +POVOPT=" -q9 +a -W1152 -H900 +WT2 -d -v " SOURCE="vision.pov" TMPF="/dev/shm/gravfield.png" -date > pov.stderr +date > WS/pov.stderr # --------------------------------------- @@ -14,9 +14,16 @@ une_passe () { clock=$1 -cp pov.stderr old.stderr +cp WS/pov.stderr WS/old.stderr -povray -i${SOURCE} -K${clock} $POVOPT -O${TMPF} 2> pov.stderr +set +e +povray -i${SOURCE} -K${clock} $POVOPT -O${TMPF} 2> WS/pov.stderr +err=$? +if [ $err != 0 ] ; then + tail -20 WS/pov.stderr + exit 1 +fi +set -e timestamp=$(date -u +'%F %H:%M' | tr '01' 'Ol') texte=$(printf "pass %04d" $clock | tr '01' 'Ol') @@ -24,12 +31,12 @@ outfile=$(printf "WS/troid/%05d.png" $clock) echo $timestamp $texte $outfile convert ${TMPF} \ - -pointsize 24 \ + -pointsize 18 \ -font Courier-Bold \ -fill Yellow \ -annotate +20+32 "$timestamp" \ -annotate +20+58 "$texte" \ - -pointsize 16 \ + -pointsize 12 \ -gravity south-west \ -annotate +15+9 "tTh & Konrad" \ ${outfile} @@ -37,11 +44,10 @@ convert ${TMPF} \ sleep 6 } -# --------------------------------------- - +# --------------------------------------- # main loop, build all that nice picz -for foo in $(seq 0 1999) +for foo in $(seq 0 665) do echo '............' $foo une_passe $foo diff --git a/GravityField/realfield.f90 b/GravityField/realfield.f90 index 18edf00..5bcc487 100644 --- a/GravityField/realfield.f90 +++ b/GravityField/realfield.f90 @@ -66,27 +66,29 @@ subroutine create_some_planets(planets, coef, sx, sy) fmt = "(I4, ' | ', 2(F10.2, ' '), ' | ', 2F9.3, ' ', e12.3, I7)" - do foo=1, ubound(planets, 1) - if (foo .EQ. 1) then !- ! the first planet is the home of Johnny Root !- planets(1)%posx = sx / 2 planets(1)%posy = sy / 2 - planets(1)%mass = 31e8 + planets(1)%mass = 7.12e3 + coef*foo*8.6 planets(1)%serial = 1337 planets(1)%speed = 6.666 - else + + do foo=2, ubound(planets, 1) !- ! others are planets for peones !- planets(foo)%posx = rand() * real(sx-1) planets(foo)%posy = rand() * real(sy-1) - planets(foo)%mass = 7.12e6 + coef*foo*3 + planets(foo)%mass = 7.12e3 + coef*foo*3 planets(foo)%heading = 2 * 3.141592654 * rand() - if (rand() .LT. 0.15) planets(foo)%speed = 3.14159 + if (rand() .LT. 0.15) then + planets(foo)%speed = rand() * 2.0 + else + planets(foo)%speed = rand() + 0.5 + endif planets(foo)%serial = foo*2 + 120 - endif write (*, fmt) foo, planets(foo) enddo diff --git a/GravityField/runme.sh b/GravityField/runme.sh index c34be79..722c2d5 100755 --- a/GravityField/runme.sh +++ b/GravityField/runme.sh @@ -3,14 +3,17 @@ set -e # stop on error make animation +echo err = $? LOG="WS/log.animation" date >> $LOG +rm WS/colmap/* WS/nanim/* + time ./animation | tee -a $LOG -./encode.sh WS/nanim/ gravity-field.mp4 +./encode.sh WS/nanim/ gravity-nanim.mp4 ./encode.sh WS/colmap/ gravity-colmap.mp4 ls -rtl *.mp4 >> $LOG diff --git a/GravityField/vision.pov b/GravityField/vision.pov index 5f12dd2..ee2ae86 100644 --- a/GravityField/vision.pov +++ b/GravityField/vision.pov @@ -20,7 +20,7 @@ global_settings { #declare HFDIR = "WS/nanim/"; #declare HFCK = mod(clock, 2000); -#declare HFNAME = concat(HFDIR, str(HFCK , -5, 0), ".pgm"); +#declare HFNAME = concat(HFDIR, str(HFCK , -5, 0), ".pnm"); #declare CMDIR = "WS/colmap/"; #declare CMNAME = concat(CMDIR, str(HFCK , -5, 0), ".pnm");