|
| 1 | +extends Control |
| 2 | + |
| 3 | +var noise = OpenSimplexNoise.new() |
| 4 | + |
| 5 | +var noise_size = 500 |
| 6 | +var min_noise = -1 |
| 7 | +var max_noise = 1 |
| 8 | + |
| 9 | +# Called when the node enters the scene tree for the first time. |
| 10 | +func _ready(): |
| 11 | + |
| 12 | + #Set up noise with basic info |
| 13 | + $ParameterContainer/SeedSpinBox.value = noise.seed |
| 14 | + $ParameterContainer/LacunaritySpinBox.value = noise.lacunarity |
| 15 | + $ParameterContainer/OctavesSpinBox.value = noise.octaves |
| 16 | + $ParameterContainer/PeriodSpinBox.value = noise.period |
| 17 | + $ParameterContainer/PersistenceSpinBox.value = noise.persistence |
| 18 | + |
| 19 | + #Render the noise |
| 20 | + _refresh_noise_images() |
| 21 | + |
| 22 | + |
| 23 | +func _refresh_noise_images(): |
| 24 | + |
| 25 | + #Get a new image |
| 26 | + var image = noise.get_seamless_image(500) |
| 27 | + var image_texture = ImageTexture.new() |
| 28 | + |
| 29 | + #Adjust min/max for shader |
| 30 | + var _min = ((min_noise + 1)/2) |
| 31 | + var _max = ((max_noise + 1)/2) |
| 32 | + var _material = $SeamlessNoiseTexture.material |
| 33 | + _material.set_shader_param("min_value", _min) |
| 34 | + _material.set_shader_param("max_value", _max) |
| 35 | + |
| 36 | + #Draw it |
| 37 | + image_texture.create_from_image(image) |
| 38 | + $SeamlessNoiseTexture.texture = image_texture |
| 39 | + |
| 40 | + |
| 41 | +func _on_DocumentationButton_pressed(): |
| 42 | + OS.shell_open("https://docs.godotengine.org/en/latest/classes/class_opensimplexnoise.html") |
| 43 | + |
| 44 | + |
| 45 | +func _on_SeedSpinBox_value_changed(value): |
| 46 | + |
| 47 | + #Update the noise seed |
| 48 | + noise.seed = value |
| 49 | + _refresh_noise_images() |
| 50 | + |
| 51 | + |
| 52 | +func _on_LacunaritySpinBox_value_changed(value): |
| 53 | + |
| 54 | + #Update noise |
| 55 | + noise.lacunarity = value |
| 56 | + _refresh_noise_images() |
| 57 | + |
| 58 | + |
| 59 | +func _on_OctavesSpinBox_value_changed(value): |
| 60 | + |
| 61 | + #Update noise |
| 62 | + noise.octaves = value |
| 63 | + _refresh_noise_images() |
| 64 | + |
| 65 | + |
| 66 | +func _on_PeriodSpinBox_value_changed(value): |
| 67 | + |
| 68 | + #Update noise |
| 69 | + noise.period = value |
| 70 | + _refresh_noise_images() |
| 71 | + |
| 72 | + |
| 73 | +func _on_PersistenceSpinBox_value_changed(value): |
| 74 | + |
| 75 | + #Update noise |
| 76 | + noise.persistence = value |
| 77 | + _refresh_noise_images() |
| 78 | + |
| 79 | + |
| 80 | +func _on_MinClipSpinBox_value_changed(value): |
| 81 | + |
| 82 | + #Just refresh |
| 83 | + min_noise = value |
| 84 | + _refresh_noise_images() |
| 85 | + |
| 86 | + |
| 87 | +func _on_MaxClipSpinBox_value_changed(value): |
| 88 | + |
| 89 | + #Just refresh |
| 90 | + max_noise = value |
| 91 | + _refresh_noise_images() |
| 92 | + |
0 commit comments