Compare commits
12 Commits
fce8fd4989
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0bc55225fc | ||
|
|
3d4fce2ed0 | ||
|
|
ec199da8dd | ||
|
|
a20725f5ef | ||
|
|
42d066678d | ||
|
|
ea373fa198 | ||
|
|
52e5e99b07 | ||
|
|
086c2af118 | ||
|
|
e060fad764 | ||
|
|
be961b46fc | ||
|
|
1dd0e71577 | ||
|
|
a0d63856af |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -14,4 +14,5 @@ lissajous
|
||||
squarmania
|
||||
testbed
|
||||
rndwlkng
|
||||
morecircles
|
||||
|
||||
|
||||
24
Makefile
24
Makefile
@@ -7,14 +7,30 @@ all: testbed
|
||||
genplotting.o: genplotting.f90 Makefile
|
||||
gfortran -Wall -c $<
|
||||
|
||||
testbed: testbed.f90 Makefile genplotting.o
|
||||
gfortran -Wall $< genplotting.o -o $@
|
||||
genp_tests.o: genp_tests.f90 genplotting.o Makefile
|
||||
gfortran -Wall -c $<
|
||||
|
||||
testbed: testbed.f90 Makefile genp_tests.o genplotting.o
|
||||
gfortran -Wall $< genplotting.o genp_tests.o -o $@
|
||||
|
||||
# -----------------------------------------------
|
||||
|
||||
rndwlkng: rndwlkng.f90 Makefile genplotting.o
|
||||
gfortran -Wall $< genplotting.o -o $@
|
||||
|
||||
rndwlkng.png: rndwlkng Makefile
|
||||
./rndwlkng
|
||||
convert rndwlkng.tga rndwlkng.png
|
||||
|
||||
# -----------------------------------------------
|
||||
|
||||
morecircles: morecircles.f90 Makefile genplotting.o
|
||||
gfortran -Wall $< genplotting.o -o $@
|
||||
|
||||
morecircles.png: morecircles Makefile
|
||||
./morecircles
|
||||
convert morecircles.tga morecircles.png
|
||||
|
||||
# -----------------------------------------------
|
||||
|
||||
starfield: starfield.f90 Makefile genplotting.o
|
||||
@@ -22,8 +38,7 @@ starfield: starfield.f90 Makefile genplotting.o
|
||||
|
||||
starfield.png: starfield Makefile
|
||||
./starfield
|
||||
genplot2 -s 512x512 WS/starfield.scratch WS/a.tga
|
||||
convert WS/a.tga $@
|
||||
convert -verbose WS/a.tga $@
|
||||
|
||||
# -----------------------------------------------
|
||||
|
||||
@@ -52,7 +67,6 @@ spirale: spirale.f90 Makefile genplotting.o
|
||||
|
||||
spirale.png: spirale Makefile
|
||||
./spirale
|
||||
genplot2 -s 512x512 WS/spirale.scratch WS/a.tga
|
||||
convert WS/a.tga $@
|
||||
|
||||
# -----------------------------------------------
|
||||
|
||||
@@ -7,25 +7,47 @@ who can be installed with the [libtthimage](https://git.tetalab.org/tTh/libtthim
|
||||
|
||||
For drawing an *useless graphic*, you have to follow three steps:
|
||||
initialize, use and terminating.
|
||||
You can look at some [examples](exemples.md) and at a
|
||||
[full page](http://maison.tth.netlib.re/dessins/numerique.html)
|
||||
off UselessGraphics.
|
||||
|
||||
## Initialize
|
||||
|
||||
Call the subroutine `genp_init` with two parameters.
|
||||
The first is an integer and must be 0.
|
||||
The first is an integer and must be 0. In the futur, it may be used for
|
||||
setting some predefined configurations.
|
||||
|
||||
The second is the filename for recording the plottings instructions,
|
||||
if this filename is an empty string, *stdout* will be used.
|
||||
I'm using the `.scratch` extension for naming this file.
|
||||
And if this filename is an empty string, *stdout* will be used, so
|
||||
you can pipe the data for post-processing purpose.
|
||||
**Be warned:** if you use this option, don't write anything to the
|
||||
unit 6 **!**
|
||||
|
||||
## Use it
|
||||
|
||||
- real xa, ya, xb, yb
|
||||
- integer color
|
||||
- call genp_move(xa, ya)
|
||||
- call genp_draw(xa, ya, color)
|
||||
- call genp_line(xa, ya, xb, yb, color)
|
||||
- `real xa, ya, xb, yb`
|
||||
- `integer color`
|
||||
- `call genp_move(xa, ya)`
|
||||
- `call genp_draw(xa, ya, color)`
|
||||
- `call genp_line(xa, ya, xb, yb, color)`
|
||||
|
||||
## Terminator
|
||||
|
||||
- call genp_end(0)
|
||||
- `call genp_end(0)`
|
||||
This procedure end the current plotting, add some *bells* to the *WIP*,
|
||||
and close the output file, if an output file was specified.
|
||||
|
||||
## Rendering
|
||||
|
||||
- `subroutine genp_do_render(srcfile, tgafile, xsize, ysize)`
|
||||
|
||||
After doing all that useless computing graphics, you can call
|
||||
the render, only if you have given a filename to `genp_init`.
|
||||
The render engine that I use can only write Targa file, but
|
||||
I'm going to add `PNG` to it output in a near futur.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
41
genp_tests.f90
Normal file
41
genp_tests.f90
Normal file
@@ -0,0 +1,41 @@
|
||||
!
|
||||
! MODULE FOR TESTING THE GENPLOTTING MODULE
|
||||
!
|
||||
! this crapware is released by tTh under the
|
||||
! DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
!
|
||||
! new Sun May 17 11:21:39 AM UTC 2026
|
||||
|
||||
module genp_tests
|
||||
use genplotting
|
||||
implicit none
|
||||
contains
|
||||
! ---------------------------------------------------------
|
||||
subroutine genp_test_rotation()
|
||||
|
||||
real :: mat(3, 3)
|
||||
real :: pta(3), ptb(3)
|
||||
integer :: pass, i, j
|
||||
|
||||
write(0, '("*** TEST ROTATION ***")' )
|
||||
do pass=1, 90
|
||||
call genp_set_rotation (real(pass)*0.10)
|
||||
write(0, *) " * the matrix was : "
|
||||
call genp_get_rot_matrix(mat)
|
||||
do i=1, 3
|
||||
do j=1, 3
|
||||
write (0, '(" ", F8.5)', advance='no') mat(i,j)
|
||||
end do
|
||||
write(0, *)
|
||||
end do
|
||||
|
||||
call genp_move(0.0, 0.0)
|
||||
pta(1) = 11.0 ; pta(2) = 0.0 ; pta(3) = 0.0
|
||||
ptb = matmul(mat, pta)
|
||||
write(0, '(" got XY: ", F8.5, " ", F8.5)') ptb(1), ptb(2)
|
||||
call genp_draw(ptb(1), ptb(2), 1+mod(pass, 7))
|
||||
end do ! pass
|
||||
|
||||
end subroutine
|
||||
! ---------------------------------------------------------
|
||||
end module
|
||||
106
genplotting.f90
106
genplotting.f90
@@ -11,8 +11,9 @@ module genplotting
|
||||
real :: xoffset, yoffset, xscale, yscale
|
||||
private :: xoffset, yoffset, xscale, yscale
|
||||
|
||||
real :: rotation
|
||||
private :: rotation
|
||||
real :: rotation, rotmatrix(3,3)
|
||||
private :: rotation, rotmatrix, compute_rot_matrix
|
||||
private :: print_rot_matrix
|
||||
|
||||
integer :: outunit = 6
|
||||
private :: outunit
|
||||
@@ -21,7 +22,7 @@ contains
|
||||
! ---------------------------------------------------------
|
||||
! the first parameter _must_ be 0.
|
||||
! the second can be
|
||||
! - the name of a file for recoding plot instructions
|
||||
! - the name of a file for recording plot instructions
|
||||
! or
|
||||
! - an empty string for send plot command to stdout
|
||||
!
|
||||
@@ -43,7 +44,8 @@ subroutine genp_init (foo, fname)
|
||||
xmin = 9e9 ; xmax = -9e9
|
||||
ymin = 9e9 ; ymax = -9e9
|
||||
xoffset = 0.0 ; yoffset = 0.0
|
||||
xscale = 0.0 ; yscale = 0.0
|
||||
xscale = 1.0 ; yscale = 1.0
|
||||
|
||||
rotation = 0.0
|
||||
|
||||
end subroutine
|
||||
@@ -57,10 +59,71 @@ subroutine genp_get_offset(ox, oy)
|
||||
ox = xoffset ; oy = yoffset
|
||||
end subroutine
|
||||
! ---------------------------------------------------------
|
||||
! new Tue May 12 06:51:57 PM UTC 2026
|
||||
subroutine genp_set_scale(sx, sy)
|
||||
real, intent(in) :: sx, sy
|
||||
xscale = sx ; yscale = sy
|
||||
end subroutine
|
||||
subroutine genp_get_scale(sx, sy)
|
||||
real, intent(out) :: sx, sy
|
||||
sx = xscale ; sy = yscale
|
||||
end subroutine
|
||||
! ---------------------------------------------------------
|
||||
! this is a private procedure, don't call it from your prog
|
||||
subroutine compute_rot_matrix(angle)
|
||||
real, intent(in) :: angle
|
||||
write (0, '("compute rot matrix for", F8.5, " radians")') &
|
||||
angle
|
||||
rotmatrix (1, 1) = cos(angle)
|
||||
rotmatrix (1, 2) = sin(angle)
|
||||
rotmatrix (1, 3) = 0.0
|
||||
|
||||
rotmatrix (2, 1) = -sin(angle)
|
||||
rotmatrix (2, 2) = cos(angle)
|
||||
rotmatrix (2, 3) = 0.0
|
||||
|
||||
rotmatrix (3, 1) = 0.0
|
||||
rotmatrix (3, 2) = 0.0
|
||||
rotmatrix (3, 3) = 1.0
|
||||
|
||||
end subroutine
|
||||
! -----------------
|
||||
! we have computed some fancy numbers
|
||||
! and we want to see them !
|
||||
subroutine print_rot_matrix(fd)
|
||||
integer, intent(in) :: fd
|
||||
|
||||
integer :: i, j
|
||||
do i=1, 3
|
||||
do j=1, 3
|
||||
write (fd, '(" ", F8.5)', advance='no') rotmatrix(i,j)
|
||||
end do
|
||||
write(fd, *)
|
||||
end do
|
||||
end subroutine
|
||||
! ---------------------------------------------------------
|
||||
subroutine genp_set_rotation(angle)
|
||||
real, intent(in) :: angle
|
||||
rotation = angle
|
||||
! compute the matrix here !
|
||||
call compute_rot_matrix(angle)
|
||||
! call print_rot_matrix(0)
|
||||
end subroutine
|
||||
|
||||
real function genp_get_rotation()
|
||||
genp_get_rotation = rotation
|
||||
end function
|
||||
|
||||
subroutine genp_get_rot_matrix (dst)
|
||||
real, intent(out) :: dst(3, 3)
|
||||
dst = rotmatrix
|
||||
end subroutine
|
||||
! ---------------------------------------------------------
|
||||
subroutine genp_move (px, py)
|
||||
real, intent(in) :: px, py
|
||||
real :: lx, ly
|
||||
lx = px + xoffset ; ly = py + yoffset
|
||||
lx = (px*xscale) + xoffset
|
||||
ly = (py*yscale) + yoffset
|
||||
write (outunit, '(2F12.5, I5)') lx, ly, -1
|
||||
if (lx .lt. xmin) xmin = lx
|
||||
if (lx .gt. xmax) xmax = lx
|
||||
@@ -72,7 +135,8 @@ subroutine genp_draw (px, py, color)
|
||||
real, intent(in) :: px, py
|
||||
integer, intent(in) :: color
|
||||
real :: lx, ly
|
||||
lx = px + xoffset ; ly = py + yoffset
|
||||
lx = (px*xscale) + xoffset
|
||||
ly = (py*yscale) + yoffset
|
||||
write (outunit, '(2F12.5, I5)') lx, ly, color
|
||||
if (lx .lt. xmin) xmin = lx
|
||||
if (lx .gt. xmax) xmax = lx
|
||||
@@ -95,10 +159,38 @@ subroutine genp_plot_axes(amp)
|
||||
call genp_draw( amp, 0.0, 7)
|
||||
end subroutine
|
||||
! ---------------------------------------------------------
|
||||
subroutine genp_circle(radius, steps, color)
|
||||
real, intent(in) :: radius
|
||||
integer, intent(in) :: steps, color
|
||||
|
||||
integer :: idx
|
||||
real :: fk, ang, x, y
|
||||
logical :: firstdot
|
||||
|
||||
if (steps .LT.3 ) then
|
||||
write(0, '("circle: steps ", I3, " bad value")') steps
|
||||
return
|
||||
endif
|
||||
|
||||
firstdot = .TRUE.
|
||||
do idx=0, steps
|
||||
fk = real(idx) / real(steps)
|
||||
ang = 6.283185307 * fk
|
||||
! write(0, '(I5, " -> ", 2F10.5)') idx, fk, ang
|
||||
x = radius * cos(ang) ; y = radius * sin(ang)
|
||||
if (firstdot) then
|
||||
call genp_move(x, y) ; firstdot = .FALSE.
|
||||
else
|
||||
call genp_draw(x, y, color)
|
||||
endif
|
||||
enddo
|
||||
|
||||
end subroutine
|
||||
! ---------------------------------------------------------
|
||||
subroutine genp_end (foo)
|
||||
integer, intent(in) :: foo
|
||||
|
||||
write (0, '("--- genp_end ---")')
|
||||
write (0, '("------------- genp_end -------------")')
|
||||
write (0, '("minmax X ", 2F18.5)') xmin, xmax
|
||||
write (0, '("minmax Y ", 2F18.5)') ymin, ymax
|
||||
|
||||
|
||||
28
morecircles.f90
Normal file
28
morecircles.f90
Normal file
@@ -0,0 +1,28 @@
|
||||
!
|
||||
! YOU LIKE CIRCLES ? TAKE IT SISTA !
|
||||
!
|
||||
! this crapware is released by tTh under the
|
||||
! DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
!
|
||||
|
||||
program morecircles
|
||||
use genplotting
|
||||
implicit none
|
||||
integer idx
|
||||
real fdx, xp, yp, scx, scy
|
||||
call genp_init(0, "WS/morecircles.scratch")
|
||||
scx = 0.6 ; scy = 2.3
|
||||
do idx=5, 60
|
||||
fdx = real(idx)
|
||||
xp = 3.5 * cos((fdx/14.0)-0.7)
|
||||
yp = 3.5 * sin((fdx/10.0)+0.3)
|
||||
call genp_set_offset(xp, yp)
|
||||
call genp_set_scale(scx, scy)
|
||||
call genp_circle(fdx, 60, 1+mod(idx, 3))
|
||||
scx = scx + 0.0185
|
||||
scy = scy - 0.0129
|
||||
enddo
|
||||
call genp_end(0)
|
||||
call genp_do_render("WS/morecircles.scratch", "morecircles.tga", &
|
||||
512, 512)
|
||||
end program
|
||||
24
rndwlkng.f90
24
rndwlkng.f90
@@ -11,27 +11,24 @@ program rndwlkng
|
||||
implicit none
|
||||
|
||||
type walker
|
||||
real :: xloc, yloc
|
||||
real :: xloc, yloc ! where I am ?
|
||||
real :: heading ! direction in degrees
|
||||
real :: powa
|
||||
real :: powa ! correlated to nothing
|
||||
end type walker
|
||||
|
||||
type (walker) drunky
|
||||
integer pass
|
||||
|
||||
drunky%xloc = 0.00
|
||||
drunky%yloc = 0.00
|
||||
drunky%heading = 13.37
|
||||
drunky%powa = 4.00
|
||||
call srand(time())
|
||||
|
||||
call genp_init(0, "WS/rndwlkng.scratch")
|
||||
|
||||
do pass=1, 100
|
||||
do pass=1, 73
|
||||
drunky%xloc = 5555 * (rand(0) - 0.50)
|
||||
drunky%yloc = 5555 * (rand(0) - 0.50)
|
||||
drunky%heading = 13.37
|
||||
drunky%powa = 4.00
|
||||
call move_the_walker(drunky, 1000, mod(pass, 5)+1)
|
||||
drunky%heading = 360 * rand(0)
|
||||
drunky%powa = 6.00
|
||||
call move_the_walker(drunky, 700, mod(pass, 6)+1)
|
||||
end do
|
||||
|
||||
call genp_end(0)
|
||||
@@ -47,18 +44,15 @@ subroutine move_the_walker(bob, nbmove, col)
|
||||
real :: rad, mv, dx, dy
|
||||
|
||||
call genp_move(bob%xloc, bob%yloc)
|
||||
|
||||
do idx=1, nbmove
|
||||
rad = ( 3.141592654 * bob%heading ) / 180.0
|
||||
mv = 0.5 + (bob%powa * rand(0))
|
||||
mv = 1.555 + (bob%powa * rand(0))
|
||||
dx = mv * sin(rad)
|
||||
dy = mv * cos(rad)
|
||||
bob%xloc = bob%xloc + dx
|
||||
bob%yloc = bob%yloc + dy
|
||||
bob%heading = bob%heading + 33 * (rand(0) - 0.50000)
|
||||
|
||||
bob%heading = bob%heading + 42.42 * (rand(0) - 0.50000)
|
||||
call genp_draw(bob%xloc, bob%yloc, col)
|
||||
|
||||
enddo
|
||||
|
||||
end subroutine
|
||||
|
||||
@@ -9,12 +9,15 @@ program spirale
|
||||
use genplotting
|
||||
implicit none
|
||||
|
||||
character(*), parameter :: scratch = "WS/spirale.scratch"
|
||||
|
||||
write (0, '(A)') "----[ genplotting spirale ]----"
|
||||
|
||||
call genp_init (0, 'WS/spirale.scratch')
|
||||
call do_spirale (1337, 0.51, 0.0666, 0.7, 3)
|
||||
call genp_init (0, scratch)
|
||||
call do_spirale (1337, 0.51, 0.0666, 0.7, 5)
|
||||
call do_spirale (1337, 0.42, 0.0333, 0.7, 6)
|
||||
call genp_end (0)
|
||||
call genp_do_render(scratch, "WS/a.tga", 512, 512)
|
||||
|
||||
contains
|
||||
! ---------------------------------------------------------
|
||||
|
||||
@@ -7,10 +7,15 @@
|
||||
program starfield
|
||||
use genplotting
|
||||
implicit none
|
||||
|
||||
character(*), parameter :: scratch = "WS/starfield.scratch"
|
||||
|
||||
write (0, '(A)') "----[ genplotting starfield ]----"
|
||||
call genp_init (0, 'WS/starfield.scratch')
|
||||
call do_starfield (200)
|
||||
call genp_init (0, scratch)
|
||||
call do_starfield (300)
|
||||
call genp_end (0)
|
||||
call genp_do_render(scratch, "WS/a.tga", 512, 512)
|
||||
|
||||
contains
|
||||
! ---------------------------------------------------------
|
||||
subroutine plot_a_star(at_x, at_y, sz, color)
|
||||
@@ -20,7 +25,7 @@ subroutine plot_a_star(at_x, at_y, sz, color)
|
||||
integer :: idx
|
||||
real :: rad, xv, yv
|
||||
|
||||
write(0, '("plot a star ", 2F8.3)') at_x, at_y
|
||||
write(0, '("plot a star at ", 2F8.3)') at_x, at_y
|
||||
call genp_set_offset(at_x, at_y)
|
||||
do idx=0, 360, 36
|
||||
! convert index to radians
|
||||
|
||||
12
testbed.f90
12
testbed.f90
@@ -1,10 +1,18 @@
|
||||
!
|
||||
! TESTBED FOR GENPLOTTING90
|
||||
!
|
||||
! this crapware is released by tTh under the
|
||||
! DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
!
|
||||
|
||||
program testbed
|
||||
use genplotting
|
||||
use genp_tests
|
||||
implicit none
|
||||
|
||||
call genp_init(0, "foo.scratch")
|
||||
call genp_plot_axes(13.37)
|
||||
call genp_test_rotation()
|
||||
! call genp_plot_axes(5.1)
|
||||
call genp_end(0)
|
||||
call genp_do_render("foo.scratch", "foo.tga", 512, 512)
|
||||
|
||||
end program
|
||||
|
||||
Reference in New Issue
Block a user