Hi, according to the experience of my last forum subject I tried to write a example for a moving rectangle which works fine. But I am not sure if the code is very good. Following questions:
- exist a better solution to erase the whole screen instead of delete the old rectangle
- how to make the code faster?
- the lines marked with '! I don't understand why' I do not understand, the code is from a earlier forum example, but without these lines it does not work
- exist a complete better solution for this example?
Johann
winapp
module common_variables
real*8 seconds
real*4 rad,deg
integer*4 k,i,ix1,iy1,r,iHandle,ans,xcenter,ycenter
end module common_variables
program test
use common_variables
implicit none
INCLUDE <windows.ins>
external startit, stopit, exitit
r= 50
xcenter=130; ycenter=100 ! values as example
deg=0.0
seconds=0.001
ans=winio@('%ca[test: drawing of moving rectangle]&')
ans=winio@('%bg[grey]&')
ans=winio@('%`gr[white,rgb_colours]&',300L,300L, iHandle)
ans=winio@('%ff%2nl%^bt[start] &',startit)
ans=winio@('%^bt[stop] &' ,stopit)
ans=winio@('%^bt[exit] ' ,exitit)
end program
!-------------------------------------------------
integer function startit ()
use common_variables
implicit none
INCLUDE <windows.ins>
real*4 sec
k=1 ! I don't understand why
sec = seconds
call PERMIT_ANOTHER_CALLBACK@
do ! I don't understand why
!call temporary_yield@
!CALL window_update@(k)
if (k==0) exit ! I don't understand why
call circle
! draw a new rectangle
CALL DRAW_RECTANGLE@ (ix1,iy1,ix1+50,iy1+50, '[black]' )
call sleep@ (sec)
! erase the old rectangle
CALL DRAW_RECTANGLE@ (ix1,iy1,ix1+50,iy1+50,rgb@(255,255,255) )
deg = deg + 2.0
end do
startit = 1
end function startit
!-----------------------------------------------------
integer function stopit ()
use common_variables
implicit none
k=0
stopit = 1
end function stopit
!------------------------------------------------------
integer function exitit ()
use common_variables
implicit none
k=0
exitit = 0 ! return zero to stop
end function exitit
!--------------------------------------------------------
subroutine circle
use common_variables
rad = deg*3.14159 / 180
ix1 = xcenter + cos(rad)*r
iy1 = ycenter - sin(rad)*r ! circle movement
!iy1 = ycenter ! left/right movement
return
end