Last active
September 10, 2023 06:33
-
-
Save hhkcu/8c23990dc8462075a1c520c6fb6cf597 to your computer and use it in GitHub Desktop.
An example of Roblox's new DynamicImage class, written by ChatGPT. Note: DynamicImage must be a child of ImageLabel, or else the game will crash
This file contains hidden or 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
| -- Create a new DynamicImage | |
| local dynamicImage = Instance.new("DynamicImage") | |
| -- Set the size of the dynamic image | |
| local imageSize = Vector2.new(512, 512) | |
| dynamicImage.Size = imageSize | |
| -- Parent the dynamic image to the workspace or another GUI element | |
| dynamicImage.Parent = script.Parent -- MUST BE AN IMAGELABEL - WILL CRASH IF NOT | |
| -- Function to draw a checkerboard pattern | |
| local function drawCheckerboard() | |
| local pixels = {} | |
| for y = 1, imageSize.y do | |
| for x = 1, imageSize.x do | |
| -- Alternate between white and black squares | |
| local color = (x + y) % 2 == 0 and Color3.new(0, 0, 0) or Color3.new(1, 1, 1) | |
| table.insert(pixels, color.r) -- Red channel | |
| table.insert(pixels, color.g) -- Green channel | |
| table.insert(pixels, color.b) -- Blue channel | |
| table.insert(pixels, 1) -- Alpha channel (fully opaque) | |
| end | |
| end | |
| -- Write the pixel data to the dynamic image | |
| dynamicImage:WritePixels(Vector2.new(0, 0), imageSize, pixels) | |
| end | |
| -- Draw a checkerboard pattern on the dynamic image | |
| drawCheckerboard() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment