From 8535ba09d953c543fe48069fee75350a85e1a0b2 Mon Sep 17 00:00:00 2001 From: tTh Date: Tue, 22 Nov 2022 08:58:56 +0100 Subject: [PATCH] OK boomer --- GrafAnim/.gitignore | 1 + GrafAnim/Makefile | 3 +++ GrafAnim/doubledice.f90 | 4 ++-- GrafAnim/essai.f90 | 25 +++++++++++++++---------- GrafAnim/usegenplot.f90 | 35 ++++++++++++++++++++++++++++++++--- 5 files changed, 53 insertions(+), 15 deletions(-) diff --git a/GrafAnim/.gitignore b/GrafAnim/.gitignore index 1558a08..a84918f 100644 --- a/GrafAnim/.gitignore +++ b/GrafAnim/.gitignore @@ -1,5 +1,6 @@ essai +doubledice *.scratch *.tga diff --git a/GrafAnim/Makefile b/GrafAnim/Makefile index bb5ea2b..6c74fa7 100644 --- a/GrafAnim/Makefile +++ b/GrafAnim/Makefile @@ -7,6 +7,9 @@ GFOPT = -Wall -Wextra -g -time essai: essai.f90 usegenplot.o Makefile gfortran $(GFOPT) $< usegenplot.o -o $@ +doubledice: doubledice.f90 usegenplot.o Makefile + gfortran $(GFOPT) $< usegenplot.o -o $@ + usegenplot.o: usegenplot.f90 Makefile gfortran $(GFOPT) -c $< diff --git a/GrafAnim/doubledice.f90 b/GrafAnim/doubledice.f90 index 862cd0c..b913143 100644 --- a/GrafAnim/doubledice.f90 +++ b/GrafAnim/doubledice.f90 @@ -2,8 +2,8 @@ program doubledice use usegenplot implicit none + call init_genplot("essai.genplot") - - + call end_genplot("OK boomer") end program diff --git a/GrafAnim/essai.f90 b/GrafAnim/essai.f90 index 1293cae..3fc1050 100644 --- a/GrafAnim/essai.f90 +++ b/GrafAnim/essai.f90 @@ -4,7 +4,7 @@ program essai integer :: foo, bar integer :: nbarg - integer :: numframe = 1 + integer :: numframe = 0 character(len=32) :: arg ! write(0, *) "------------ essai graf anim ---------------" @@ -12,30 +12,35 @@ program essai nbarg = IARGC() if (nbarg .GT. 0) then call GETARG(1, arg) - write (0, '(A40, A5)') "argument = ", arg + ! write (0, '(A40, A5)') "argument = ", arg read (arg, *) numframe endif - write(0, '(A40, I5)') "frame number =", numframe + ! write(0, '(A20, I5)') "frame number =", numframe call init_genplot("essai.genplot") - ! call do_frame(7) + call do_frame(7) - bar = (numframe * 20) - 160 - do foo=20, 620, 40 + call gplt_setcol(2) + + bar = (numframe * 20) - 120 + do foo=20, 620, 50 call gplt_line(foo, 20, bar, 460) call gplt_line(bar, 20, foo, 460) enddo + call end_genplot("done for today") + contains !------------------------------------------ subroutine do_frame(color) integer, intent(in) :: color + integer :: savecol - call gplt_line( 0, 0, 640, 0) - call gplt_line( 0, 480, 640, 480) - call gplt_line( 0, 0, 0, 480) - call gplt_line(640, 0, 640, 480) + savecol = gplt_getcol() + call gplt_setcol(color) + call gplt_rect(0, 0, 640, 480) + call gplt_setcol(savecol) end subroutine diff --git a/GrafAnim/usegenplot.f90 b/GrafAnim/usegenplot.f90 index 0691519..18fdfe4 100644 --- a/GrafAnim/usegenplot.f90 +++ b/GrafAnim/usegenplot.f90 @@ -1,6 +1,9 @@ module usegenplot implicit none + + integer, private :: color = 4 + logical, private :: initialised = .FALSE. contains ! ------------------------------------------------------------------- @@ -8,11 +11,29 @@ module usegenplot subroutine init_genplot(filename) character(*), intent(in) :: filename - write(0, *) '--> init genplot "', filename, '"' + initialised = .TRUE. + color = 4 end subroutine +subroutine end_genplot(message) + + character(*), intent(in) :: message + write(0, *) '--> end genplot "', message, '"' + initialised = .FALSE. + +end subroutine + +! ------------------------------------------------------------------- +subroutine gplt_setcol(col) + integer, intent(in) :: col + color = col +end subroutine +function gplt_getcol() + integer gplt_getcol + gplt_getcol = color +end function ! ------------------------------------------------------------------- subroutine gplt_move(x, y) @@ -24,7 +45,7 @@ end subroutine subroutine gplt_draw(x, y) integer, intent(in) :: x, y - print *, x, y, 2 + print *, x, y, color end subroutine ! ------------------------------------------------------------------- @@ -36,11 +57,19 @@ subroutine gplt_line(x1, y1, x2, y2) end subroutine ! ------------------------------------------------------------------- + subroutine gplt_rect(x1, y1, x2, y2) - integer, intent(in) :: x1, y1, x2, y2! ------------------------------------------------------------------- + integer, intent(in) :: x1, y1, x2, y2 + + call gplt_move(x1, y1) + call gplt_draw(x2, y1) + call gplt_draw(x2, y2) + call gplt_draw(x1, y2) + call gplt_draw(x1, y1) end subroutine +! ------------------------------------------------------------------- ! ------------------------------------------------------------------- end module