API Documentation for CanvasDraw 4.0


This is a post that documents all of the properties, events, functions, objects and methods of the CanvasDraw Module. You can find more information about the module here:


Table of Contents:

Module

  • CanvasDraw Functions
    • .new()
    • .GetImageData()
    • .GetImageDataFromTextureId()
    • .CreateBlankImageData()
    • .CompressImageData()
    • .DecompressImageData()
    • .CreateSaveObject()
    • .CreateSaveObjectFromPixels()

Canvas

  • Canvas Events
    • .OnRendered
  • Canvas Methods
    • :Render()
    • :CreateImageDataFromCanvas()
    • :Destroy()
  • Canvas Fetch Methods
    • :GetPixel()
    • :GetRGB()
    • :GetAlpha()
    • :GetPixels()
    • :GetMousePoint()
    • :ViewportToCanvasPoint()
    • :MouseIsOnTop()
  • Canvas Drawing Methods
    • :Fill()
    • :Clear()
    • :FloodFill()
    • :DrawPixel()
    • :SetPixel()
    • :SetRGB()
    • :SetAlpha()
    • :DrawCircle()
    • :DrawRectangle()
    • :DrawTriangle()
    • :DrawLine()
    • :DrawImage()
    • :DrawTexturedTriangle()
    • :DrawDistortedImage()
    • :DrawRotatedImage()
    • :DrawImageRect()
    • :DrawText()

ImageData

  • ImageData Methods
    • :GetPixel()
    • :GetRGB()
    • :GetRGBA()
    • :SetPixel()
    • :SetRGB()
    • :SetRGBA()
    • :Tint()
    • :TintRGB()
    • :Clone()
    • :Freeze()
9 Likes

CanvasDraw Functions:


CanvasDraw.new (Parent: Instance, Resolution: Vector2?, CanvasColour: Color3?) : Canvas

  • This will create and return a canvas. This can be used on a GuiObject (such as a Frame), Decal, Texture, MeshPart or SurfeaceAppereance.
Example
Canvas = CanvasDraw.new(
    Frame, -- Put the canvas in this frame
    Vector.new(150, 75), -- Give the a rectangle shape resolution
    Color3.new(1, 0, 0) -- Give the canvas a red background colour
)
Parameters and Returns

Parameters:

Parent Instance

  • Default:
  • Description: The GuiObject or Image-based instance that the canvas will be parented to. Such as a Frame, Decal, Texture, MeshPart or SurfaceAppearance

Resolution Vector2?

  • Default: Vector2.new(100, 100)
  • Description: The size that determines how many pixels are created. For example, a resolution of 150 x 150 will create a canvas with a grid of 22500 pixels that can be changed.

CanvasColour Color3?

  • Default: Frame.BackgroundColor3
  • Description: The colour that will be applied to all of the generated pixels. This colour will then be treated as the background colour for the canvas. This background colour can be used for clearing or delete functions such as ClearPixels().
  • If this parameter is empty, the colour will be the same as your chosen canvas frame’s BackgroundColor3 property.

Blur boolean?

  • Default: false
  • Description: Determines if the canvas should have sharp, or blurred pixels. This parameter only works if the canvas is parented to a GuiObject.

Returns:

Return Type: Canvas (class/object)
Summary: Returns the canvas class


CanvasDraw.CreateSaveObject (ImageData) : Instance

  • This function will return a folder instance that will be treated as a “SaveObject”. This instance has custom attributes that contain the data of your image. This instance is great as it is treated as an image asset for CanvasDraw. This means you can store images created by CanvasDraw and store them in a storage instance (such as a folder in ReplicatedStorage) and then you can easily load the image into canvas draw to be used when ever you want!

  • NOTE: ImageData on a SaveObject cannot have a resolution greater than 256x256.

Example
local Saves = workspace.Saves -- A folder to store the save object

local ImageData = Canvas:CreateImageDataFromCanvas(
    false, 
    Vector2.new(1, 1), 
    Vector2.new(100, 100)
)

local SaveObject = CanvasDraw.CreateSaveObject(ImageData)
SaveObject.Name = "MyDrawing"
SaveObject.Parent = Saves
Parameters and Returns

Parameters:

ImageData Table

  • Default:
  • Description: The ImageData that you wish to use to create the save object.

Returns:

Return Type: SaveObject (Folder)
Summary: Returns a folder instance that contains compressed ImageData.


CanvasDraw.CreateSaveObjectFromPixels (PixelArray: Table, Width: number, Height: number, InstantCreate: boolean?) : Instance

  • Same as ‘CanvasDraw.CreateSaveObject’, but takes an array of RGBA values with
    a width and height parameter.

  • Intended for plugin use.

  • NOTE: The width and height has to be 256x256 or under!

  • NOTE: This function yields by default!

Parameters and Returns

Parameters:

PixelArray Table

  • Default:
  • Description: The image represented in the form of an array of RGBA values.

Returns:

Width number

  • Default:
  • Description: The image width

Height number

  • Default:
  • Description: The image height

InstantCreate boolean

  • Default: false
  • Description: When set to true, the SaveObject will be instantly created without yielding your code. Otherwise if left empty or set to false, the SaveObject will slowly be created

Returns:

Return Type: SaveObject (Folder)
Summary: Returns a folder instance that contains compressed ImageData.


CanvasDraw.GetImageData (SaveObject: Instance) : ImageData

  • This function will read the SaveObject and return a decompressed ImageData object. This object contains cached pixel data for real-time image manipulation or sampling.
    This object also has a pixel fetch method!
    e.g. ImageData:GetPixel(Point) or ImageData:GetRGB(x, y)
Example
-- Get the save object and it's data
local SaveObject = workspace.Saves.MyFirstDrawing -- Path to the save object
local ImageData = CanvasDraw.GetImageData(SaveObject)

-- Draw the image to the canvas
Canvas:DrawImage(ImageData)

-- Sample the middle pixel from our image (assuming it is a 100x100 image in this case)
local Colour, Alpha = ImageData:GetPixelXY(50, 50)

print("Colour:", Colour) -- The main color3 value
print("Alpha:", Alpha) -- The pixel's transparency value (from 0)
Parameters and Returns

Parameters:

SaveObject Folder

  • Default:
  • Description: The SaveObject instance folder that you wish to grab the ImageData from.

Returns:

Return Type: ImageData (Table)
Summary: The ImageData table that contains all data to your image from the SaveObject instance.


CanvasDraw.GetImageDataFromTextureId (TextureId: string) : ImageData

  • This function will fetch a decompressed ImageData object. This object contains cached pixel data for real-time image manipulation or sampling.

  • NOTE: This function yields!

Example
-- Get the save object and it's data
local AssetId = "rbxassetid://14585145213" -- Your roblox image asset
local ImageData = CanvasDraw.GetImageDataFromTextureId(AssetId)

-- Sample the middle pixel from our image (assuming it is a 1024x1024 image in this case)
local R, G, B, A = ImageData:GetRGBA(512, 512)
Parameters and Returns

Parameters:

TextureId string

  • Default:
  • Description: The roblox texture id of the image you wish to create the ImageData from.

Returns:

Return Type: ImageData (Table)
Summary: The ImageData table that contains all data to your image from the SaveObject instance.


CanvasDraw.CompressImageData (ImageData) : CompressedImageData

  • Returns a compressed image in the form of a very small table which takes advantage of string compression which reduces file size by a lot.
  • Very useful with datastores.
  • NOTE: Large images may cause slight lag spikes
Example
local DatastoreService = game:GetService("DataStoreService")
local ImagesDatastore = DatastoreService:GetDataStore("Images")

local SaveObject = Textures["RobloxNoob.png"] -- Path to your SaveObject
local ImageData = CanvasDraw.GetImageData(SaveObject)

local CompressedData = CanvasDraw.CompressImageData(ImageData)

-- Save the image to the datastore
pcall(function()
	ImagesDatastore:SetAsync(Player.UserId .. "_Image", CompressedData)
end)
Parameters and Returns

Parameters:

ImageData Object

  • Default:
  • Description: The ImageData that you wish to compress.

Returns:

Return Type: CompressedImageData (Object)
Summary: The compressed ImageData object that contains all data to your image.


CanvasDraw.DecompressImageData (CompressedImageData) : ImageData

  • Decompresses the CompressedImageData table, and converts it back to the original ImageData class.
  • Very useful with datastores.
  • NOTE: Large images may cause slight lag spikes
Example
local DatastoreService = game:GetService("DataStoreService")
local ImagesDatastore = DatastoreService:GetDataStore("Images")

-- Fetch the image from the datastore
local CompressedImageData

pcall(function()
	CompressedImageData = ImagesDatastore:GetAsync(Player.UserId .. "_Image")
end)

if CompressedImageData then
    -- Convert compressed data back into the original ImageData class
    local ImageData = CanvasDraw.DecompressImageData(CompressedImageData)
    Canvas:DrawImage(ImageData)
end
Parameters and Returns

Parameters:

CompressedImageData Object

  • Default:
  • Description: The compressed ImageData that you wish to decompress back into the original ImageData class.

Returns:

Return Type: ImageData (Object)
Summary: The ImageData object that contains all data to your image.

1 Like

Canvas Events:

OnRendered double - DeltaTime

  • Fires whenever the canvas renders. This is every frame (RunService.Heartbeat).
  • This event will never fire if ‘Canvas.AutoRender’ is set to false

1 Like

Canvas Methods:


Canvas:Destroy ()

  • This will physically destroy the canvas that has been created by the CanvasDraw.new() function.
Parameters and Returns

Parameters:

This function has no parameters

Returns:

Return Type: Void
Summary: Nothing will be returned (nil)


Canvas:Render ()

  • This function allows you to manually update the canvas. Normally, for every heartbeat, CanvasDraw will automatically update the canvas so pixels will instantly appear on the canvas. This function may be helpful as you can control when to update the canvas. To use this function and to stop automatic updates, set the AutoRender property to false on the canvas object.
Example
-- Define our rectangle
local PointA = Vector2.new(25, 25)
local PointB = Vector2.new(75, 75)
local Colour = Color3.new(0, 0, 1)

-- Create the canvas and disable auto updating for every frame
local Canvas = CanvasDraw.new(Frame)
Canvas.AutoUpdate = false

-- Image will not show straight away, so we need to manually update the picture after drawing
Canvas:DrawRectangle(PointA, PointB, Color3.new(0, 0, 1))
Canvas:Render()
Parameters and Returns

Parameters:

This function has no parameters

Returns:

Return Type: Void
Summary: Nothing will be returned (nil)


Canvas:CreateImageDataFromCanvas (PointA: Vector2?, PointB: Vector2?) : ImageData

  • This method will return an ImageData table/class from the canvas pixels from PointA to PointB (if the PointA and PointB arguments are empty, then it will grab all pixels on the canvas instead)
  • This method was intended for plugin use. (e.g. An image editor / image file importer)
Example
-- Define the region to capture
local PointA = Vector.new(25, 25)
local PointB = Vector.new(75, 75)

local ImageData = Canvas:CreateImageDataFromCanvas(PointA, PointB)
Parameters and Returns

Parameters:

PointA Vector2

  • Default: Vector2.new(1, 1)
  • Description: The starting point on the canvas that you grab the pixels from for the ImageData.

PointB Vector2

  • Default: Canvas.Resolution
  • Description: The ending point on the canvas that you grab the pixels from for the ImageData.

Returns:

Return Type: ImageData (Table/class)
Summary: Returns the ImageData of your captured area on your canvas.


1 Like

Canvas Fetch Methods:


Canvas:GetPixel (Point: Vector2) : Color3

  • Returns the chosen pixel’s colour given from the provided point on the canvas.
Example
-- Get the colour on our canvas at point 50, 50
local Colour = Canvas:GetPixel(Vector2.new(50, 50))
print(Colour)
Parameters and Returns

Parameters:

Point Vector2

  • Default:
  • Description: The desired point that you wish to use to get the pixel colour from.

Returns:

Return Type: Color3
Summary: The pixel’s colour that has been chosen in the canvas from a given point.


Canvas:GetPixelXY (X: number, Y: number) : Color3

  • Returns the chosen pixel’s colours given from the provided X and Y coordinates on the canvas. This function behaves almost exactly the same as GetPixel(), but main difference being is that this is a slightly more performant version that uses an X and Y parameter for the point.
Example
-- Get the colour on our canvas at point 50, 50
local Colour = Canvas:GetPixelXY(50, 50)
print(Colour)
Parameters and Returns

Parameters:

X number

  • Default:
  • Description: The desired X coordinate that you wish to use to get the pixel colour from on the canvas.

Y number

  • Default:
  • Description: The desired Y coordinate that you wish to use to get the pixel colour from on the canvas.

Returns:

Return Type: Color3
Summary: The pixel’s colour that has been chosen in the canvas from a given point.


Canvas:GetRGB (X: number, Y: number) : number, number, number

  • Returns the chosen pixel’s colour given from the provided X and Y coordinates on the canvas. This function is much faster than GetPixel or GetPixelXY.
Example
-- Get the colour on our canvas at point 50, 50
local R, G, B = Canvas:GetRGB(50, 50)
print(R, G, B)
Parameters and Returns

Parameters:

X number

  • Default:
  • Description: The desired X coordinate that you wish to use to get the pixel colour from on the canvas.

Y number

  • Default:
  • Description: The desired Y coordinate that you wish to use to get the pixel colour from on the canvas.

Returns:

Return Type: tuple
Summary: The pixel’s R, G and B value that has been chosen in the canvas from the given (X, Y) coordinate.


Canvas:GetAlpha (X: number, Y: number) : number,

  • Returns the chosen pixel’s alpha value given from the provided X and Y coordinates on the canvas.
Example
-- Get the pixel transparency from our canvas at point 50, 50
local Alpha = Canvas:GetAlpha(50, 50)
print(Alpah)
Parameters and Returns

Parameters:

X number

  • Default:
  • Description: The desired X coordinate that you wish to use to get the pixel colour from on the canvas.

Y number

  • Default:
  • Description: The desired Y coordinate that you wish to use to get the pixel colour from on the canvas.

Returns:

Return Type: number
Summary: The alpha (transparency) value that has been chosen in the canvas from the given (X, Y) coordinate.


Canvas:GetPixels (PointA: Vector2?, PointB: Vector2?) : {…}

  • This will get all of the pixel colours in the canvas between two points in a square shape from corner to corner. If all the parameters are empty, every single pixel colour in the canvas will be returned instead.
Example
-- Define our region
local PointA = Vector2.new(25, 25)
local PointB = Vector2.new(50, 50)

local TableOfColours = Canvas:GetPixels(PointA, PointB)
Parameters and Returns

Parameters:

PointA Vector2

  • Default: Vector2.new(1, 1)
  • Description: The starting point in the canvas for the pixels to grab.

PointB Vector2

  • Default: Canvas.Resolution
  • Description: The ending point in the canvas for the pixels to grab.

Returns:

Return Type: Table
**Summary:**A table of all the pixel colours (Color3s) that are between PointA and PointB.


Canvas:GetMousePoint () : Vector2? CLIENT/PLUGIN ONLY

  • This will function will either return a Vector2 point on the canvas from the client’s mouse position, or nil if the mouse isn’t within the canvas.
  • This function will work for both Guis and SurfaceGuis.
  • NOTE: This function only works on the client or locally. If you are using this function from the server, it will throw a warning in the console/output.
Example
-- Get the mouses point on the canvas and draws a pixel.
local Point = Canvas:GetMousePoint()

if Point then
     Canvas:DrawPixel(Point, Color3.new(1, 0, 0))
    print("Red pixel drawn!")
else
    print("The mouse is not the within the canvas!")
end
Parameters and Returns

Parameters:

This function has no parameters

Returns:

Return Type: Vector2 OR nil
Summary: The point on the canvas at which the mouse is currently at. If the mouse is not on the canvas, nothing will be returned (nil/false)


Canvas:MouseIsOnTop () : boolean? CLIENT/PLUGIN ONLY

  • Returns true if the user’s mouse is only on top of the canvas gui element.
  • Will return false if the user’s mouse in on top of a different gui element that’s
    layered above the canvas, or if the mouse location is outside the canvas entirely.
  • Useful for mouse inputs with canvas.
Example
-- Get the mouses point on the canvas and draws a pixel.
local Point = Canvas:GetMousePoint()

-- Only draw if our mouse is on top of the canvas and no other overlapping frames
if Point and Canvas:MouseIsOnTop() then
     Canvas:DrawPixel(Point, Color3.new(1, 0, 0))
    print("Red pixel drawn!")
else
    print("The mouse is not on the canvas!")
end
Parameters and Returns

Parameters:

This function has no parameters

Returns:

Return Type: boolean
Summary: Either false or true if the mouse is on top of the canvas


1 Like

Canvas Drawing Methods:


Canvas:Fill (Colour: Color3)

  • This will go through every single pixel in the canvas and change the colours to your desired colour.
Parameters and Returns

Parameters:

Colour Color3

  • Default:
  • Description: The colour that you wish to apply.

Returns:

Return Type: Void
Summary: Nothing will be returned (nil)


Canvas:Clear ()

  • Will go through every single pixel within the canvas and replace them with the canvas background colour.
Parameters and Returns

Parameters:

This function has no parameters

Returns:

Return Type: Void
Summary: Nothing will be returned (nil)


Canvas:ClearPixels (Points: Table)

  • Works similar to ClearCanvas(), except this function will only clear chosen pixels at the points provided instead of the whole canvas.
    This will go through all the chosen pixels and change their colours to the canvas background colour (Canvas.CanvasColour).
Example
local PointsToClear = {
    Vector2.new(1, 1),
    Vector2.new(70, 70),
    Vector2.new(25, 90),
    Vector2.new(1, 50),
}

Canvas:ClearPixels(PointsToClear)
Parameters and Returns

Parameters:

Points Table

  • Default:
  • Description: The table containing all the pixel points that you wish to clear.

Returns:

Return Type: Void
Summary: Nothing will be returned (nil)


Canvas:FloodFill (Point: Vector2, Colour: Color3) : {…}

  • This function will fill an area of pixels on the canvas of the specific colour that your point is on. This works pretty well the same way how MS Paint’s paint bucket tool does.

  • NOTE: This method is not fast and may cause lag spikes when using on very large high-res areas. Do not use for real-time engines!

Example
-- Divide the canvas into two parts with a line (Assuming your canvas is at a resolution of 100 x 100)
local LinePointA = Vector2.new(1, 40)
local LinePointA = Vector2.new(100, 60)

Canvas:DrawLine(LinePointA, LinePointB, Color3.new(0, 0, 0))

-- Fill the bottom half of the canvas red
Canvas:FloodFill(Vector2.new(50, 75), Color3.new(1, 0, 0))
Parameters and Returns

Parameters:

Point Vector2

  • Default:
  • Description: The point to start filling from.

Colour Color3

  • Default:
  • Description: The colour that you wish to use to fill the area of pixels with.

Returns:

Return Type: Table
Summary: A table of all the points that were coloured.


Canvas:FloodFillXY (X: number, Y: number, Colour: Color3)

  • This method will fill an area of pixels on the canvas of the specific colour that your point is on. This works pretty well the same way how MS Paint’s paint bucket tool does.

  • NOTE: This method is not fast and may cause lag spikes when using on very large high-res areas. Do not use for real-time engines!

Example
-- Divide the canvas into two parts with a line (Assuming your canvas is at a resolution of 100 x 100)
local LinePointA = Vector2.new(1, 40)
local LinePointA = Vector2.new(100, 60)

Canvas:DrawLineXY(1, 40, 100, 60, Color3.new(0, 0, 0))

-- Fill the bottom half of the canvas red
Canvas:FloodFillXY(50, 75, Color3.new(1, 0, 0))
Parameters and Returns

Parameters:

X number

  • Default:
  • Description: The X coordinate to start filling from.

Y number

  • Default:
  • Description: The Y coordinate to start filling from.

Colour Color3

  • Default:
  • Description: The colour that you wish to use to fill the area of pixels with.

Returns:

Return Type: Void
Summary: Nothing will be returned (nil)


Canvas:DrawPixel (Point: Vector2, Colour: Color3) : Vector2

  • This will change the pixel at the chosen point and change its colour.

  • NOTE: Use the SetPixel method if you plan on doing proper pixel-based real-time high resolution projects, as it is faster than this method as it avoids clip checks, rounding, and vector constructing.

Example
-- Create a canvas and place a red pixel in the middle of it
local Canvas = CanvasDraw.new(Frame, Vector2.new(50, 50))
Canvas:DrawPixel(Vector2.new(25, 25), Color3.new(1, 0, 0))
Parameters and Returns

Parameters:

Point Vector2

  • Default:
  • Description: The point that determines what pixel to colour.

Colour Color3

  • Default:
  • Description: The colour that you wish to apply.

Returns:

Return Type: Vector2
Summary: The point that you have selected.


Canvas:SetPixel (X: number, Y: number, Colour: Color3)

  • This behaves similarly to DrawPixel(), all though main difference being is that this a much more performant method for colouring a pixel to the screen as it avoids constructing a vector and avoids checks to the canvas, unlike DrawPixel. If you want an even faster method, use SetRGB instead.
Example
-- Create a canvas and place a red pixel at point 25, 40
local Canvas = CanvasDraw.new(Frame, Vector2.new(50, 50))
Canvas:SetPixel(25, 40, Color3.new(1, 0, 0))
Parameters and Returns

Parameters:

Point Vector2

  • Default:
  • Description: The point that determines what pixel to colour.

Colour Color3

  • Default:
  • Description: The colour that you wish to apply.

Returns:

Return Type: Void
Summary: Nothing will be returned (nil)


Canvas:SetRGB (X: number, Y: number, R: number, G: number, B: number)

  • This behaves similarly to SetPixel(), all though main difference being is that this is the raw and fastest method to drawing a pixel to the canvas.

  • This method is highly recommended if you plan on doing proper real-time per-pixel work with high resolutions.

Example
-- Create a canvas and place a red pixel at point 25, 40
local Canvas = CanvasDraw.new(Frame, Vector2.new(50, 50))
Canvas:SetRGB(25, 40, 1, 0, 0)
Parameters and Returns

Parameters:

X number

  • Default:
  • Description: The X coordinate that determines what pixel to colour.

Y number

  • Default:
  • Description: The Y coordinate that determines what pixel to colour.

R number

  • Default:
  • Description: The R channel of colour that you wish to apply.

G number

  • Default:
  • Description: The G channel of colour that you wish to apply.

B number

  • Default:
  • Description: The B channel of colour that you wish to apply.

Returns:

Return Type: Void
Summary: Nothing will be returned (nil)


Canvas:SetAlpha (X: number, Y: number, Alpha: number)

  • Sets the alpha channel/value of a pixel. (Transparency)
Example
-- Create a canvas and place a red pixel at point 25, 40
local Canvas = CanvasDraw.new(Frame, Vector2.new(50, 50))
Canvas:SetRGB(25, 40, 1, 0, 0)
Parameters and Returns

Parameters:

X number

  • Default:
  • Description: The X coordinate that determines what pixel to colour.

Y number

  • Default:
  • Description: The Y coordinate that determines what pixel to colour.

Alpha number

  • Default:
  • Description: The alpha/transparency value that you wish to apply.

Returns:

Return Type: Void
Summary: Nothing will be returned (nil)


Canvas:DrawCircle (Point: Vector2, Radius: number, Colour: Color3, Fill: boolean?) : {…}

  • This will create a circle at the desired point with a set radius and colour. This shape originates from the centre of your point when drawn.
Example
local CirclePoint = Vector.new(50, 50) -- The circle's origin is the centre, so the circle should be placed in the middle of the canvas
local CircleRadius = 10 -- The radius of the circle in pixels
local CircleColour = Color3.new(1, 0, 0) -- Give the circle a nice red

local Canvas = CanvasDraw.new(Frame)

Canvas:DrawCircle(
    CirclePoint,
    CircleRadius,
    CircleColour,
    false -- Don't fill the circle with colour. This should create a circle outline instead.
)
Parameters and Returns

Parameters:

Point Vector2

  • Default:
  • Description: The point that you wish to place your circle at.

Radius number

  • Default:
  • Description: The radius of the circle. This determines how large your circle will be. Be careful not to draw the circle too big. Otherwise, if the circle is clipping through the sides of the canvas, the circle may break and be drawn correctly.

Colour Color3

  • Default:
  • Description: The colour that you wish to apply to your shape

Fill boolean

  • Default: true
  • Description: Determines wether every pixel within the shape get’s filled with colour. When set to false or left empty, the shape created will be an outline only.

Returns:

**Return Type: Table
Summary: Returns an array of all the pixel points (Vector2s) that have been drawn on for the circle.


Canvas:DrawCircleXY (X: number, Y: number, Radius: number, Colour: Color3, Fill: boolean?)

  • Behaves pretty well exactly the same as DrawCircle(), but uses an X and a Y parameter as the circle point. This function is also much more performant than DrawCircle(), but avoids checks to the coordinates on the canvas. So the circle will not be able to draw or even partially go out of bounds in the canvas.

  • In most cases, DrawCircle() is much more recommended and should be used instead.

Example
local CircleRadius = 10 -- The radius of the circle in pixels
local CircleColour = Color3.new(1, 0, 0) -- Give the circle a nice red colour

local Canvas = CanvasDraw.new(Frame)

Canvas:DrawCircle(
    50, 50, -- The circle's origin is the centre, so the circle should be placed in the middle of the canvas
    CircleRadius,
    CircleColour,
    false -- Don't fill the circle with colour. This should create a circle outline instead.
)
Parameters and Returns

Parameters:

X number

  • Default:
  • Description: The X coordinate that you wish to place your circle at.

Y number

  • Default:
  • Description: The Y coordinate that you wish to place your circle at.

Radius number

  • Default:
  • Description: The radius of the circle. This determines how large your circle will be. Be careful not to draw the circle too big. Otherwise, if the circle is clipping through the sides of the canvas, the circle may break and be drawn correctly.

Colour Color3

  • Default:
  • Description: The colour that you wish to apply to your shape

Fill boolean

  • Default: true
  • Description: Determines wether every pixel within the shape get’s filled with colour. When set to false or left empty, the shape created will be an outline only.

Returns:

Return Type: Void
Summary: Nothing will be returned (nil)


Canvas:DrawRectangle (PointA: Vector2, PointB: Vector2, Colour: Color3, Fill: boolean?) : {…}

  • This will draw a simple rectangle shape from PointA (top left) to PointB (bottom right).
Example
-- Define the rectangle
local PointA = Vector.new(25, 25)
local PointB = Vector.new(75, 35)
local Colour = Color3.new(1, 0, 0) -- Give the rectangle a nice red colour

local Canvas = CanvasDraw.new(Frame)

Canvas:DrawRectangle(
    PointA,
    PointB,
    Colour,
    false -- Don't fill the rectangle with colour. This should create an outline of the rectangle instead.
)
Parameters and Returns

Parameters:

PointA Vector2

  • Default:
  • Description: The starting point on the canvas that you draw your rectangle from.

PointB Vector2

  • Default:
  • Description: The ending point on the canvas that you draw your rectangle to.

Colour Color3

  • Default:
  • Description: The colour that you wish to apply to your shape.

Fill boolean

  • Default: true
  • Description: Determines wether every pixel within the shape get’s filled with colour. When set to false or left empty, the shape created will be an outline only.

Returns:

**Return Type: Table
Summary: Returns an array of all the points (Vector2) that have been drawn on to create the rectangle.


Canvas:DrawRectangleXY (X1: number, Y1: number, X2: number, Y2: number, Colour: Color3, Fill: boolean?)

  • This will draw a simple rectangle from X1, Y1 (top left) to X2, Y2 (bottom right).

  • This almost behaves exactly like DrawRectange(), but with coordinates in the parameters instead of Vector2 points with no checks.
    (This means your rectangle coordinates/points have to be whole numbers and within the canvas)

  • This function also runs much faster than the normal DrawRectange()

Example
local Colour = Color3.new(1, 0, 0) -- Give the rectangle a nice red colour

local Canvas = CanvasDraw.new(Frame)

Canvas:DrawRectangleXY(
    25, 25,
    75, 50,
    Colour,
    false -- Don't fill the rectangle with colour. This should create an outline of the rectangle instead.
)
Parameters and Returns

Parameters:

X1 number

  • Default:
  • Description: The starting point for the X coordinate on the canvas for your rectangle.

Y1 number

  • Default:
  • Description: The starting point for the Y coordinate on the canvas for your rectangle.

X2 number

  • Default:
  • Description: The ending point for the X coordinate on the canvas for your rectangle.

Y2 number

  • Default:
  • Description: The ending point for the Y coordinate on the canvas for your rectangle.

Colour Color3

  • Default:
  • Description: The colour that you wish to apply to your shape.

Fill boolean

  • Default: true
  • Description: Determines wether every pixel within the shape get’s filled with colour. When set to false or left empty, the shape created will be an outline only.

Returns:

**Return Type: Void
Summary: Nothing will be returned (nil)


Canvas:DrawTriangle (PointA: Vector2, PointB: Vector2, PointC: Vector2, Colour: Color3, Fill: boolean?) : {…}

  • This will draw a triangle from three points on the canvas (PointA, PointB, and PointC).
Example
-- Define the triangle
local PointA = Vector.new(25, 25)
local PointB = Vector.new(75, 25)
local PointC = Vector.new(50, 75)
local Colour = Color3.new(0, 0, 1) -- Give the triangle a nice blue colour

local Canvas = CanvasDraw.new(Frame)

Canvas:DrawTriangle(
    PointA,
    PointB,
    PointC,
    Colour,
    false -- Don't fill the triangle with colour. This should create an outline of the triangle instead.
)
Parameters and Returns

Parameters:

PointA Vector2

  • Default:
  • Description: The first point for the corner of the triangle.

PointB Vector2

  • Default:
  • Description: The second point for the corner of the triangle.

PointC Vector2

  • Default:
  • Description: The third point for the corner of the triangle.

Colour Color3

  • Default:
  • Description: The colour that you wish to apply to your shape.

Fill boolean

  • Default: true
  • Description: Determines wether every pixel within the shape get’s filled with colour. When set to false or left empty, the shape created will be an outline only.

Returns:

Return Type: Table
Summary: Returns an array of all the points (Vector2) that have been drawn on to create the triangle.


Canvas:DrawTriangleXY (X1: number, Y1: number, X2: number, Y2: number, X3: number, Y3: number, Colour: Color3, Fill: boolean?)

  • This will draw a triangle from three points on the canvas ([X1, Y1], [X2, Y2] and [X3, Y3]).

  • This almost behaves exactly like DrawTriangle(), but with coordinates in the parameters instead of Vector2 points with no checks or rounding of the coordinates.
    (This means your rectangle coordinates/points have to be whole numbers and within the canvas)

  • This function also runs much faster than the normal DrawTriangle()

Example
-- Define the triangle
local X1, Y1 = 25, 25
local X2, Y2 = 75, 25
local X3, Y3 = 50, 75
local Colour = Color3.new(0, 0, 1) -- Give the triangle a nice blue colour

local Canvas = CanvasDraw.new(Frame)

Canvas:DrawTriangle(
    X1, Y1,
    X2, Y2,
    X3, Y3,
    Colour,
    false -- Don't fill the triangle with colour. This should create an outline of the triangle instead.
)
Parameters and Returns

Parameters:

X1 number

  • Default:
  • Description: The first X coordinate for the corner of the triangle.

Y1 number

  • Default:
  • Description: The first Y coordinate for the corner of the triangle.

X2 number

  • Default:
  • Description: The second X coordinate for the corner of the triangle.

Y2 number

  • Default:
  • Description: The second Y coordinate for the corner of the triangle.

X3 number

  • Default:
  • Description: The third X coordinate for the corner of the triangle.

Y3 number

  • Default:
  • Description: The third Y coordinate for the corner of the triangle.

Colour Color3

  • Default:
  • Description: The colour that you wish to apply to your shape.

Fill boolean

  • Default: true
  • Description: Determines wether every pixel within the shape get’s filled with colour. When set to false or left empty, the shape created will be an outline only.

Returns:

Return Type: Void
Summary: Nothing will be returned (nil)


Canvas:DrawLine (PointA: Vector2, PointB: Vector2, Colour: Color3, Thickness: number?) : {…}

  • This will draw a simple pixel line from PointA to PointB with an optional thickness
Example
-- Define the line
local PointA = Vector.new(25, 25)
local PointB = Vector.new(75, 40)
local Colour = Color3.new(0, 0, 1)

local Canvas = CanvasDraw.new(Frame)

Canvas:DrawLine(PointA, PointB, Colour)
Parameters and Returns

Parameters:

PointA Vector2

  • Default:
  • Description: The starting point for the line.

PointB Vector2

  • Default:
  • Description: The ending point for the line.

Colour Color3

  • Default:
  • Description: The colour that you wish to apply to the line.

Thickness number

  • Default: 1
  • Description: The line’s thickness radius (in pixels)

Returns:

Return Type: Table
Summary: Returns an array of all the points (Vector2s) that have been drawn on to create the line.


Canvas:DrawLineXY (X1: number, Y1: number, X2: number, Y2: number, Colour: Color3, Thickness: number?)

  • This will draw a simple pixel line from X1, Y1 to X2, Y2 with an optional thickness parameter

  • This function behaves very much like DrawLine(), but uses X and Y coordinates as points in the parameters and will avoid checks, rounding and vector constructing. So ensure your coordinates are whole numbers and are within the canvas

Example
-- Define the line
local X1, Y1 = 25, 25
local X2, Y2 = 75, 40
local Colour = Color3.new(0, 0, 1)

local Canvas = CanvasDraw.new(Frame)

Canvas:DrawLineXY(X1, Y1, X2, Y2, Colour)
Parameters and Returns

Parameters:

X1 number

  • Default:
  • Description: The starting X coordinate for the line.

Y1 number

  • Default:
  • Description: The starting Y coordinate for the line.

X2 number

  • Default:
  • Description: The ending X coordinate for the line.

Y2 number

  • Default:
  • Description: The ending Y coordinate for the line.

Colour Color3

  • Default:
  • Description: The colour that you wish to apply to the line.

Thickness number

  • Default: 1
  • Description: The line’s thickness radius (in pixels)

Returns:

Return Type: Void
Summary: Nothing will be returned (nil)


Canvas:DrawImage (ImageData, Point: Vector2?, Scale: Vector2?, TransparencyEnabled: boolean?)

  • This function will load the image from ImageData, which is assumed to be created from a SaveObject with the GetImageData() method, and then draw every single pixel from the data onto your canvas originating from the given point on your canvas. If this point parameter is empty, then the default point will be at the top left of your canvas (Vector2.new(1, 1))
Example
local Saves = workspace.Saves -- Our folder containing our save objects
local SaveToLoad = Saves.MyDrawing -- Our save object to load

local ImageData = CanvasDraw.GetImageData(SaveToLoad) -- Get the image data from the save object

Canvas:DrawImage(
    ImageData, -- Our data to draw from
    Vector2.new(25, 25), -- Place the image at point 25, 25
    Vector2.new(1, 1) -- Draw the image at normal scale (100%, 100%)
    true -- Enable alpha transparency blending
)
Parameters and Returns

Parameters:

ImageData Table

  • Default:
  • Description: The ImageData that you wish to load onto your canvas.

Point Vector2

  • Default: Vector2.new(1, 1)
  • Description: The point on your canvas that you wish to draw the image from. (NOTE: The image’s origin is top left relative to it self)

Scale Vector2

  • Default: Vector2.new(1, 1)
  • Description: The image’s scaling factor. This variable is percentage based, meaning that (1, 1) is 100%, 100%, which means the default image resolution will be used, and (0.5, 0.5) is half of that, etc

TransparencyEnabled boolean

  • Default: true
  • Description: Determines whether alpha transparency will be applied to the drawn image in the canvas. When set to false, all transparent areas will be replaced with black. Setting this argument to false will also slightly improve performance. Especially for larger resolution images.

Returns:

Return Type: void
Summary: Nothing will be returned (nil)


Canvas:DrawImageXY (ImageData, X: number? Y: number?, ScaleX: number? ScaleY: number?, TransparencyEnabled: boolean?)

  • This function will load the image from the ImageData and draw every single pixel from the data onto your canvas originating from the given point on your canvas. If this point parameter is empty, then the default point will be at the top left of your canvas (Vector2.new(1, 1))
Example
local Saves = workspace.Saves -- Our folder containing our save objects
local SaveToLoad = Saves.MyDrawing -- Our save object to load

local ImageData = CanvasDraw.GetImageData(SaveToLoad) -- Get the image data from the save object

Canvas:DrawImage(
    ImageData, -- Our data to draw from
    25, 25, -- Place the image at point 25, 25
    1, 1 -- Image scale percentage (Normal scaling at 1, 1)
    true -- Enable alpha transparency blending
)
Parameters and Returns

Parameters:

ImageData Table

  • Default:
  • Description: The ImageData that you wish to load onto your canvas.

X number

  • Default: 1
  • Description: The X coordinate your canvas that you wish to draw the image from (NOTE: Image origin is top left)

Y number

  • Default: 1
  • Description: The Y coordinate your canvas that you wish to draw the image from (NOTE: Image origin is top left)

ScaleX number

  • Default: 1
  • Description: The image’s X scale. This variable is percentage based, meaning that 1 is 100%, and 0.5, is 50%, and so on.

ScaleX number

  • Default: 1
  • Description: The image’s Y scale. This variable is percentage based, meaning that 1 is 100%, and 0.5, is 50%, and so on.

TransparencyEnabled boolean

  • Default: true
  • Description: Determines whether alpha transparency will be applied to the drawn image in the canvas. When set to false, all transparent areas will be replaced with black. Setting this argument to false will also slightly improve performance. Especially for larger resolution images.

Returns:

Return Type: Void
Summary: Nothing will be returned (nil)


Canvas:DrawTexturedTriangle (PointA: Vector2, PointB: Vector2, PointC: Vector2, UV1: Vector2, UV2: Vector2, UV3: Vector2, ImageData, Brightness: number?)

  • This will draw a textured triangle from three points on the canvas ([X1, Y1], [X2, Y2] and [X3, Y3]) with a given set of UV coordinates for the image

  • The UV coordinates should be between 0 and 1 for each axis ([0, 0] being top left, and [1, 1] being bottom right

  • This can be used for 3D rendering or can be used for 2D textured polygons or custom 2D image transformations

Example
-- Define the triangle
local PointA = Vector2.new(25, 25)
local PointB = Vector2.new(75, 25)
local PointC = Vector2.new(50, 75)
local Texture = CanvasDraw.GetImageData(Gui.Textures["Wall-01.png"]) -- Get the ImageData from our SaveObject instance

Canvas:DrawTexturedTriangle(
    PointA,
    PointB,
    PointC,
    -- Set our UV coordinates to just be 3 of the image corners (top left, bottom left, bottom right)
    Vector2.new(0, 0),
    Vector2.new(0, 1),
    Vector2.new(1, 1),
    Texture,
    0.5 -- Draw at half the brightness
)
Parameters and Returns

Parameters:

PointA Vector2

  • Default:
  • Description: The first corner coordinate for the triangle.

PointB Vector2

  • Default:
  • Description: The second corner coordinate for the triangle.

PointC Vector2

  • Default:
  • Description: The third corner coordinate for the triangle.

UV1 number

  • Default:
  • Description: The first UV coordinate from the image source.

UV2 number

  • Default:
  • Description: The second UV coordinate from the image source.

UV3 number

  • Default:
  • Description: The third UV coordinate from the image source.

ImageData ImageData

  • Default:
  • Description: The image that you wish to texture the triangle.

Brightness number?

  • Default: 1
  • Description: Determines how bright or dark the texture should be (0 is fully dark, 1 is full bright / normal)

Returns:

Return Type: Void
Summary: Nothing will be returned (nil)


Canvas:DrawTexturedTriangleXY (X1: number, Y1: number, X2: number, Y2: number, X3: number, Y3: number, U1: number, V1: number, U2: number, V2: number, U3: number, V3: number, ImageData, Brightness: number?)

  • This will draw a textured triangle from three points on the canvas ([X1, Y1], [X2, Y2] and [X3, Y3]) with a given set of UV coordinates for the image

  • The UV coordinates should be between 0 and 1 for each axis ([0, 0] being top left, and [1, 1] being bottom right

  • This can be used for 3D rendering or can be used for 2D textured polygons or custom 2D image transformations

  • This drawing function automatically clips to the canvas

Example
-- Define the triangle
local X1, Y1 = 25, 25
local X2, Y2 = 75, 25
local X3, Y3 = 50, 75
local Texture = CanvasDraw.GetImageData(Gui.Textures["Wall-01.png"]) -- Get the ImageData from our SaveObject instance

Canvas:DrawTexturedTriangleXY(
    X1, Y1,
    X2, Y2,
    X3, Y3,
    -- Set our UV coordinates to just be 3 of the image corners (top left, bottom left, bottom right)
    0, 0,
    0, 1,
    1, 1,
    Texture,
    0.5 -- Draw at half the brightness
)
Parameters and Returns

Parameters:

X1 number

  • Default:
  • Description: The first X coordinate for the corner of the triangle.

Y1 number

  • Default:
  • Description: The first Y coordinate for the corner of the triangle.

X2 number

  • Default:
  • Description: The second X coordinate for the corner of the triangle.

Y2 number

  • Default:
  • Description: The second Y coordinate for the corner of the triangle.

X3 number

  • Default:
  • Description: The third X coordinate for the corner of the triangle.

Y3 number

  • Default:
  • Description: The third Y coordinate for the corner of the triangle.

U1 number

  • Default:
  • Description: The first U coordinate from the image source.

V1 number

  • Default:
  • Description: The first V coordinate from the image source.

U2 number

  • Default:
  • Description: The second U coordinate from the image source.

V2 number

  • Default:
  • Description: The second V coordinate from the image source.

U3 number

  • Default:
  • Description: The third U coordinate from the image source.

V3 number

  • Default:
  • Description: The third V coordinate from the image source.

ImageData ImageData

  • Default:
  • Description: The image that you wish to texture the triangle.

Brightness number?

  • Default: 1
  • Description: Determines how bright or dark the texture should be (0 is fully dark, 1 is full bright / normal)

Returns:

Return Type: Void
Summary: Nothing will be returned (nil)


Canvas:DrawDistortedImage (PointA: Vector2, PointB: Vector2, PointC: Vector2, PointD: Vector2, ImageData, Brightness: number?)

  • This method will draw a dynamic four point image. This method internally uses two textured triangles to draw this dynamic shape.

  • This can be used for basic 3D rendering and also presents an easy and fast way to create skewable, scalable and rotatable images as well

  • NOTE: This method uses affine transformations to map the image to the 2D plane, which means if you try to use this for perspective, you may get some unwanted distortion.

Example
local Canvas = CanvasDraw.new(Frame, Vector2.new(128, 128))

-- Define the quad
local CornerA = Vector2.new(25, 25)
local CornerB = Vector2.new(30, 75)
local CornerC = Vector2.new(75, 100)
local CornerD = Vector2.new(110, 40)

local Texture = CanvasDraw.GetImageData(Gui.Textures["Wall-01.png"]) -- Get the ImageData from our SaveObject instance

Canvas:DrawDistortedImage(
    CornerA,
    CornerB,
    CornerC,
    CornerD,
    Texture
)
Parameters and Returns

Parameters:

PointA Vector2

  • Default:
  • Description: The first corner coordinate for the image.

PointB Vector2

  • Default:
  • Description: The second corner coordinate for the image.

PointC Vector2

  • Default:
  • Description: The third corner coordinate for the image.

PointD Vector2

  • Default:
  • Description: The third corner coordinate for the image.

ImageData ImageData

  • Default:
  • Description: The image that you wish to texture the triangle.

Brightness number?

  • Default: 1
  • Description: Determines how bright or dark the texture should be (0 is fully dark, 1 is full bright / normal)

Returns:

Return Type: Void
Summary: Nothing will be returned (nil)


Canvas:DrawDistortedImageXY (X1: number, Y1: number, X2: number, Y2: number, X3: number, Y3: number, X4: number, Y4: number, ImageData, Brightness: number?)

  • This method will draw a dynamic four point image. This method internally uses two textured triangles to draw this dynamic shape.

  • This can be used for basic 3D rendering and also presents an easy and fast way to create skewable, scalable and rotatable images as well

  • NOTE: This method uses affine transformations to map the image to the 2D plane, which means if you try to use this for perspective, you may get some unwanted distortion.

Example
local Canvas = CanvasDraw.new(Frame, Vector2.new(128, 128))

local Texture = CanvasDraw.GetImageData(Gui.Textures["Wall-01.png"]) -- Get the ImageData from our SaveObject instance

Canvas:DrawDistortedImageXY(
    25, 25,
    30, 75,
    75, 100,
    110, 40,
    Texture
)
Parameters and Returns

Parameters:

X1 number

  • Default:
  • Description: The first corner X coordinate for the image.

Y1 number

  • Default:
  • Description: The first corner Y coordinate for the image.

X2 number

  • Default:
  • Description: The second corner X coordinate for the image.

Y2 number

  • Default:
  • Description: The second corner Y coordinate for the image.

X1 number

  • Default:
  • Description: The first corner X coordinate for the image.

Y1 number

  • Default:
  • Description: The first corner Y coordinate for the image.

ImageData ImageData

  • Default:
  • Description: The image that you wish to texture the triangle.

Brightness number?

  • Default: 1
  • Description: Determines how bright or dark the texture should be (0 is fully dark, 1 is full bright / normal)

Returns:

Return Type: Void
Summary: Nothing will be returned (nil)


Canvas:DrawRotatedImage (ImageData, Angle: number, Point: Vector2?, PivotPoint: Vector2?, Scale: Vector2?)

  • Draws a rotated image to the canvas with a given angle with a pivoting point.
    a pivot of (0, 0) will draw and rotate the image from the top left, and a pivot point of (1, 1) will do it from the bottom right corner.
Example
local Placement = Vector2.new(256, 256)
local Pivot = Vector2.new(0.5, 0.5)

Canvas.OnRendered:Connect(function(DeltaTime)
	task.wait()

	Rot += 0.5 * DeltaTime -- Rotate the image at a consistent speed
	local Size = Vector2.new(1, 1) * (math.sin(Rot * 3) / 2 + 1)

	Canvas:Clear()
	Canvas:DrawRotatedImage(Image, Rot, Placement, Pivot, Size)
end)
Parameters and Returns

Parameters:

ImageData ImageData

  • Default:
  • Description: The image that you wish to use.

Angle number

  • Default:
  • Description: The angle at which you want to rotate the image by (in radians)

Point Vector2

  • Default: Vector2.new(1, 1)
  • Description: The canvas point for the image.

PivotPoint Vector2

  • Default: Vector2.new(0, 0)
  • Description: The coordinate for the image’s pivot/anchor point. (Axis lengths ranges from 0 to 1)

Scale Vector2

  • Default: Vector2.new(1, 1)
  • Description: The scale for the image. This vector is a percentage (e.g, setting to Vectoe2.new(1.5, 1) will stretch the image horizontally by 1.5x)

Returns:

Return Type: Void
Summary: Nothing will be returned (nil)


Canvas:DrawRotatedImageXY (ImageData, Angle: number, X: number?, Y: number?, PivotX: number?, PivotY: number?, ScaleX: number?, ScaleY: number?)

  • Draws a rotated image to the canvas with a given angle with a pivoting point.
    a pivot of (0, 0) will draw and rotate the image from the top left, and a pivot point of (1, 1) will do it from the bottom right corner.
Example
Canvas.OnRendered:Connect(function(DeltaTime)
	task.wait()

	Rot += 0.5 * DeltaTime -- Rotate the image at a consistent speed
	local Size = math.sin(Rot * 3) / 2 + 1

	Canvas:Clear()
	Canvas:DrawRotatedImageXY(Image, Rot, 256, 256, 0.5, 0.5, Size, Size)
end)
Parameters and Returns

Parameters:

ImageData ImageData

  • Default:
  • Description: The image that you wish to use.

Angle number

  • Default:
  • Description: The angle at which you want to rotate the image by (in radians)

X number

  • Default: 1
  • Description: The X coordinate for the image.

Y number

  • Default: 1
  • Description: The Y coordinate for the image.

PivotX number

  • Default: 0
  • Description: The X coordinate for the image’s pivot/anchor point. (Ranges from 0 to 1)

PivotY number

  • Default: 0
  • Description: The Y coordinate for the image’s pivot/anchor point. (Ranges from 0 to 1)

ScaleX number

  • Default: 1
  • Description: The scale X for the image. This unit is a percentage (e.g, setting to 1.4 will stretch the image by 1.4x)

ScaleY number

  • Default: 1
  • Description: The scale Y for the image. This unit is a percentage (e.g, setting to 1.4 will stretch the image by 1.4x)

Returns:

Return Type: Void
Summary: Nothing will be returned (nil)


Canvas:DrawImageRect (ImageData, Point: Vector2, RectOffset: Vector2, RectSize: Vector2, Scale: Vector2?, FlipX: boolean?, FlipY: boolean?, AlphaBlending: boolean?)

  • Draws an image to the canvas with rect offset and rect size properties.

  • RectSize and RectOffset are in pixels.

  • Intended for image cropping or spritesheets.

  • NOTE: This doesn’t support padding/margins. Ensure your spritesheet contents have no padding/spacing between each sprite, or ensure you have the correct math to support padding.

Example
local Image = CanvasDraw.GetImageData(script.Tileset)

local ResX, ResY = 128, 128

local Canvas = CanvasDraw.new(Frame, Vector2.new(ResX, ResY))

local Columns, Rows = 13, 11
local SpriteSize = Vector2.new(16, 16) -- Rect size

local FPS = 3 -- How many frames we cycle through per second

local Scale = 3 -- Scale multiplier

-- Cycle through sheet sprite
while true do
	for Y = 1, Rows do
		for X = 1, Columns do

			local OffsetX = (X - 1) * SpriteSize.X
			local OffsetY = (Y - 1) * SpriteSize.Y

			Canvas:Clear()
			Canvas:DrawImageRect(Image, Vector2.new(1, 1), Vector2.new(OffsetX, OffsetY), SpriteSize, Vector2.new(Scale / Columns, Scale / Rows))

			task.wait(1 / FPS)
		end
	end
end


Parameters and Returns

Parameters:

ImageData ImageData

  • Default:
  • Description: The image that you wish to use.

Point Vector2

  • Default:
  • Description: The canvas point for the image.

RectOffset Vector2

  • Default:
  • Description: The top-left offset point for sampling the image.

RectSize Vector2

  • Default:
  • Description: The rectangular sample size for drawing the image

Scale Vector2

  • Default: Vector2.new(1, 1)
  • Description: The scale for the image. This vector is a percentage (e.g, setting to Vectoe2.new(1.5, 1) will stretch the image horizontally by 1.5x)

FlipX boolean

  • Default: false
  • Description: Flips the rect region horizontally

FlipY boolean

  • Default: false
  • Description: Flips the rect region vertically

AlphaBlending boolean

  • Default: false
  • Description: Enables true transparency/alpha blending

Returns:

Return Type: Void
Summary: Nothing will be returned (nil)


Canvas:DrawImageRectXY (ImageData, X: number, Y: number, RectOffsetX: number, RectOffsetY: number, RectSizeX: number, RectSizeY: number, ScaleX: number?, ScaleY: number?, FlipX: boolean?, FlipY: boolean?, AlphaBlending boolean?)

  • Draws an image to the canvas with rect offset and rect size properties.

  • RectSize and RectOffset are in pixels.

  • Intended for image cropping or spritesheets.

  • NOTE: This doesn’t support padding/margins. Ensure your spritesheet contents have no padding/spacing between each sprite, or ensure you have the correct math to support padding.

Example
local Image = CanvasDraw.GetImageData(script.Tileset)

local ResX, ResY = 128, 128

local Canvas = CanvasDraw.new(Frame, Vector2.new(ResX, ResY))

local Columns, Rows = 13, 11
local SpriteWidth, SpriteHeight = 16, 16

local FPS = 3 -- How many frames we cycle through per second

local Scale = 3 -- Scale multiplier

-- Cycle through sheet sprite
while true do
	for Y = 1, Rows do
		for X = 1, Columns do

			local OffsetX = (X - 1) * SpriteWidth
			local OffsetY = (Y - 1) * SpriteHeight

			Canvas:Clear()
			Canvas:DrawImageRect(Image, Vector2.new(1, 1), OffsetX, OffsetY, SpriteWidth, SpriteHeight, Scale / Columns, Scale / Rows)

			task.wait(1 / FPS)
		end
	end
end

Parameters and Returns

Parameters:

ImageData ImageData

  • Default:
  • Description: The image that you wish to use.

Point Vector2

  • Default:
  • Description: The canvas point for the image.

RectOffsetX number

  • Default:
  • Description: The top-left offset X point for sampling the image.

RectOffsetY number

  • Default:
  • Description: The top-left offset Y point for sampling the image.

RectSizeX number

  • Default:
  • Description: The rectangular sample X size for drawing the image.

RectSizeY number

  • Default:
  • Description: The rectangular sample Y size for drawing the image.

ScaleX number

  • Default: 1
  • Description: The X scale for the image. This number is a percentage (e.g, setting to 1.5 will stretch the image horizontally by 1.5x)

ScaleY number

  • Default: 1
  • Description: The Y scale for the image. This number is a percentage (e.g, setting to 1.5 will stretch the image vertically by 1.5x)

FlipX boolean

  • Default: false
  • Description: Flips the rect region horizontally

FlipY boolean

  • Default: false
  • Description: Flips the rect region vertically

AlphaBlending boolean

  • Default: false
  • Description: Enables true transparency/alpha blending

Returns:

Return Type: Void
Summary: Nothing will be returned (nil)


Canvas:DrawText (Text: string, Point: Vector2, Colour: Color3, FontName: string?, Scale: number?, Wrap: boolean?, Spacing: number?)

  • This method will draw text at a desired point on the canvas.

  • You can find the names of fonts under CanvasDraw > Fonts in the explorer.

  • TIP: You can put \n in your text parameter to have multiple lines without drawing text multiple times!

Example
Canvas:DrawText(
    "first line \n second line!", -- The text to display (`\n` means new line and will not be displayed as text)
    Vector2.new(5, 5), -- Place the text at point (5, 5)
    Color3.new(0, 0, 0), -- Make the text black 
    2 -- Make the text twice as large
)
Parameters and Returns

Parameters:

Text string

  • Default:
  • Description: The text you wish to display. NOTE: If you wish to have multiple lines in one string, you can put \n in your text to declare new lines.

Point Vector2

  • Default:
  • Description: The point on the canvas to draw the text at. (NOTE: The origin for text is at the top left corner)

Colour Color3

  • Default:
  • Description: The colour you wish to apply to the text.

FontName string

  • Default: “3x6”
  • Description: The font you wish to apply. As of v4.5.0, there are 7 fonts you can use:
    • 3x6
    • Round
    • Monogram
    • GrandCD
    • Atari
    • Codepage
    • CodepageLarge

Scale number

  • Default: 1
  • Description: The size multiplier for the text.
    (NOTE: By default, a text’s character is sized at 3x5 on the canvas. Setting the scale to 2 will double that size to 6x10 on the canvas)

Wrap boolean

  • Default: true
  • Description: When set to true, the text will wrap and create a new line if it’s outside the canvas horizontally. When set to false, the text will just cut off and not create any more text.

Spacing number

  • Default: 1
  • Description: Determines how many pixels of space should be between each character both vertically and horizontally.

Returns:

Return Type: Void
Summary: Nothing will be returned (nil).


Canvas:DrawTextXY (Text: string, X: number, Y: number, Colour: Color3, FontName: string?, Scale: number?, Wrap: boolean?, Spacing: number?)

  • This method will draw text at a desired point on the canvas.

  • You can find the names of fonts under CanvasDraw > Fonts in the explorer.

  • TIP: You can put \n in your text parameter to have multiple lines without drawing text multiple times!

  • NOTE: This function behaves exactly the same as DrawText(), but will take coordinates instead of a Vecor3 for the point.

Example
Canvas:DrawTextXY(
    "first line \n second line!", -- The text to display (`\n` means new line and will not be displayed as text)
    5, 5, -- Place the text at point (5, 5)
    Color3.new(0, 0, 0), -- Make the text black 
    2 -- Make the text twice as large
)
Parameters and Returns

Parameters:

Text string

  • Default:
  • Description: The text you wish to display. NOTE: If you wish to have multiple lines in one string, you can put \n in your text to declare new lines.

X number

  • Default:
  • Description: The X coordinate on the canvas to draw the text at.

Y number

  • Default:
  • Description: The Y coordinate on the canvas to draw the text at.

Colour Color3

  • Default:
  • Description: The colour you wish to apply to the text.

FontName string

  • Default: “3x6”
  • Description: The font you wish to apply. As of v4.5.0, there are 7 fonts you can use:
    • 3x6
    • Round
    • Monogram
    • GrandCD
    • Atari
    • Codepage
    • CodepageLarge

Scale number

  • Default: 1
  • Description: The size multiplier for the text. This value should be a whole number (int).
    (NOTE: By default, a text’s size is equal to the chosen font’s character size. Setting the scale to 2 will double that size on the canvas)

Wrap boolean

  • Default: true
  • Description: When set to true, the text will wrap and create a new line if it’s outside the canvas horizontally. When set to false, the text will just cut off and not create any more text.

Spacing number

  • Default: 1
  • Description: Determines how many pixels of space should be between each character both vertically and horizontally.

Returns:

Return Type: Void
Summary: Nothing will be returned (nil).


1 Like

ImageData Methods:


ImageData:GetPixel (Point: Vector2) : Color3, number

  • This method will return the colour and the alpha value from the ImageData from the chosen point relative to the image.
  • NOTE: An image pixel coordinates works the same as the canvas. For example, a 64x64 image starts at 1,1 (top left), and ends at 64, 64 (bottom right)
Example
-- Define the region to capture
local ImageData = Canvas:GetImageData(Gui.Textures["Wall.png"]) -- 128x128 wall texture

-- Grab the middle pixel info of our wall texture
local Colour, Transparency = ImageData:GetPixel(Vector2.new(64, 64))

print("Colour:", Colour) -- Typical Color3 value
print("Alpha:", Transparency) -- A number that ranges from 0 to 255
Parameters and Returns

Parameters:

Point Vector2

  • Default:
  • Description: The desired pixel sample point on the Image.

Returns:

Return Type: tuple
Summary: A tuple containing, in order: A Color3 value of the pixel, and a number value that represents the alpha/transparency value of the pixel


ImageData:GetPixelXY (X: number, Y: number) : Color3, number

  • This method will return the colour and the alpha value from the ImageData from the chosen point relative to the image.
  • NOTE: An image pixel coordinates works the same as the canvas. For example, a 64x64 image starts at 1,1 (top left), and ends at 64, 64 (bottom right)
Example
-- Define the region to capture
local ImageData = Canvas:GetImageData(Gui.Textures["Wall.png"]) -- 128x128 wall texture

-- Grab the middle pixel info of our wall texture
local Colour, Transparency = ImageData:GetPixelXY(64, 64)

print("Colour:", Colour) -- Typical Color3 value
print("Alpha:", Transparency) -- A number that ranges from 0 to 255
Parameters and Returns

Parameters:

X number

  • Default:
  • Description: The desired pixel sample X coordinate on the Image.

Y number

  • Default:
  • Description: The desired pixel sample Y coordinate on the Image.

Returns:

Return Type: tuple
Summary: A tuple containing, in order: A Color3 value of the pixel, and a number value that represents the alpha/transparency value of the pixel


ImageData:SetPixel (X: number, Y: number, Colour: Color3, Alpha: number?)

  • Sets a given pixel’s colour and alpha value on the ImageData.
  • The X and Y values should be between (1, 1) and (Image Width, Image Height)
  • The alpha value should between 0 and 1
Example
local ImageData = Canvas:GetImageData(Textures["Texture.png"]) -- Our image

-- Set the top left pixel to be green with an opacity of around 50%
ImageData:SetPixel(1, 1, Color3.new(0, 1, 0), 127)
Parameters and Returns

Parameters:

X number

  • Default:
  • Description: The X point that determines what pixel to set the colour and alpha value to.

Y number

  • Default:
  • Description: The Y point that determines what pixel to set the colour and alpha value to.

Colour Color3

  • Default:
  • Description: The colour that you wish to apply.

Alpha number

  • Default:
  • Description: The alpha/transparency value that you wish to apply to the pixel. This value should be between 0 and 1. Leave this parameter blank or set to false if you don’t want to change the alpha value.

Returns:

Return Type: Void
Summary: Nothing will be returned (nil)

ImageData:SetRGBA (X: number, Y: number, R: number, G: number, B: number, A: number)

  • Sets a given pixel’s RGBA value on the ImageData.
  • The X and Y values should be between (1, 1) and (Image Width, Image Height)
  • The alpha value should between 0 and 1
Example
local ImageData = Canvas:GetImageData(Textures["Texture.png"]) -- Our image

-- Set the top left pixel to be green with an opacity of 50%
ImageData:SetRGBA(1, 1, 0, 1, 0, 0.5)
Parameters and Returns

Parameters:

X number

  • Default:
  • Description: The X point that determines what pixel to set the colour and alpha value to.

Y number

  • Default:
  • Description: The Y point that determines what pixel to set the colour and alpha value to.

R number

  • Default:
  • Description: The R channel of the pixel that you wish to apply.

G number

  • Default:
  • Description: The G channel of the pixel that you wish to apply.

B number

  • Default:
  • Description: The B channel of the pixel that you wish to apply.

A number

  • Default:
  • Description: The A (alpha/transparency) channel of the pixel that you wish to apply.

Returns:

Return Type: Void
Summary: Nothing will be returned (nil)

ImageData:Tint (Colour: Color3, T: number)

  • This method will set and blend the original image colours using interpolation with a set colour and percentage.
Example
local ImageData = Canvas:GetImageData(Textures["Wall.png"]) -- Our image

-- Tint the image with 50% black
ImageData:Tint(Color3.new(0, 0, 0), 0.5)

Parameters and Returns

Parameters:

Colour Color3

  • Default:
  • Description: The colour used to interpolate with the image colours.

T number

  • Default:
  • Description: The percentage value between 0 and 1 to tint the image by.

Returns:

Return Type: void
Summary: Nothing will be returned (nil)


ImageData:TintRGB (R: number, G number, B number, T: number)

  • This method will set and blend the original image colours using interpolation with a set colour and percentage.
Example
local ImageData = Canvas:GetImageData(Textures["Wall.png"]) -- Our image

-- Tint the image with 50% black
ImageData:TintRGB(0, 0, 0, 0.5)

Parameters and Returns

Parameters:

R number

  • Default:
  • Description: The R channel of the colour used to interpolate with the image colours.

G number

  • Default:
  • Description: The G channel of the colour used to interpolate with the image colours.

B number

  • Default:
  • Description: The B channel of the colour used to interpolate with the image colours.

T number

  • Default:
  • Description: The percentage between 0 and 1 to tint the image by.

Returns:

Return Type: void
Summary: Nothing will be returned (nil)


ImageData:Clone ()

  • This method return a complete deep copy of the ImageData class.
Parameters and Returns

Returns:

Return Type: ImageData
Summary: Returns the cloned ImageData


1 Like