line(3f) - [M_pixel:DRAW] draw line between two points
(LICENSE:PD)
definition:
subroutine line(x1,y1, x2,y2 )
real,intent(in) :: x1,y1,x2,y2
Draw line between two points using current line width and color
X1,Y1 starting point for line segment
X2,Y2 end point for line segment
John S. Urban
Public Domain
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real, | intent(in) | :: | x1 | |||
real, | intent(in) | :: | y1 | |||
real, | intent(in) | :: | x2 | |||
real, | intent(in) | :: | y2 |
subroutine line(x1,y1, x2,y2 )
! ident_2="@(#) M_pixel line(3f) draw line between two points applying line width and color"
real,intent(in) :: x1,y1,x2,y2
real :: xx1,yy1,xx2,yy2
integer :: i
integer :: ix1,iy1,ix2,iy2
P_x=x2 ! update current position
P_y=y2
if(P_debug)write(*,*)'linewidth ',P_width,';move2 ',x1,y1,';draw2 ',x2,y2
!-----------------------------------------------------------------------------------------------------------------------------------
! allow collecting points in a continuous polyline into a polygon as a first cut using makepoly(3f) and closepoly(3f)
! assuming all line drawing goes thru this routine, and using fixed size array
if(P_inpolygon)then
if(P_polyvertex.gt.P_MAXVERTS)then
write(*,*)'*P_line* exceeded limit on number of points in a polygon (',P_MAXVERTS,')'
else
if(P_polyvertex.eq.1)then
P_polypoints(1,1)=x1
P_polypoints(2,1)=y1
P_polyvertex=P_polyvertex+1
endif
P_polypoints(1,P_polyvertex)=x2
P_polypoints(2,P_polyvertex)=y2
P_polyvertex=P_polyvertex+1
endif
return
endif
!-----------------------------------------------------------------------------------------------------------------------------------
call world2viewport(x1,y1,xx1,yy1) ! convert from world coordinates to pixel array addresses
call world2viewport(x2,y2,xx2,yy2)
ix1=nint(xx1) ! change values to integers
iy1=nint(yy1)
ix2=nint(xx2)
iy2=nint(yy2)
select case(P_width)
case(:1)
call draw_line_single(ix1, iy1 , ix2, iy2 ) ! draw line
case(2:5)
do i=1,P_width/2 ! thicken line NEEDS BETTER METHOD
call draw_line_single(ix1+i, iy1 , ix2+i, iy2 )
call draw_line_single(ix1 , iy1+i, ix2 , iy2+i)
enddo
do i=1,(P_width-1)/2
call draw_line_single(ix1-i, iy1 , ix2-i, iy2 )
call draw_line_single(ix1 , iy1-i, ix2 , iy2-i)
enddo
case(6:)
call PPM_draw_thick_line(ix1, iy1, ix2, iy2)
end select
end subroutine line