2020-04-27 15:09:54 +00:00
|
|
|
class Drawer:
|
|
|
|
func reset() -> void:
|
|
|
|
pass
|
|
|
|
|
2020-04-30 21:02:52 +00:00
|
|
|
func set_pixel(_sprite: Image, _pos: Vector2, _new_color: Color) -> void:
|
2020-04-27 15:09:54 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class SimpleDrawer extends Drawer:
|
|
|
|
func reset() -> void:
|
|
|
|
pass
|
|
|
|
|
2020-05-01 17:47:10 +00:00
|
|
|
|
2020-04-30 21:02:52 +00:00
|
|
|
func set_pixel(_sprite: Image, _pos: Vector2, _new_color: Color) -> void:
|
|
|
|
_sprite.set_pixel(_pos.x, _pos.y, _new_color)
|
2020-04-27 15:09:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PixelPerfectDrawer extends Drawer:
|
|
|
|
const neighbours = [Vector2(0, 1), Vector2(1, 0), Vector2(-1, 0), Vector2(0, -1)]
|
|
|
|
const corners = [Vector2(1, 1), Vector2(-1, -1), Vector2(-1, 1), Vector2(1, -1)]
|
|
|
|
var last_pixels = [null, null]
|
|
|
|
|
2020-05-01 17:47:10 +00:00
|
|
|
|
2020-04-27 15:09:54 +00:00
|
|
|
func reset():
|
|
|
|
last_pixels = [null, null]
|
|
|
|
|
2020-05-01 17:47:10 +00:00
|
|
|
|
2020-04-30 21:02:52 +00:00
|
|
|
func set_pixel(_sprite: Image, _pos: Vector2, _new_color: Color) -> void:
|
|
|
|
last_pixels.push_back([_pos, _sprite.get_pixel(_pos.x, _pos.y)])
|
|
|
|
_sprite.set_pixel(_pos.x, _pos.y, _new_color)
|
2020-04-27 15:09:54 +00:00
|
|
|
|
|
|
|
var corner = last_pixels.pop_front()
|
|
|
|
var neighbour = last_pixels[0]
|
|
|
|
|
|
|
|
if corner == null or neighbour == null:
|
|
|
|
return
|
|
|
|
|
2020-04-30 21:02:52 +00:00
|
|
|
if _pos - corner[0] in corners and _pos - neighbour[0] in neighbours:
|
|
|
|
_sprite.set_pixel(neighbour[0].x, neighbour[0].y, neighbour[1])
|
2020-04-27 15:09:54 +00:00
|
|
|
last_pixels[0] = corner
|