add a randomwalking prog

This commit is contained in:
Tonton Th
2026-04-24 23:23:40 +02:00
parent c1694dbaf2
commit 845a00d476
3 changed files with 40 additions and 0 deletions

36
randomwalk.f90 Normal file
View File

@@ -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