-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
1,902 additions
and
2,107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,36 @@ | ||
module fig_canvas | ||
use fig_config | ||
use fig_shapes | ||
use fig_types | ||
implicit none | ||
|
||
type, abstract :: base_canvas | ||
type(canvas_size) :: size | ||
character(len=:), allocatable :: title | ||
contains | ||
procedure(canvas_draw_shape), deferred :: draw_shape | ||
procedure :: init | ||
end type base_canvas | ||
use fig_config | ||
use fig_shapes | ||
use fig_types | ||
implicit none | ||
|
||
abstract interface | ||
subroutine canvas_draw_shape(canva,sh) | ||
import base_canvas, shape | ||
class(base_canvas), intent(inout) :: canva | ||
class(shape), intent(in) :: sh | ||
end subroutine canvas_draw_shape | ||
end interface | ||
type, abstract :: base_canvas | ||
type(canvas_size) :: size | ||
character(len=:), allocatable :: title | ||
contains | ||
procedure(canvas_draw_shape), deferred :: draw_shape | ||
procedure :: init | ||
end type base_canvas | ||
|
||
abstract interface | ||
subroutine canvas_draw_shape(canva, sh) | ||
import base_canvas, shape | ||
class(base_canvas), intent(inout) :: canva | ||
class(shape), intent(in) :: sh | ||
end subroutine canvas_draw_shape | ||
end interface | ||
|
||
contains | ||
|
||
subroutine init(this, width, height, title) | ||
class(base_canvas), intent(inout) :: this | ||
integer, intent(in) :: width, height | ||
character(len=*), intent(in) :: title | ||
subroutine init(this, width, height, title) | ||
class(base_canvas), intent(inout) :: this | ||
integer, intent(in) :: width, height | ||
character(len=*), intent(in) :: title | ||
|
||
this%size%width = width | ||
this%size%height = height | ||
this%title=title | ||
this%size%width = width | ||
this%size%height = height | ||
this%title = title | ||
|
||
end subroutine init | ||
end subroutine init | ||
|
||
end module fig_canvas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,58 @@ | ||
module fig_drawing | ||
use fig_config | ||
use fig_shapes | ||
use fig_rgb | ||
use fig_rgb_color_constants | ||
implicit none | ||
use fig_config | ||
use fig_shapes | ||
use fig_rgb | ||
use fig_rgb_color_constants | ||
implicit none | ||
|
||
type,private :: shape_wrapper | ||
type, private :: shape_wrapper | ||
class(shape), allocatable :: sh | ||
end type | ||
|
||
type :: drawing | ||
type(shape_wrapper), allocatable :: shapes(:) | ||
type(RGB) :: background = FIG_COLOR_BLANK | ||
integer :: shape_count | ||
contains | ||
procedure :: add_shape | ||
procedure :: init | ||
end type drawing | ||
end type | ||
|
||
type :: drawing | ||
type(shape_wrapper), allocatable :: shapes(:) | ||
type(RGB) :: background = FIG_COLOR_BLANK | ||
integer :: shape_count | ||
contains | ||
procedure :: add_shape | ||
procedure :: init | ||
end type drawing | ||
|
||
contains | ||
|
||
subroutine init(this) | ||
class(drawing), intent(inout) :: this | ||
this%shape_count = 0 | ||
allocate(this%shapes(0)) | ||
end subroutine init | ||
|
||
subroutine add_shape(this, s) | ||
class(drawing), intent(inout) :: this | ||
class(shape), intent(in), target :: s | ||
integer :: new_size | ||
type(shape_wrapper), allocatable :: temp(:) | ||
|
||
if (this%shape_count >= size(this%shapes)) then | ||
new_size = max(1, 2 * size(this%shapes)) | ||
|
||
if (this%shape_count > 0) then | ||
allocate(temp(this%shape_count)) | ||
temp = this%shapes(1:this%shape_count) | ||
endif | ||
deallocate(this%shapes) | ||
allocate(this%shapes(new_size)) | ||
if (this%shape_count > 0) then | ||
this%shapes(1:this%shape_count) = temp | ||
deallocate(temp) | ||
endif | ||
|
||
endif | ||
|
||
this%shape_count = this%shape_count + 1 | ||
allocate(this%shapes(this%shape_count)%sh, source=s) | ||
end subroutine add_shape | ||
subroutine init(this) | ||
class(drawing), intent(inout) :: this | ||
this%shape_count = 0 | ||
allocate (this%shapes(0)) | ||
end subroutine init | ||
|
||
subroutine add_shape(this, s) | ||
class(drawing), intent(inout) :: this | ||
class(shape), intent(in), target :: s | ||
integer :: new_size | ||
type(shape_wrapper), allocatable :: temp(:) | ||
|
||
if (this%shape_count >= size(this%shapes)) then | ||
new_size = max(1, 2*size(this%shapes)) | ||
|
||
if (this%shape_count > 0) then | ||
allocate (temp(this%shape_count)) | ||
temp = this%shapes(1:this%shape_count) | ||
end if | ||
|
||
deallocate (this%shapes) | ||
allocate (this%shapes(new_size)) | ||
|
||
if (this%shape_count > 0) then | ||
this%shapes(1:this%shape_count) = temp | ||
deallocate (temp) | ||
end if | ||
|
||
end if | ||
|
||
this%shape_count = this%shape_count + 1 | ||
allocate (this%shapes(this%shape_count)%sh, source=s) | ||
end subroutine add_shape | ||
|
||
end module fig_drawing | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,84 @@ | ||
module fig_path | ||
use fig_shapes | ||
implicit none | ||
|
||
type, extends(shape) :: path | ||
character(len=:), allocatable :: path_string | ||
contains | ||
procedure :: move_to | ||
procedure :: line_to | ||
procedure :: bezier_curve_to | ||
procedure :: quadratic_curve_to | ||
procedure :: elliptical_arc_to | ||
procedure :: close_path | ||
end type path | ||
use fig_shapes | ||
implicit none | ||
|
||
type, extends(shape) :: path | ||
character(len=:), allocatable :: path_string | ||
contains | ||
procedure :: move_to | ||
procedure :: line_to | ||
procedure :: bezier_curve_to | ||
procedure :: quadratic_curve_to | ||
procedure :: elliptical_arc_to | ||
procedure :: close_path | ||
end type path | ||
|
||
contains | ||
|
||
subroutine move_to(this, x, y) | ||
class(path), intent(inout) :: this | ||
real, intent(in) :: x, y | ||
character(len=30) :: command | ||
|
||
write(command, '(A,F6.2,A,F6.2,A)') "M ", x, " ", y | ||
this%path_string = trim(this%path_string) // trim(command) | ||
end subroutine move_to | ||
|
||
subroutine line_to(this, x, y) | ||
class(path), intent(inout) :: this | ||
real, intent(in) :: x, y | ||
character(len=30) :: command | ||
|
||
write(command, '(A,F6.2,A,F6.2,A)') "L ", x, " ", y | ||
this%path_string = trim(this%path_string) // trim(command) | ||
end subroutine line_to | ||
|
||
subroutine bezier_curve_to(this, x1, y1, x2, y2, x, y) | ||
class(path), intent(inout) :: this | ||
real, intent(in) :: x1, y1, x2, y2, x, y | ||
character(len=50) :: command | ||
|
||
write(command, '(A,F6.2,A,F6.2,A,F6.2,A,F6.2,A,F6.2,A,F6.2,A)') "C ", x1, " ", y1, " ", x2, " ", y2, " ", x, " ", y | ||
|
||
this%path_string = trim(this%path_string) // trim(command) | ||
end subroutine bezier_curve_to | ||
|
||
subroutine quadratic_curve_to(this, x1, y1, x, y) | ||
class(path), intent(inout) :: this | ||
real, intent(in) :: x1, y1, x, y | ||
character(len=50):: command | ||
|
||
write(command, '(A,F6.2,A,F6.2,A,F6.2,A,F6.2,A)') "Q ", x1, " ", y1, " ", x, " ", y, " " | ||
this%path_string = trim(this%path_string) // trim(command) | ||
end subroutine quadratic_curve_to | ||
|
||
subroutine elliptical_arc_to(this, rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, x, y) | ||
class(path), intent(inout) :: this | ||
real, intent(in) :: rx, ry, x_axis_rotation, x, y | ||
integer, intent(in) :: large_arc_flag, sweep_flag | ||
character(len=80) :: command | ||
|
||
write(command, '(A,F6.2,A,F6.2,A,F6.2,A,I0,A,I0,A,F6.2,A,F6.2,A)') & | ||
"A ", rx, " ", ry, " ", x_axis_rotation, " ", large_arc_flag, " ", & | ||
sweep_flag, " ", x, " ", y | ||
this%path_string = trim(this%path_string) // trim(command) | ||
end subroutine elliptical_arc_to | ||
|
||
subroutine close_path(this) | ||
class(path), intent(inout) :: this | ||
|
||
this%path_string = trim(this%path_string) // "Z " | ||
end subroutine close_path | ||
subroutine move_to(this, x, y) | ||
class(path), intent(inout) :: this | ||
real, intent(in) :: x, y | ||
character(len=30) :: command | ||
|
||
write (command, '(A,F6.2,A,F6.2,A)') "M ", x, " ", y | ||
this%path_string = trim(this%path_string)//trim(command) | ||
end subroutine move_to | ||
|
||
subroutine line_to(this, x, y) | ||
class(path), intent(inout) :: this | ||
real, intent(in) :: x, y | ||
character(len=30) :: command | ||
|
||
write (command, '(A,F6.2,A,F6.2,A)') "L ", x, " ", y | ||
this%path_string = trim(this%path_string)//trim(command) | ||
end subroutine line_to | ||
|
||
subroutine bezier_curve_to(this, x1, y1, x2, y2, x, y) | ||
! x1, y1 - Coordinates of the first control point for the Bezier curve. | ||
! x2, y2 - Coordinates of the second control point for the Bezier curve. | ||
! x, y - Coordinates of the end point of the Bezier curve. | ||
class(path), intent(inout) :: this | ||
real, intent(in) :: x1, y1, x2, y2, x, y | ||
character(len=50) :: command | ||
|
||
write (command, '(A,F6.2,A,F6.2,A,F6.2,A,F6.2,A,F6.2,A,F6.2,A)') "C ", x1, " ", y1, " ", x2, " ", y2, " ", x, " ", y | ||
|
||
this%path_string = trim(this%path_string)//trim(command) | ||
end subroutine bezier_curve_to | ||
|
||
subroutine quadratic_curve_to(this, x1, y1, x, y) | ||
! x1, y1 - Coordinates of the control point for the quadratic curve. | ||
! x, y - Coordinates of the end point of the quadratic curve. | ||
class(path), intent(inout) :: this | ||
real, intent(in) :: x1, y1, x, y | ||
character(len=50):: command | ||
|
||
write (command, '(A,F6.2,A,F6.2,A,F6.2,A,F6.2,A)') "Q ", x1, " ", y1, " ", x, " ", y, " " | ||
this%path_string = trim(this%path_string)//trim(command) | ||
end subroutine quadratic_curve_to | ||
|
||
subroutine elliptical_arc_to(this, rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, x, y) | ||
! rx - Radius of the ellipse in the x direction. | ||
! ry - Radius of the ellipse in the y direction. | ||
! x_axis_rotation - Rotation of the ellipse in degrees. | ||
! large_arc_flag - Flag indicating if the arc should be greater than 180 degrees (1 for true, 0 for false). | ||
! sweep_flag - Flag indicating the direction of the arc (1 for clockwise, 0 for counterclockwise). | ||
! x, y - Coordinates of the end point of the arc. | ||
class(path), intent(inout) :: this | ||
real, intent(in) :: rx, ry, x_axis_rotation, x, y | ||
integer, intent(in) :: large_arc_flag, sweep_flag | ||
character(len=80) :: command | ||
|
||
write (command, '(A,F6.2,A,F6.2,A,F6.2,A,I0,A,I0,A,F6.2,A,F6.2,A)') & | ||
"A ", rx, " ", ry, " ", x_axis_rotation, " ", large_arc_flag, " ", & | ||
sweep_flag, " ", x, " ", y | ||
this%path_string = trim(this%path_string)//trim(command) | ||
end subroutine elliptical_arc_to | ||
|
||
subroutine close_path(this) | ||
class(path), intent(inout) :: this | ||
|
||
this%path_string = trim(this%path_string)//"Z " | ||
end subroutine close_path | ||
|
||
end module fig_path |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.