94 lines
2.6 KiB
GDScript
94 lines
2.6 KiB
GDScript
extends RefCounted
|
|
|
|
class_name SpriteGeneration
|
|
|
|
static func color_sprinkle_image(image:Image, color:Color, ignoreColors:Array[Color] = []):
|
|
var imageWidth = image.get_width()
|
|
var imageHeight = image.get_height()
|
|
|
|
var sprinkleOffsets = [5, 6, 3, 4, 6, 4, 5, 3, 2, 4, 4, 6, 3, 2, 4]
|
|
var sprinkleOffsetIndex = 0
|
|
var countToSprinkle = 3
|
|
for x in range(imageWidth):
|
|
for y in range(imageHeight):
|
|
var currentColor = image.get_pixel(x, y)
|
|
if currentColor.a > 0 and !(currentColor in ignoreColors):
|
|
countToSprinkle -= 1
|
|
if countToSprinkle <= 0:
|
|
image.set_pixel(x, y, color)
|
|
countToSprinkle = sprinkleOffsets[sprinkleOffsetIndex]
|
|
|
|
sprinkleOffsetIndex += 1
|
|
if sprinkleOffsetIndex >= sprinkleOffsets.size():
|
|
sprinkleOffsetIndex = 0
|
|
|
|
return image
|
|
|
|
static func color_multipy_image(image:Image, color:Color):
|
|
var imageWidth = image.get_width()
|
|
var imageHeight = image.get_height()
|
|
|
|
for x in range(imageWidth):
|
|
for y in range(imageHeight):
|
|
var currentColor = image.get_pixel(x, y)
|
|
if currentColor.a > 0:
|
|
image.set_pixel(x, y, currentColor * color)
|
|
|
|
return image
|
|
|
|
static func color_blend_image(image:Image, color:Color):
|
|
var imageWidth = image.get_width()
|
|
var imageHeight = image.get_height()
|
|
|
|
for x in range(imageWidth):
|
|
for y in range(imageHeight):
|
|
var currentColor = image.get_pixel(x, y)
|
|
if currentColor.a > 0:
|
|
image.set_pixel(x, y, currentColor.blend(color))
|
|
|
|
return image
|
|
|
|
static func add_lower_outline(image:Image, color:Color, pixelCount:int = 3):
|
|
var imageWidth = image.get_width()
|
|
var imageHeight = image.get_height()
|
|
|
|
var outlineLeft = 0
|
|
for x in range(imageWidth):
|
|
outlineLeft = 0
|
|
for y in range(imageHeight):
|
|
var currentColor = image.get_pixel(x, y)
|
|
if currentColor.a == 0:
|
|
if outlineLeft > 0:
|
|
image.set_pixel(x, y, color)
|
|
outlineLeft -= 1
|
|
else:
|
|
outlineLeft = pixelCount
|
|
|
|
return image
|
|
|
|
static func get_average_color(image:Image, ignoreColors:Array[Color] = []):
|
|
var totalRed = 0
|
|
var totalGreen = 0
|
|
var totalBlue = 0
|
|
|
|
var imageWidth = image.get_width()
|
|
var imageHeight = image.get_height()
|
|
|
|
var pixelsChecked = 0
|
|
for x in range(imageWidth):
|
|
for y in range(imageHeight):
|
|
var currentColor = image.get_pixel(x, y)
|
|
if currentColor.a > 0 and !(currentColor in ignoreColors):
|
|
pixelsChecked += 1
|
|
|
|
totalRed += currentColor.r
|
|
totalGreen += currentColor.g
|
|
totalBlue += currentColor.b
|
|
|
|
if pixelsChecked > 0:
|
|
totalRed = totalRed / pixelsChecked
|
|
totalGreen = totalGreen / pixelsChecked
|
|
totalBlue = totalBlue / pixelsChecked
|
|
|
|
return Color(totalRed, totalGreen, totalBlue)
|