Skip to content

Commit

Permalink
draw arc
Browse files Browse the repository at this point in the history
  • Loading branch information
AnonMiraj committed Jul 10, 2024
1 parent 38ceb37 commit c153d7b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 15 deletions.
9 changes: 8 additions & 1 deletion src/backends/fig_shapes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ module fig_shapes
use fig_rgb

type, abstract :: shape
type(RGB) :: fill_color = FIG_COLOR_BLACK
type(RGB) :: fill_color = FIG_COLOR_BLANK
type(RGB) :: stroke_color = FIG_COLOR_BLANK
real(kind=8) :: stroke_width =1
end type shape

type, extends(shape) :: arc
type(point) :: center
real (kind=8):: r
real (kind=8):: start_angle
real (kind=8):: end_angle
end type arc

type, extends(shape) :: circle
type(point) :: center
real (kind=8):: r
Expand Down
3 changes: 3 additions & 0 deletions src/backends/generic_cairo/cairo_backend.f90
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module fig_cairo
use fig_cairo_circle
use fig_cairo_ellipse
use fig_cairo_line
use fig_cairo_arc
use fig_path
use fig_cairo_path
use fig_cairo_poly
Expand Down Expand Up @@ -72,6 +73,8 @@ subroutine cairo_write_shape(canva,sh)
call write_polyline(canva, canva%cairo, sh)
type is (polygon)
call write_polygon(canva, canva%cairo, sh)
type is (arc)
call write_arc(canva, canva%cairo, sh)
end select

end subroutine cairo_write_shape
Expand Down
23 changes: 23 additions & 0 deletions src/backends/generic_cairo/shapes/arc.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module fig_cairo_arc
use cairo
use fig_shapes
use fig_canvas
use fig_cairo_utils

contains

subroutine write_arc(canva, cr, sh)
class(base_canvas), intent(inout) :: canva
type(c_ptr), intent(inout):: cr
type(arc), intent(in) :: sh
type(canvas_point) :: c

c = to_canvas ( sh%center , canva%size)
call cairo_arc(cr, c%x, c%y, sh%r, sh%start_angle, sh%end_angle)
call fill(cr,sh)
call stroke(cr,sh)

end subroutine write_arc

end module fig_cairo_arc

29 changes: 15 additions & 14 deletions test/drawing_test.f90
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ program drawing_test_all
type(triangle) :: tri
type(line) :: l
type(ellipse) :: elp
type(arc) :: ar
type(RGB) :: bg, color
type(svg_canvas) :: svg_canva
type(bitmap_canvas) :: bitmap_canva
file_name='test_all'
real(8) :: pi = 4.0d0 * atan(1.0d0)
file_name = "test_all"
bg = FIG_COLOR_WHITE

call canva%init()
call canva%set_background(bg)

! Circle
! Circle
c%center%x = 100.0 / CANVAS_WIDTH
c%center%y = 100.0 / CANVAS_HEIGHT
c%r = 50.0
Expand Down Expand Up @@ -104,18 +106,17 @@ program drawing_test_all
call canva%add_shape(l)


! Triangle
tri%p1%x = 450.0 / CANVAS_WIDTH
tri%p1%y = 150.0 / CANVAS_HEIGHT
tri%p2%x = 550.0 / CANVAS_WIDTH
tri%p2%y = 250.0 / CANVAS_HEIGHT
tri%p3%x = 450.0 / CANVAS_WIDTH
tri%p3%y = 350.0 / CANVAS_HEIGHT
tri%fill_color = FIG_COLOR_SILVER
tri%fill_color%a = 100
tri%stroke_color = FIG_COLOR_RED
call canva%add_shape(tri)

! arc
ar%center%x = 300.0 / CANVAS_WIDTH
ar%center%y = 400.0 / CANVAS_HEIGHT
ar%r = 50.0
ar%start_angle= 0
ar%end_angle= pi * 1.2
ar%fill_color = FIG_COLOR_INDIGO
ar%fill_color%a=100
ar%stroke_color = FIG_COLOR_BROWN
call canva%add_shape(ar)

call svg_canva%init(CANVAS_WIDTH,CANVAS_HEIGHT,file_name)
call svg_canva%apply_shapes(canva)
call svg_canva%save_to_svg()
Expand Down

0 comments on commit c153d7b

Please sign in to comment.