broken_seals/game/addons/mat_maker_gd/nodes/noise/noise.gd

69 lines
1.4 KiB
GDScript3
Raw Normal View History

tool
extends MMNode
2021-10-01 23:07:05 +02:00
var Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
var image : Image
var tex : ImageTexture
export(Vector2) var bmin : Vector2 = Vector2(0.1, 0.1)
export(Vector2) var bmax : Vector2 = Vector2(1, 1)
export(bool) var refresh setget reff,reffg
func _ready():
if !Engine.editor_hint:
gen()
func gen() -> void:
if !image:
image = Image.new()
image.create(300, 300, false, Image.FORMAT_RGBA8)
if !tex:
tex = ImageTexture.new()
# var bmin : Vector2 = Vector2(0.1, 0.1)
# var bmax : Vector2 = Vector2(1, 1)
image.lock()
var w : float = image.get_width()
var h : float = image.get_width()
var pseed : float = randf() + randi()
for x in range(image.get_width()):
for y in range(image.get_height()):
var v : Vector2 = Vector2(x / w, y / h)
# var f : float = pattern(v, 4, 4, CombinerType.MULTIPLY, CombinerAxisType.SINE, CombinerAxisType.SINE)
var col : Color = sinewave(v)
# var col : Color = beehive_2_col(v)
# var col : Color = beehive_3_col(v)
image.set_pixel(x, y, col)
image.unlock()
tex.create_from_image(image)
texture = tex
var p_o7136_amplitude = 0.500000000;
var p_o7136_frequency = 2.000000000;
var p_o7136_phase = 0.000000000;
func sinewave(uv : Vector2) -> Color:
2021-10-02 15:38:12 +02:00
return Commons.sinewave(uv, p_o7136_amplitude, p_o7136_frequency, p_o7136_phase)
func reffg():
return false
func reff(bb):
if bb:
gen()