Fortraneries/Fraktalism/mkmandel.f90

126 lines
3.6 KiB
Fortran
Raw Normal View History

2022-02-07 16:20:42 +01:00
!-----------------------------------------------------
2022-12-30 02:06:00 +01:00
! MANDELBROT SET
!-
! refactored Thu 29 Dec 2022 03:21:16 PM CET
!-
2022-02-07 16:20:42 +01:00
!-----------------------------------------------------
2022-12-27 19:59:07 +01:00
!-
2022-12-27 01:29:04 +01:00
subroutine plotsomething(pic, start)
2022-12-20 13:04:30 +01:00
! use cmplxmath
! use imagetools
2022-12-27 01:29:04 +01:00
use pixrgb
2022-02-07 16:20:42 +01:00
implicit none
2022-12-27 01:29:04 +01:00
type(t_pixrgb), intent(inout), dimension (:,:) :: pic
complex, intent(in) :: start
! type (CenterMag), intent(in) :: cz
2022-02-07 16:20:42 +01:00
integer :: ix, iy, width, height
2022-12-30 02:06:00 +01:00
real :: fx, fy, mod2, rval
2022-02-07 16:20:42 +01:00
complex :: za, zb, cste
integer :: iter, maxiter
logical :: escape
print *, "> plotsomething"
width = ubound(pic, 1)
height = ubound(pic, 2)
2022-12-27 19:59:07 +01:00
! print *, " pic size ", width, height
2022-02-07 16:20:42 +01:00
print *, " start ", start
! initialise constants
!
2022-12-30 02:06:00 +01:00
maxiter = 1984
2022-02-07 16:20:42 +01:00
! enter megaloop
!
do iy = 1, height
fy = (float(iy) / float(height/3)) - 1.5
!! print *, "line ", iy, fy
do ix = 1, width
fx = (float(ix) / float(width/3)) - 2.0
!-------------------------------------
! working on the current pixel
za = start
cste = complex ( fx, fy )
iter = 0
escape = .FALSE.
do while (iter .lt. maxiter)
zb = (za * za) + cste
mod2 = real(zb)*real(zb) + aimag(zb)*aimag(zb)
!! print *, "mod2 ", mod2
if (mod2 .GT. 4.0) then
escape = .TRUE.
exit
endif
za = zb
iter = iter + 1
!! print *, "ZA ITER ESCAPE", za, iter, escape
enddo
if (escape) then
2022-12-30 02:06:00 +01:00
pic(ix, iy)%r = mod(iter*12, 255)
pic(ix, iy)%b = mod(iter*8, 255)
2022-02-07 16:20:42 +01:00
else
2022-12-30 02:06:00 +01:00
rval = (mod2 + abs(real(start)*aimag(start))) * 666.666
pic(ix, iy)%g = mod(int(rval), 180)
2022-12-27 19:59:07 +01:00
! pic(ix, iy)%g = mod(iter, 255)
! pic(ix, iy)%b = mod(iter*11, 255)
2022-02-07 16:20:42 +01:00
endif
!-------------------------------------
end do ! fin boucle sur X
end do
end
!-----------------------------------------------------
!
! this is the main programm
!
2022-02-12 13:34:44 +01:00
program mkmandel
2022-12-27 01:29:04 +01:00
use pixrgb
2022-02-07 16:20:42 +01:00
implicit none
interface
2022-12-27 01:29:04 +01:00
subroutine plotsomething (pic, start)
use pixrgb
type(t_pixrgb), intent(inout), dimension (:,:) :: pic
complex, intent(in) :: start
2022-02-07 16:20:42 +01:00
end subroutine plotsomething
end interface
2022-12-27 01:29:04 +01:00
type(t_pixrgb), allocatable :: pic(:,:)
2022-02-07 16:20:42 +01:00
integer :: angle
real :: radangle, radius
real :: stx, sty
character (len=80) :: filename
2022-12-30 02:06:00 +01:00
write(0, *) "-------- making some mandelbrot -------"
2022-02-07 16:20:42 +01:00
2022-12-30 02:06:00 +01:00
allocate(pic(1152, 900))
2022-12-27 19:59:07 +01:00
2022-12-30 02:06:00 +01:00
do angle = 0, 1500
2022-12-27 01:29:04 +01:00
call rgbpix_set_to_zero(pic)
2022-02-07 16:20:42 +01:00
2022-12-30 02:06:00 +01:00
radangle = float(angle) * 0.01664
radius = float(angle) / 1500.0
2022-12-27 01:29:04 +01:00
write (filename, "(a, i5.5, a)") "frames/mandel/", angle, ".pnm"
2022-02-07 16:20:42 +01:00
! filename = trim(filename)
print *, "#### passe ", angle, radangle, trim(filename)
2022-12-30 02:06:00 +01:00
stx = radius * (sin(radangle*3.9) + sin(radangle*5.36))
2022-12-27 19:59:07 +01:00
sty = radius * cos(radangle*3.3)
2022-02-07 16:20:42 +01:00
2022-12-27 01:29:04 +01:00
call plotsomething (pic, complex(stx, sty))
call rgbpix_spit_as_pnm_8 (pic, trim(filename))
2022-02-07 16:20:42 +01:00
print *
enddo
2022-12-27 01:29:04 +01:00
print *, " [DONE]"
2022-02-07 16:20:42 +01:00
end
!-----------------------------------------------------