Skip to content

Drawing

Cameron Kirk edited this page Dec 3, 2023 · 3 revisions

Drawing

The Draw module exposes a series of functions for drawing graphics primitives. The list of graphics primitives currently implemented in SDLCanvas are as follows:

  • draw_pixel
  • draw_line
  • draw_arc
  • draw_filled_arc
  • draw_circle
  • draw_filled_circle
  • draw_rect
  • draw_filled_rect

Note: None of the graphics primitives implemented in SDLCanvas have anti-aliasing capabilities. For now, this is due to a lack of bindings for the the SDL_gfx C library for Julia.


API Reference

Note: For clarity, not all variants of each graphics function have been included. Most notably, any of the colour arguments can be provided either as a ColourRGBA type, a 4-integer tuple Tuple{Int, Int, Int, Int} as (r, g, b, a) or a 3-integer tuple Tuple{Int, Int, Int} as (r, g, b) with the alpha value defaulting to 255.

draw_pixel(window::Window, x::Int, y::Int, colour::ColourRGBA)

Draws a single pixel at pixel position (x, y) with the given colour

draw_line(window::Window, x1::Int, y1::Int, x2::Int, y2::Int, colour::ColourRGBA; kwargs...)

Draws a straight line from pixel coordinates (x1, y1) to (x2_y2) with the given colour. Possible keyword arguments are:

  • thickness::Int = 1 : The thickness of the line in pixels

draw_arc(window::Window, x::Int, y::Int, r::Int, start_angle::Real, end_angle::Real, colour::ColourRGBA)

Draws an arc centred at pixel coordinates (x, y) with radius r with the given colour. The arc is drawn from start_angle to end_angle in a counter-clockwise direction. The start and end angles should be provided in radians between 0 and $2\pi$. The end angle must be greater than the start angle. An angle of $\theta=0$ corresponds with the positive x-axis.

draw_circle(window::Window, x::Int, y::Int, r::Int, colour::ColourRGBA)

Draws a circle centred at pixel coordinates (x, y) with radius r with the given colour.

draw_rect(window::Window, x::Int, y::Int, w::Int, h::Int, colour::ColourRGBA)

Draws a rectangle with width w and height h with the given colour. The pixel coordinates (x, y) correspond to the top-left corner of the rectangle.