Silverfrost Forums

Welcome to our forums

Avoiding flicker with rapid %pl updates

28 Jan 2025 8:41 #31864

Ken,

I am a bit behind, as I am not using Ver 9.06 as yet.

However I ran your 27-Jan example in Plato (without buffering), plus having FTN95 help window opened and the FTN95 Help window index was also flickering.

Also noticed 'call sleep@(0.02)' was also working, contrary to sleep@(time), for time < .05.

Thanks for the examples.

28 Jan 2025 10:36 #31865

John

There was a bug in ClearWin+ that in some contexts was causing other applications to flicker. This has been fixed.

28 Jan 2025 12:07 #31866

Paul,

If you run this program a dozen times, you may get a surprise. Using winop@ calls and extremely rapid update I occasionally get the clearwin error 'Too many colours for %pl plot'.

I m guessing, but it looks like the character string created by winop@ in the previous iteration is not cleared.

module data_mod
use clrwin
implicit none
integer, parameter :: n = 100
real*8 :: x(n), random_y(n), mean_y(n)
end module data_mod

program p
implicit none
integer :: iw
integer, external :: run_cb
iw = winio@('%^bt[Run]%nl&',run_cb)
iw = winio@('%gr[white]', 900, 600)
end program p

integer function run_cb()
use data_mod
implicit none
integer :: i, iw
real*8 :: acc
  
  call random_number(random_y)
  acc = 0.d0
  do i = 1, n, 1
    
    x(i) = dble(i)
    acc = acc + random_y(i)
    mean_y(i) = acc / x(i)
        
!$$$$$$       iw = winio@('%fn[Consolas]%ts&',1.5d0)
!$$$$$$       iw = winio@('%pl[native,n_graphs=2,frame,gridlines,width=3,'//&
!$$$$$$                       'link=none,colour=red,symbol=10,'//&
!$$$$$$                       'link=lines,colour=blue,symbol=0,'//&
!$$$$$$                       'external,buffered'//']', i, 1.d0, 1.d0, random_y, mean_y)
         
!  The code commented out above works without any issues.
!  The equivalent code below using winop@ calls will
!  ** on occasion ** fail reporting the clearwin error 
!  'Too many colours for %pl plot'
!  This happens when i is small, typically < 6
      print*, i
      call winop@('%pl[native]') 
      call winop_int@('%pl[n_graphs]', 2)
      call winop@('%pl[frame,gridlines]')
      call winop_int@('%pl[width]',3) 
      call winop@('%pl[link=none,colour=red,symbol=10]')
      call winop@('%pl[link=lines,colour=blue,symbol=0]')
      call winop@('%pl[external,buffered]')
      iw = winio@('%fn[Consolas]%tc[blue]%ts&',1.5d0)
      iw = winio@('%pl', i, 0.d0, 1.d0, random_y, mean_y)
  end do
  run_cb = 2
end function run_cb
29 Jan 2025 7:48 #31867

Ken

When setting the number of graphs, it must be the first option when using winop@ etc..

Also it looks like the %pl options must be kept together by moving the font attributes to the beginning. But I don't know why this is necessary.

So...

  iw = winio@('%fn[Consolas]%tc[blue]%ts&amp;',1.5d0)
  call winop_int@('%pl[n_graphs]', 2)
  call winop@('%pl[native]')
  call winop@('%pl[frame,gridlines]')
  call winop_int@('%pl[width]',3)
  call winop@('%pl[link=none,colour=red,symbol=10]')
  call winop@('%pl[link=lines,colour=blue,symbol=0]')
  call winop@('%pl[external,buffered]')
  iw = winio@('%pl', i, 0.d0, 1.d0, random_y, mean_y)

then maybe a call to perform_graphics_update@() and temporary_yield@() might be good.

29 Jan 2025 10:46 #31870

Thanks Paul,

For some reason I had it in my head that the requirement for n_graphs to be in the first winop@ call only applied when n_graphs > 10. I’m pretty sure that’s stated in the documentation somewhere.

All working now.

Also fine in the case where there are multiple %gr regions and a call to select_graphics_object@ is required. I plan to do a few more tests.

29 Jan 2025 11:58 #31872

Yes. The documentation needs fixing. The change may not get into the next full release.

29 Jan 2025 2:29 #31873

Thanks, Paul, for polishing one more thing in CWP.

Noticed something unusual here: winop_int@ and when looked at ctwplus.enh file I found a lot of things I missed because did not have time to look into this file hidden deeply into the directory structure. All these new features have to be actively advertised otherwise the situation look like with Franz Schubert, who was writing all his music into the table shelf 😦

30 Jan 2025 11:13 #31879

Paul,

Pleased to report that my further tests did not identify any additional problems.

Here is one with multiple graphs.

https://www.dropbox.com/scl/fi/cuu91mgnsmrjeqr6wbblf/three_pl_buffered.f95?rlkey=dwslwk621wxvjeo68xz53xx7t&st=q4nx73xj&dl=0

Thanks again for this enhancement.

Ken

2 Feb 2025 9:51 #31894

Here is another example which appeals to the electrical engineer or “sparky” in me.

The program simulates an electrical arc between two arcing horns in 2D, using midpoint displacement and recursion to generate the chaotic, jagged path of each sequential arc.

https://www.dropbox.com/scl/fi/pzwe2l0zuy4jazshnkmsd/arcing.f95?rlkey=vbwq0vbjiea290k386vtexvak&st=zxqml4c3&dl=0

3 Feb 2025 7:24 #31896

Ken

These applications are very impressive.

4 Feb 2025 3:03 #31901

Here is another fractal - the Barnsley fern.

There a few tricks with the %pl margin, frame, etched, external_ticks and x_min etc, options, which along with an offset in the x axis values passed to %pl which combine to hide all axis annotations.

Not a good example to ask the %pl[external,buffered] to update on each iteration however.

options (optimise)
program bfern
use clrwin
implicit none
integer, parameter :: n = 100000
integer :: i, current, iw, control, idx, gh
real*8 :: temp_x, temp_y, r, x_shift = 5.5d0   
real*8, allocatable, dimension(:) :: x, y
real*8, dimension(4, 6) :: coeffs
data coeffs/0.0d0, 0.2d0, -0.15d0, 0.84d0, 0.0d0, -0.26d0, 0.28d0, 0.04d0, &
            0.0d0, 0.23d0, 0.26d0,-0.04d0, 0.16d0, 0.22d0, 0.24d0, 0.85d0, & 
            0.0d0, 0.0d0,  0.0d0,  0.0d0,  0.0d0,  1.6d0,  0.44d0, 1.6d0 /
  write(*,'(a)') 'Initialising'             
  allocate(x(n),y(n))
  gh = 0.80*clearwin_info@('screen_depth')
  iw = winio@('%mn[Exit]&','Exit')
  iw = winio@('%gr[grey]%lw',gh,gh,control)
  x(1) = 0.d0
  y(1) = 0.d0
  current = 1
  write(*,'(a,f6.2)') '% complete ',0.d0
  do i = 2, n
    call random_number(r)
    temp_x = x(current)
    temp_y = y(current)
    if (r .le. 0.01d0) then
      idx = 1
    else if (r .le. 0.08d0) then
      idx = 2
    else if (r .le. 0.15d0) then
      idx = 3
    else
      idx = 4
    end if
    x(i) = coeffs(idx, 1) * temp_x + coeffs(idx, 2) * temp_y + coeffs(idx, 5)
    y(i) = coeffs(idx, 3) * temp_x + coeffs(idx, 4) * temp_y + coeffs(idx, 6)
    current = i
    if ( mod(i,1000) .eq. 0 ) call temporary_yield@()
    if ( mod(i,n/20) .eq. 0  ) then
      iw = winio@('%`bg[grey]&')
      call winop_int@('%pl[n_graphs]',1)
      call winop_clr@('%pl[colour]', rgb@(1,130,32)) 
      call winop@('%pl[x_array,independent,link=none,symbol=11,symbol_size=1]')
      call winop@('%pl[frame,etched,external_ticks,margin=2]')
      call winop@('%pl[x_min=0,x_max=11,y_min=0,y_max=11]')
      iw = winio@('%pl[external,buffered]', i, x + x_shift, y)
      
      call perform_graphics_update@()
      call temporary_yield@()
      write(*,'(a,f6.2)') '% complete ',dble(i)/n*100
    end if
  end do
  write(*,'(a)') 'all done'
end program bfern
Please login to reply.