From 845a00d476d58ebb4618f28eeeb662beae3ab680 Mon Sep 17 00:00:00 2001 From: Tonton Th Date: Fri, 24 Apr 2026 23:23:40 +0200 Subject: [PATCH] add a randomwalking prog --- .gitignore | 1 + Makefile | 3 +++ randomwalk.f90 | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 randomwalk.f90 diff --git a/.gitignore b/.gitignore index 19d285e..e959e72 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ spirale starfield +randomwalk diff --git a/Makefile b/Makefile index 69fbd92..de3e060 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,9 @@ genplotting.o: genplotting.f90 Makefile starfield: starfield.f90 Makefile genplotting.o gfortran -Wall $< genplotting.o -o $@ +randomwalk: randomwalk.f90 Makefile genplotting.o + gfortran -Wall $< genplotting.o -o $@ + # ----------------------------------------------- spirale: spirale.f90 Makefile genplotting.o diff --git a/randomwalk.f90 b/randomwalk.f90 new file mode 100644 index 0000000..c3f123c --- /dev/null +++ b/randomwalk.f90 @@ -0,0 +1,36 @@ +! +! R A N D O M W A L K +! la marche de l'ivrogne qui cherche ses clefs sous +! le lampadaire, juste là où il y a de la lumière. +! +program randomwalk + use genplotting + implicit none + integer foo, col + + write (0, '(A)') "----[ genplotting randomwalk ]----" + call srand(time()) + call genp_init (0, 'randomwalk.scratch') + do foo=1, 51 + col = 2 + mod(foo, 4) + call do_randomwalk(42, col) + enddo + call genp_end (0) +contains +! --------------------------------------------------------- +subroutine do_randomwalk(nbre, col) + integer, intent(in) :: nbre, col + integer :: idx + real :: px, py, px2, py2 + + px = 0.0 ; py = 0.0 + call genp_move(px, py) + do idx=1, nbre + px2 = px + rand(0) - 0.50 + py2 = py + rand(0) - 0.50 + call genp_line(px, py, px2, py2, col) + px = px2 ; py = py2 + enddo +end subroutine +! --------------------------------------------------------- +end program