Files
GenPlotting90/oscilloscope.f90
2026-05-05 14:23:20 +02:00

70 lines
1.9 KiB
Fortran

!
! OSCILLOSCOPE EXPERIMENT
!
! this crapware is released by tTh under the
! DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
!
program oscilloscope
use genplotting
implicit none
real, dimension(4) :: frequences
write (0, '(A)') "----[ genplotting oscilloscope ]----"
call srand(time())
call genp_init (0, 'WS/oscilloscope.scratch')
frequences(1) = 24.86
frequences(2) = 29.77
frequences(3) = 37.56
frequences(4) = 49.3
call do_oscilloscope(frequences, 2)
call genp_end (0)
contains
! ---------------------------------------------------------
real function compute_a_value(clk, freq, phase)
real, intent(in) :: clk, freq, phase
real :: v, f
f = freq*(clk+phase)
v = sin(f) + (0.3 * sin(3*f)) + (0.1 * sin(5*f))
compute_a_value = v
end function
! ---------------------------------------------------------
subroutine plot_a_trace(freq, phy, nbsteps, ypos, col)
real, intent(in) :: freq, phy, ypos
integer, intent(in) :: nbsteps, col
integer idx
real rstep, px, py
logical firstdot
firstdot = .TRUE.
do idx=0, nbsteps
rstep = (real(idx)/real(nbsteps))
px = -10.0 + (20.0 * rstep)
py = ypos + compute_a_value (rstep, freq, phy)
if (firstdot) then
call genp_move(px, py) ; firstdot = .false.
else
call genp_draw(px, py, col)
endif
enddo
end subroutine
! ---------------------------------------------------------
subroutine do_oscilloscope(freqs, col)
real, intent(in), dimension(4) :: freqs
integer, intent(in) :: col
call plot_a_trace(freqs(1), 0.2, 120, 6.66, col)
call plot_a_trace(freqs(2), 1.0, 120, 3.33, col)
call plot_a_trace(freqs(3), 2.6, 120, -3.33, col)
call plot_a_trace(freqs(4), 3.1, 120, -6.66, col)
call plot_axes(10.0)
end subroutine
! ---------------------------------------------------------
end program