Last active
December 1, 2022 02:18
-
-
Save Hairic95/e2612f5dd94e56a25ee4e25b9daa3a3a to your computer and use it in GitHub Desktop.
Random Sprite generator with horizontal symmetry for Godot
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
extends Sprite | |
export (int) var width = 16 | |
export (int) var height = 16 | |
func _ready(): | |
randomize() | |
var imageTexture = ImageTexture.new() | |
var image = Image.new() | |
image.create(width, height, false, Image.FORMAT_RGB8) | |
var image_grid = [] | |
image.lock() | |
for x in range(width / 2): | |
var array_grid = [] | |
for y in range(height): | |
if (randi()%2 == 0): | |
array_grid.append(0) | |
else: | |
array_grid.append(1) | |
image_grid.append(array_grid) | |
var color = Color(randf(), randf(), randf()) | |
for x in range(width): | |
for y in range(height): | |
var x_index = 0 | |
if x >= width / 2: | |
x_index = (width - 1) - x | |
else: | |
x_index = x | |
if image_grid[x_index][y] == 0: | |
image.set_pixel(x, y, color) | |
imageTexture.create_from_image(image) | |
texture = imageTexture | |
imageTexture.resource_name = "randomSprite" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment