From c0c031f21a0f95abb2ae696ff9499d85daeff200 Mon Sep 17 00:00:00 2001 From: tth Date: Sun, 6 Feb 2022 23:45:08 +0100 Subject: [PATCH] first bloubspace run done --- .gitignore | 7 ++++ BloubWorld/.gitignore | 10 ++++++ BloubWorld/Makefile | 33 ++++++++++++++++++ BloubWorld/README.md | 29 ++++++++++++++++ BloubWorld/bloubspace.f90 | 54 +++++++++++++++++++++++++++++ BloubWorld/exportbloubs.f90 | 41 ++++++++++++++++++++++ BloubWorld/genbloubs.f90 | 43 +++++++++++++++++++++++ BloubWorld/movebloubs.f90 | 68 +++++++++++++++++++++++++++++++++++++ BloubWorld/povstuff.f90 | 27 +++++++++++++++ BloubWorld/runme.sh | 58 +++++++++++++++++++++++++++++++ BloubWorld/scene.pov | 40 ++++++++++++++++++++++ BloubWorld/toinc.awk | 22 ++++++++++++ 12 files changed, 432 insertions(+) create mode 100644 BloubWorld/.gitignore create mode 100644 BloubWorld/Makefile create mode 100644 BloubWorld/README.md create mode 100644 BloubWorld/bloubspace.f90 create mode 100644 BloubWorld/exportbloubs.f90 create mode 100644 BloubWorld/genbloubs.f90 create mode 100644 BloubWorld/movebloubs.f90 create mode 100644 BloubWorld/povstuff.f90 create mode 100755 BloubWorld/runme.sh create mode 100644 BloubWorld/scene.pov create mode 100644 BloubWorld/toinc.awk diff --git a/.gitignore b/.gitignore index 45c4f1b..2d68d2c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,13 @@ # Prerequisites *.d +# added by tTh + + +# --- + + + # Compiled Object files *.slo *.lo diff --git a/BloubWorld/.gitignore b/BloubWorld/.gitignore new file mode 100644 index 0000000..fd95ff7 --- /dev/null +++ b/BloubWorld/.gitignore @@ -0,0 +1,10 @@ + +bloubs.inc +*.gif +*.blbs +frames/* + +exportbloubs +genbloubs +movebloubs + diff --git a/BloubWorld/Makefile b/BloubWorld/Makefile new file mode 100644 index 0000000..9b3d4fa --- /dev/null +++ b/BloubWorld/Makefile @@ -0,0 +1,33 @@ + + +all: genbloubs movebloubs exportbloubs + + +GFOPT = -Wall -Wextra -g -time +OBJS = bloubspace.o povstuff.o +# ------------------------------------------------------------ + +initial.blbs: genbloubs Makefile + ./genbloubs $@ 1000 + +# ------------------------------------------------------------ + +bloubspace.o: bloubspace.f90 Makefile + gfortran $(GFOPT) -c $< + +povstuff.o: povstuff.f90 Makefile + gfortran $(GFOPT) -c $< + +# ------------------------------------------------------------ + +genbloubs: genbloubs.f90 Makefile $(OBJS) + gfortran $(GFOPT) $(OBJS) $< -o $@ + +movebloubs: movebloubs.f90 Makefile bloubspace.o + gfortran $(GFOPT) $(OBJS) $< -o $@ + +exportbloubs: exportbloubs.f90 Makefile bloubspace.o + gfortran $(GFOPT) $(OBJS) $< -o $@ + +# ------------------------------------------------------------ + diff --git a/BloubWorld/README.md b/BloubWorld/README.md new file mode 100644 index 0000000..59c2ec4 --- /dev/null +++ b/BloubWorld/README.md @@ -0,0 +1,29 @@ +# BloubWorld + +C'est quoi ? + +Le BloubWorld (que l'on appelle aussi BloubSpace) est un espace borné +dans lequel se déplcent des **bloubs**, une sorte de particule +munie de certaines propriétés. Lesquelles évoluent en fonction du temps. + +## Description d'un bloubs + +``` + type t_bloubs + character(8) :: nick + integer :: num + real :: px, py, pz + real :: vx, vy, vz + real :: radius + integer :: seq + end type t_bloubs +``` + +C'est simple, en fait. Le plus compliqué, c'est de savoir quoi en faire. + +## Comment ça fonctionne ? + +Pas trop mal pour un premier jet. Il suffit de lire +le script `runme.sh` pour avoir une idée de l'enchainement +des opérations. + diff --git a/BloubWorld/bloubspace.f90 b/BloubWorld/bloubspace.f90 new file mode 100644 index 0000000..cab17c7 --- /dev/null +++ b/BloubWorld/bloubspace.f90 @@ -0,0 +1,54 @@ +! +! fonctions de base de gestion des bloubs +! + +module bloubspace + + implicit none + + ! ---------------------------------------------------------------- + + type t_bloubs + character(8) :: nick + logical :: alive + integer :: num + real :: px, py, pz + real :: vx, vy, vz + real :: radius + integer :: seq + end type t_bloubs + + contains ! ----------------------------------------- + + subroutine random_pv (blb) + + type(t_bloubs), intent (inout) :: blb + + blb%px = rand() - 0.50 + blb%py = rand() * 0.25 + blb%pz = rand() - 0.50 + + blb%vx = (rand() - 0.5) / 5.000 + blb%vy = (rand() - 0.5) / 5.000 + blb%vz = (rand() - 0.5) / 5.000 + + end subroutine + + ! ---------------------------------------------------------------- + + subroutine move_bloub (blb, coef) + type(t_bloubs), intent (inout) :: blb + real, intent (in) :: coef + + blb%px = blb%px + (blb%vx * coef) + blb%py = blb%py + (blb%vy * coef) + blb%pz = blb%pz + (blb%vz * coef) + blb%seq = blb%seq + 1 + + end subroutine + ! ---------------------------------------------------------------- + +end module + + + diff --git a/BloubWorld/exportbloubs.f90 b/BloubWorld/exportbloubs.f90 new file mode 100644 index 0000000..5edd9ca --- /dev/null +++ b/BloubWorld/exportbloubs.f90 @@ -0,0 +1,41 @@ +program genbloubs + + use bloubspace + implicit none + + character(200) :: filename + integer, parameter :: idu = 33 + integer :: i, compte, errcode + type(t_bloubs) :: bloub + + ! parsing command line + i = IARGC() + if (1 .ne. i) then + STOP ' :BAD COMMAND LINE' + endif + call getarg(1, filename) + + write (0, '(A, A)') "*** exporting from ", trim(filename) + + open(unit=idu, file=trim(filename), form='unformatted', & + iostat=errcode, & + action='read', status='old') + + if (0 .ne. errcode) then + ! print *, 'errcode ', errcode + STOP " : CAN'T OPEN FILE " // trim(filename) + endif + + compte=0 + do + read (unit=idu, iostat=errcode) bloub + if (0 .ne. errcode) then + exit + endif + print *, bloub%px, bloub%py, bloub%pz, bloub%radius + compte = compte + 1 + enddo + + close(idu) + +end program diff --git a/BloubWorld/genbloubs.f90 b/BloubWorld/genbloubs.f90 new file mode 100644 index 0000000..3e79961 --- /dev/null +++ b/BloubWorld/genbloubs.f90 @@ -0,0 +1,43 @@ +program genbloubs + + use bloubspace + + integer :: nbbloubs + integer :: i + character(200) :: filename + character(30) :: str + type(t_bloubs) :: bloub + + integer, parameter :: idu = 33 + + i = IARGC() + if (i .ne. 2) then + STOP ": BAD ARGS ON COMMAND LINE" + endif + + call getarg(1, filename) + call getarg(2, str) + read(str,*) nbbloubs + + write (0, '(A,I6,A)') & + "*** generating ", nbbloubs, " bloubs to "//trim(filename) + + ! print *, "generating ", nbbloubs, "bloubs to ", filename + + open(unit=idu, file=trim(filename), form='unformatted', & + action='write', status='replace') + + do i = 1, nbbloubs + bloub%nick = 'noname ' + bloub%alive = .TRUE. + call random_pv(bloub) + bloub%radius = 0.009999 + bloub%seq = 0 + + write(idu) bloub ! no error control ? + + end do + + close(unit=idu) + +end program \ No newline at end of file diff --git a/BloubWorld/movebloubs.f90 b/BloubWorld/movebloubs.f90 new file mode 100644 index 0000000..2015647 --- /dev/null +++ b/BloubWorld/movebloubs.f90 @@ -0,0 +1,68 @@ +program movebloubs + + use bloubspace + use povstuff + + implicit none + + character(200) :: infile, outfile + integer :: inu, outu, errcode, i + type(t_bloubs) :: bloub + double precision :: bx, by, bz + + i = IARGC() + if (i .ne. 2) then + STOP ": BAD ARGS ON COMMAND LINE" + endif + call getarg(1, infile) + call getarg(2, outfile) + + inu = 42 ; outu = 51 + + write (0, '(A)') & + "*** moving bloubs from "//trim(infile)//" to "//trim(outfile) + + open(unit=inu, file=trim(infile), form='unformatted', & + iostat=errcode, & + action='read', status='old') + if (0 .ne. errcode) then + STOP " : CAN'T OPEN FILE " // trim(infile) + endif + + open(unit=outu, file=trim(outfile), form='unformatted', & + iostat=errcode, & + action='write', status='replace') + if (0 .ne. errcode) then + STOP " : CAN'T WRITE TO " // trim(outfile) + endif + + bx = 0.0; by = 0.0; bz = 0.0 + + do + read (unit=inu, iostat=errcode) bloub + if (0 .ne. errcode) then + exit + endif + + call move_bloub (bloub, 0.333) + + bx = bx + bloub%px + by = by + bloub%py + bz = bz + bloub%pz + + ! boundingbox action + if (0.0 .gt. bloub%py) then + bloub%vy = -1.0 * bloub%vy + bloub%py = 0.0 + endif + + write(outu) bloub ! no error control ? + + + enddo + + + + close(inu) ; close(outu) + +end program \ No newline at end of file diff --git a/BloubWorld/povstuff.f90 b/BloubWorld/povstuff.f90 new file mode 100644 index 0000000..a07cab3 --- /dev/null +++ b/BloubWorld/povstuff.f90 @@ -0,0 +1,27 @@ +module povstuff + + implicit none + + ! ---------------------------------------------------------------- + type t_boundb + + real :: BBminX, BBmaxX, BBminY, BBmaxY, BBminZ, BBmaxZ + integer :: id + + end type + + contains ! ----------------------------------------- + + subroutine show_bbox( bbox ) + + type (t_boundb), intent(in) :: bbox + + print *, bbox%bbminx, bbox%bbminy, bbox%bbminz + print *, bbox%bbmaxx, bbox%bbmaxy, bbox%bbmaxz + + end subroutine + + ! ---------------------------------------------------------------- + +end module + diff --git a/BloubWorld/runme.sh b/BloubWorld/runme.sh new file mode 100755 index 0000000..59ce2b0 --- /dev/null +++ b/BloubWorld/runme.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +# +# how to run this mess in a batch style +# + + +INCFILE="bloubs.inc" +TMPPNG="/dev/shm/bloubs7.png" +POVOPT="+Q9 -v -d -W640 -H480" +DDIR="frames" + +make all +err=$? +if [ $err -ne 0 ] ; then + echo 'make error = ' $err + exit 1 +fi +# +# first, we have to make a seminal buch of bloubs +# --> this function need to be paraletrizable +# +./genbloubs in.blbs 10000 + +for idx in $(seq 0 40) +do + + echo "======== run passe $idx =========" + + ./exportbloubs in.blbs | awk -f toinc.awk > $INCFILE + + povray -Iscene.pov -K${idx} -O${TMPPNG} ${POVOPT} 2> toto + grep "Trace Tim" toto + + txt=$(date +'%F %R:%S') + PNG=$(printf "%s/%05d.png" ${DDIR} $idx) + echo $PNG $txt + + convert ${TMPPNG} \ + -font fixed \ + -pointsize 12 \ + -fill orange \ + -gravity south-east \ + -annotate +10+10 "$txt" \ + $PNG + + ./movebloubs in.blbs out.blbs + + cp out.blbs in.blbs + + sleep 2 ; echo +done + +rm toto + +convert -delay 10 -colors 32 $DDIR/*.png foo.gif + + diff --git a/BloubWorld/scene.pov b/BloubWorld/scene.pov new file mode 100644 index 0000000..0cb0f4b --- /dev/null +++ b/BloubWorld/scene.pov @@ -0,0 +1,40 @@ +/* + * BLOUBSWORLD + * new Sun 06 Feb 2022 01:33:39 PM CET, rue Ernest Renan + */ +#version 3.7; + +global_settings { + ambient_light rgb <0.02, 0.02, 0.09> + assumed_gamma 1.0 + } + +#include "colors.inc" + +#include "bloubs.inc" + +object { + Bloubs + texture { + pigment { color Gray50 } + finish { phong 0.58 metallic 0.45 } + } + } + +plane { + <0, 1, 0>, 0 + texture { + pigment { color Gray10 } + finish { phong 0.58 metallic 0.45 } + } + } + +light_source { <4, 1, -9> color White } +light_source { <4, 9, 9> color White } + +camera { + location <1, 3, -5> + look_at <0, 0, 0> + right x*image_width/image_height + angle 48 + } diff --git a/BloubWorld/toinc.awk b/BloubWorld/toinc.awk new file mode 100644 index 0000000..d6d0b18 --- /dev/null +++ b/BloubWorld/toinc.awk @@ -0,0 +1,22 @@ + +# +# this code is (C) 2022 tTh +# + +BEGIN { + count = 0 + print "// GENERATED FILE, DON'T TOUCH IT !" + print "#declare Bloubs = object\n{" + print "union\t{" + } + + { + printf "\t\tsphere { <%f, %f, %f>, %f }\n", \ + $1, $2, $3, $4 + count++ + } + +END { + print "\t} // end of union\n}\n" + print "#declare Nb_Bloubs = ", count, ";\n" + }