M_pixel Module

NAME

M_pixel(3f) - [M_pixel::INTRO] module for drawing into a pixel array
              with 2D vector operations
(LICENSE:PD)

SYNOPSIS

Module procedures

use M_writegif, only : writegif

use :: M_pixel, only : drawchar,  rect,            rdraw2,     strlength
use :: M_pixel, only : color,     mapcolor,        clear,      draw2
use :: M_pixel, only : circle,    circleprecision, arc,        getviewport
use :: M_pixel, only : viewport,  ortho2,          rmove2
use :: M_pixel, only : line,      linewidth,       polyline2
use :: M_pixel, only : move2,     draw2,           prefsize,   vinit
use :: M_pixel, only : textang,   textsize,        drawstr,    getgp2
use :: M_pixel, only : vflush,    page,            point2,     getdisplaysize
use :: M_pixel, only : poly2,     centertext,      xcentertext, ycentertext
use :: M_pixel, only : makepoly,  closepoly,       font

use :: M_pixel, only : state,     hershey,         justfy
use :: M_pixel, only : print_ascii, print_ppm, print_p3, print_p6, print_ansi
use :: M_pixel, only : pixel
use :: M_pixel, only : hue

! Differences between M_pixel and M_draw and M_draw-related procedures:
!  o  hershey(3f) and justfy(3f) do not exist in M_draw and might be
!     replaced and the same font names are not available
!  o  print_ansi, print_ascii(3f) and print_ppm|p3|p6(3f) do not
!     exist in M_draw
!  -  state(3f) does not exist in M_draw
!  -  viewport is in terms of pixels, not range -1.0 to 1.0

Module variables

use M_pixel, only : P_pixel, P_ColorMap, P_debug

DESCRIPTION

M_pixel(3fm) is intended to produce simple pixel graphics composed of
line drawings and polygon fills in two dimensions. It handles circles,
curves, arcs, polygons, and software text. It is designed to provide a
programming interface very similar to a subset of the VOGLE graphics
library (M_pixel does not support objects, interactive graphics,
or 3D vectors).

It is primarily intended to provide a simple Fortran-based set of
routines that can generate simple graphics that can be written to a
GIF file using the writegif(3f) routine.

This is a prototype under construction starting 2017-06, but is already
useful. Improvements in line width, dashed lines, polygon fill and
higher level graphing routines are being worked on. If anyone is
interested in collaborating on the module, contact the author.

EXAMPLE

Sample program

program demo_M_pixel
use M_pixel
use M_writegif, only :  writegif
use M_pixel,    only : cosd, sind
implicit none

integer  :: i
integer  :: j
integer  :: icolor

   ! initialize image
   call prefsize(400,400)  ! set size before starting
   call vinit()            ! start graphics
   call clear(0)           ! clear to color 0

   ! put some colored boxes into pixmap by address
   ! so show how the pixel map can be edited easily with
   ! other routines that can manipulate a pixel array.
   ! The P_pixel array was created when vinit(3f) was called
   icolor=1
   do i=1,4
      do j=1,4
         P_pixel((i-1)*100+1+3:i*100-3,(j-1)*100+1+3:j*100-3)=icolor
         icolor=icolor+1
      enddo
   enddo

   ! map area of virtual world to pixel array
   ! notice Y-axis for viewport is zero at TOP
      ! viewport(left, right, bottom, top)
   call viewport(0.0,  400.0,  400.0, 0.0)
   ! define the virtual world area we want to work in
       !ortho2(left, right, bottom,   top)
   call ortho2(0.0,  400.0,    0.0, 400.0)
   ! the drawing routines use these world units

   ! draw polar grids
   call linewidth(100)
   call color(14)
   call target(200.0,200.0,200.0)

   call linewidth(75)
   call color(0)
   call target(100.0,200.0,50.0)

   ! draw some lines
   call color(1)
   call linewidth(200)
   call line(1.0,1.0,400.0,400.0)

   call color(4)
   call line(350.0,200.0,350.0,300.0)

   ! print some text
   call color(1)
   !call hershey(x,y,height,itext,theta,ntext)
   call linewidth(125)
   call hershey(40.0, 40.0,35.0,'Hello World',0.0,11)
   call color(7)
   call linewidth(25)
   call hershey(40.0, 80.0,35.0,'Hello World',0.0,11)
   call linewidth(100)
   call hershey(40.0,120.0,35.0,'Hello World',30.0,11)

   call hershey( 40.0,350.0,35.0,'\COMPLEX\Hello World',0.0,20)
   call hershey( 40.0,310.0,35.0,'\DUPLEX\Hello World',0.0,19)
   call hershey( 350.0,400.0,35.0,'\ITALIC\Hello World',90.0,19)
   call linewidth(50)
   call hershey(200.0,120.0,15.0,'\SIMPLEX\Hello World',20.0,20)

   ! change background color directly
   where (P_pixel.eq.0) P_pixel=9
   ! write standard gif file
   call writegif('M_pixel.3m_pixel.gif',P_pixel,P_ColorMap)

contains

   subroutine target(xc,yc,rc)
   use M_pixel,    only : cosd, sind
   real     :: xc,yc,rc
   integer  :: i
   real     :: x,y
      do i=0,360,10
         x=rc*cosd(i)
         y=rc*sind(i)
         call line(xc,yc,xc+x,yc+y)
      enddo
      do i=1,int(rc),10
         call circle(xc,yc,real(i))
      enddo
   end subroutine target
end program demo_M_pixel

AUTHOR

John S. Urban

LICENSE

Public Domain


Contents


Variables

Type Visibility Attributes Name Initial
integer(kind=c_int), public, parameter :: D_BLACK = 0_C_INT
integer(kind=c_int), public, parameter :: D_BLUE = 4_C_INT
integer(kind=c_short), public, parameter :: D_BOLD = 1_C_SHORT
integer(kind=c_short), public, parameter :: D_BOTTOM = 32_C_SHORT
integer(kind=c_int), public, parameter :: D_CYAN = 6_C_INT
integer(kind=c_int), public, parameter :: D_GREEN = 2_C_INT
integer(kind=c_short), public, parameter :: D_LEFT = 4_C_SHORT
integer(kind=c_int), public, parameter :: D_MAGENTA = 5_C_INT
integer(kind=c_short), public, parameter :: D_NORMAL = 0_C_SHORT
integer(kind=c_int), public, parameter :: D_RED = 1_C_INT
integer(kind=c_short), public, parameter :: D_RIGHT = 8_C_SHORT
integer(kind=c_short), public, parameter :: D_THICK = 1_C_SHORT
integer(kind=c_short), public, parameter :: D_THIN = 0_C_SHORT
integer(kind=c_short), public, parameter :: D_TOP = 16_C_SHORT
integer(kind=c_int), public, parameter :: D_WHITE = 7_C_INT
integer(kind=c_short), public, parameter :: D_XCENTERED = 1_C_SHORT
integer(kind=c_short), public, parameter :: D_YCENTERED = 2_C_SHORT
integer(kind=c_int), public, parameter :: D_YELLOW = 3_C_INT
integer, public, save :: P_ColorMap(3,0:255)
logical, public, save :: P_debug = .false.
integer, public, save, allocatable :: P_pixel(:,:)

Interfaces

public interface d2r

  • private elemental function d2r_d(degrees)

    Arguments

    Type IntentOptional Attributes Name
    doubleprecision, intent(in) :: degrees

    Return Value doubleprecision

  • private elemental function d2r_r(degrees)

    NAME

    d2r(3f) - [M_pixel:TRIGONOMETRY] convert degrees to radians
    (LICENSE:PD)
    

    SYNOPSIS

    elemental real function d2r(degrees)
    
     class(*),intent(in) :: radians
    

    DESCRIPTION

    Converts degrees to radians using the formula:
    
     radians=real(degrees*acos(-1.0d0)/180.d0)
    

    OPTIONS

    degrees    any standard scalar value supported by anyscalar_to_real(3f).
               This includes REAL, INTEGER, DOUBLEPRECISION, ... .
    

    EXAMPLE

    Sample program

    program demo_d2r
    use M_pixel, only :  d2r
    implicit none
       write(*,*)'With REAL array input    ', &
        & d2r([0.0,45.0,90.0,135.0,180.0])
       write(*,*)'With INTEGER array input ', &
        & d2r([0,  45,  90,  135,  180  ])
       write(*,*)'With DOUBLEPRECISION     ', &
        & d2r(0.0d0),d2r(45.0d0),d2r(90.0d0),d2r(135.0d0),d2r(180.0d0)
    end program demo_d2r
    

    Results

    With REAL array input    0.00000 0.785398185 1.57079637
    2.35619450 3.14159274
    With INTEGER array input 0.00000 0.785398185 1.57079637
    2.35619450 3.14159274
    With DOUBLEPRECISION     0.00000 0.785398185 1.57079637
    2.35619450 3.14159274
    

    AUTHOR

    John S. Urban
    

    LICENSE

    Public Domain
    

    Arguments

    Type IntentOptional Attributes Name
    real, intent(in) :: degrees

    Return Value real

  • private elemental function d2r_i(idegrees)

    Arguments

    Type IntentOptional Attributes Name
    integer, intent(in) :: idegrees

    Return Value doubleprecision

public interface drawstr

  • private subroutine msg_scalar(generic0, generic1, generic2, generic3, generic4, generic5, generic6, generic7, generic8, generic9, generica, genericb, genericc, genericd, generice, genericf, genericg, generich, generici, genericj, sep)

    NAME

    drawstr(3f) - [M_msg] converts any standard scalar type to a string and prints it
    (LICENSE:PD)
    

    SYNOPSIS

    subroutine drawstr(g0,g1,g2,g3,g4,g5,g6,g7,g8,g9,ga,gb,gc,gd,ge,gf,gg,gh,gi,gj,sep)
    
     class(*),intent(in),optional  :: g0,g1,g2,g3,g4,g5,g6,g7,g8,g9
     class(*),intent(in),optional  :: ga,gb,gc,gd,ge,gf,gg,gh,gi,gj
     character(len=*),intent(in),optional :: sep
     character(len=:),allocatable  :: sep_local
    

    DESCRIPTION

    drawstr(3f) builds a space-separated string from up to twenty scalar values.
    

    OPTIONS

    g[0-9a-j]   optional value to print the value of after the message. May
                be of type INTEGER, LOGICAL, REAL, DOUBLEPRECISION,
                COMPLEX, or CHARACTER.
    
                Optionally, all the generic values can be
                single-dimensioned arrays. Currently, mixing scalar
                arguments and array arguments is not supported.
    
    sep         separator between values. Defaults to a space.
    

    EXAMPLES

    Sample program:

    program demo_msg
    use M_pixel, only : str
    implicit none
    character(len=:),allocatable :: pr
    character(len=:),allocatable :: frmt
    integer                      :: biggest
    
       pr=str('HUGE(3f) integers',huge(0),'and real',huge(0.0),'and double',huge(0.0d0))
       write(*,'(a)')pr
       pr=str('real            :',huge(0.0),0.0,12345.6789,tiny(0.0) )
       write(*,'(a)')pr
       pr=str('doubleprecision :',huge(0.0d0),0.0d0,12345.6789d0,tiny(0.0d0) )
       write(*,'(a)')pr
       pr=str('complex         :',cmplx(huge(0.0),tiny(0.0)) )
       write(*,'(a)')pr
    
       ! create a format on the fly
       biggest=huge(0)
       frmt=str('(*(i',int(log10(real(biggest))),':,1x))',sep='')
       write(*,*)'format=',frmt
    
       ! although it will often work, using str(3f) in an I/O statement is not recommended
       ! because if an error occurs str(3f) will try to write while part of an I/O statement
       ! which not all compilers can handle and is currently non-standard
       write(*,*)str('program will now stop')
    
    end program demo_msg
    

    Output

    HUGE(3f) integers 2147483647 and real 3.40282347E+38 and double 1.7976931348623157E+308
    real            : 3.40282347E+38 0.00000000 12345.6787 1.17549435E-38
    doubleprecision : 1.7976931348623157E+308 0.0000000000000000 12345.678900000001 2.2250738585072014E-308
    complex         : (3.40282347E+38,1.17549435E-38)
     format=(*(i9:,1x))
     program will now stop
    

    AUTHOR

    John S. Urban
    

    LICENSE

    Public Domain
    

    Arguments

    Type IntentOptional Attributes Name
    class(*), intent(in), optional :: generic0
    class(*), intent(in), optional :: generic1
    class(*), intent(in), optional :: generic2
    class(*), intent(in), optional :: generic3
    class(*), intent(in), optional :: generic4
    class(*), intent(in), optional :: generic5
    class(*), intent(in), optional :: generic6
    class(*), intent(in), optional :: generic7
    class(*), intent(in), optional :: generic8
    class(*), intent(in), optional :: generic9
    class(*), intent(in), optional :: generica
    class(*), intent(in), optional :: genericb
    class(*), intent(in), optional :: genericc
    class(*), intent(in), optional :: genericd
    class(*), intent(in), optional :: generice
    class(*), intent(in), optional :: genericf
    class(*), intent(in), optional :: genericg
    class(*), intent(in), optional :: generich
    class(*), intent(in), optional :: generici
    class(*), intent(in), optional :: genericj
    character(len=*), intent(in), optional :: sep
  • private subroutine msg_one(generic0, generic1, generic2, generic3, generic4, generic5, generic6, generic7, generic8, generic9, sep)

    Arguments

    Type IntentOptional Attributes Name
    class(*), intent(in) :: generic0(:)
    class(*), intent(in), optional :: generic1(:)
    class(*), intent(in), optional :: generic2(:)
    class(*), intent(in), optional :: generic3(:)
    class(*), intent(in), optional :: generic4(:)
    class(*), intent(in), optional :: generic5(:)
    class(*), intent(in), optional :: generic6(:)
    class(*), intent(in), optional :: generic7(:)
    class(*), intent(in), optional :: generic8(:)
    class(*), intent(in), optional :: generic9(:)
    character(len=*), intent(in), optional :: sep

Derived Types

type, public ::  MATRIX

Components

Type Visibility Attributes Name Initial
real(kind=C_FLOAT), public, dimension(4,4) :: ARRAY

Functions

public elemental function cosd(angle_in_degrees)

Arguments

Type IntentOptional Attributes Name
class(*), intent(in) :: angle_in_degrees

Return Value real

public function i2s(ivalue) result(outstr)

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: ivalue

Return Value character(len=:), allocatable

public pure elemental function lower(str) result(string)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str

Return Value character(len=len(str))

public elemental function sind(angle_in_degrees)

Arguments

Type IntentOptional Attributes Name
class(*), intent(in) :: angle_in_degrees

Return Value real

public function strlength(string)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: string

Return Value real


Subroutines

public subroutine arc(x, y, radius, startang, endang)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
real, intent(in) :: x
real, intent(in) :: y
real, intent(in) :: radius
real, intent(in) :: startang
real, intent(in) :: endang

public subroutine centertext(onoff)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
logical, intent(in) :: onoff

public subroutine circle(x, y, radius)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
real, intent(in) :: x
real, intent(in) :: y
real, intent(in) :: radius

public subroutine circleprecision(nsegs)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: nsegs

public subroutine clear(indx)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
integer, intent(in), optional :: indx

public subroutine closepoly()

definition:

Read more…

Arguments

None

public subroutine closest_color_name(r, g, b, closestname)

Read more…

Arguments

Type IntentOptional Attributes Name
real, intent(in) :: r
real, intent(in) :: g
real, intent(in) :: b
character(len=*), intent(out) :: closestname

public subroutine color(icolor)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: icolor

public subroutine color_name2rgb(name, r, g, b, echoname)

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: name
real, intent(out) :: r
real, intent(out) :: g
real, intent(out) :: b
character(len=*), intent(out), optional :: echoname

public impure elemental subroutine draw2(x, y)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
real, intent(in) :: x
real, intent(in) :: y

public subroutine drawchar(ch)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=1), intent(in) :: ch

public subroutine font(fontname)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: fontname

public subroutine getdisplaysize(w, h)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
real, intent(out) :: w
real, intent(out) :: h

public subroutine getgp2(x, y)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
real, intent(out) :: x
real, intent(out) :: y

public subroutine getviewport(left, right, bottom, top)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
real, intent(out) :: left
real, intent(out) :: right
real, intent(out) :: bottom
real, intent(out) :: top

public subroutine hershey(x, y, height, itext, theta, ntext)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
real, intent(in) :: x
real, intent(in) :: y
real, intent(in) :: height
character(len=*), intent(in) :: itext
real, intent(in) :: theta
integer, intent(in) :: ntext

public subroutine hue(modei, clr1i, clr2i, clr3i, modeo, clr1o, clr2o, clr3o, status)

Sample program

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: modei
real, intent(in) :: clr1i
real, intent(in) :: clr2i
real, intent(in) :: clr3i
character(len=*), intent(in) :: modeo
real, intent(out) :: clr1o
real, intent(out) :: clr2o
real, intent(out) :: clr3o
integer, intent(out) :: status

public subroutine justfy(s, height, text, ntext)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
real, intent(out) :: s(4)
real, intent(in) :: height
character(len=*), intent(in) :: text
integer, intent(in) :: ntext

public subroutine line(x1, y1, x2, y2)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
real, intent(in) :: x1
real, intent(in) :: y1
real, intent(in) :: x2
real, intent(in) :: y2

public subroutine linewidth(iwidth)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: iwidth

public subroutine makepoly()

definition:

Read more…

Arguments

None

public impure elemental subroutine mapcolor(indx, red, green, blue)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: indx
integer, intent(in) :: red
integer, intent(in) :: green
integer, intent(in) :: blue

public subroutine move2(x, y)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
real, intent(in) :: x
real, intent(in) :: y

public subroutine ortho2(left, right, bottom, top)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
real, intent(in) :: left
real, intent(in) :: right
real, intent(in) :: bottom
real, intent(in) :: top

public subroutine page(xsmall, xlarge, ysmall, ylarge)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
real, intent(in) :: xsmall
real, intent(in) :: xlarge
real, intent(in) :: ysmall
real, intent(in) :: ylarge

public impure elemental subroutine pixel(row, column, indx)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: row
integer, intent(in) :: column
integer, intent(in), optional :: indx

public impure elemental subroutine point2(x, y)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
real, intent(in) :: x
real, intent(in) :: y

public subroutine polar_to_cartesian(radius, inclination, x, y)

examples of usage

Read more…

Arguments

Type IntentOptional Attributes Name
real, intent(in) :: radius
real, intent(in) :: inclination
real, intent(out) :: x
real, intent(out) :: y

public subroutine poly2(n, points)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: n
real, intent(in) :: points(2,n)

public subroutine polyline2(x, y)

Sample program:

Read more…

Arguments

Type IntentOptional Attributes Name
class(*), intent(in) :: x(:)
class(*), intent(in), optional :: y(:)

public subroutine prefsize(x, y)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: x
integer, intent(in) :: y

public subroutine print_ansi(filename)

print_ansi(3f) - [M_pixel:PRINT] print small pixel array as colored text on terminals and terminal emulators that obey ANSI escape sequences (LICENSE:PD)

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in), optional :: filename

public subroutine print_ascii(filename)

print_ascii(3f) - [M_pixel:PRINT] print small pixel array as ASCII text (LICENSE:PD)

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in), optional :: filename

public subroutine print_p3(filename)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: filename

public subroutine print_p6(filename)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: filename

public subroutine print_ppm(filename)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: filename

public impure elemental subroutine rdraw2(xdelta, ydelta)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
real, intent(in) :: xdelta
real, intent(in) :: ydelta

public subroutine rect(x1, y1, x2, y2)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
real, intent(in) :: x1
real, intent(in) :: y1
real, intent(in) :: x2
real, intent(in) :: y2

public subroutine rgbmono(rr, rg, rb, ri, status)

Arguments

Type IntentOptional Attributes Name
real, intent(in) :: rr
real, intent(in) :: rg
real, intent(in) :: rb
real, intent(out) :: ri
integer, intent(out) :: status

public subroutine rmove2(Xdelta, Ydelta)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
real, intent(in) :: Xdelta
real, intent(in) :: Ydelta

public recursive subroutine state(string)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in), optional :: string

public subroutine textang(ang)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
real, intent(in) :: ang

public subroutine textsize(width, height)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
real, intent(in) :: width
real, intent(in) :: height

public subroutine vexit()

definition:

Read more…

Arguments

None

public subroutine vflush()

Arguments

None

public subroutine viewport(left, right, bottom, top)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
real, intent(in) :: left
real, intent(in) :: right
real, intent(in) :: bottom
real, intent(in) :: top

public subroutine vinit(string)

definition:

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), optional :: string

public subroutine xcentertext()

definition:

Read more…

Arguments

None

public subroutine ycentertext()

definition:

Read more…

Arguments

None