PirateTreasureHunt/IslandGenerator.gd

46 lines
1.2 KiB
GDScript

extends Node2D
var circles = []
# Called when the node enters the scene tree for the first time.
func _ready():
generate()
func add_circle (pos, radius, color):
circles.append ([pos, radius, color])
func render_recursive (pos, radius, count):
add_circle (pos, radius, "#888888")
for i in range (count):
var angle = rand_range(0, 2 * PI)
var dist_scale = rand_range (0.9, 1.8)
var coord = Vector2 (cos(angle), sin(angle)) * radius * dist_scale
render_recursive (pos + coord, radius * 0.6, count - 1)
func generate():
var start = OS.get_window_safe_area().size * 0.5
var radius = 100
circles.clear()
render_recursive (start, radius, get_node("HBoxContainer/IterationsSpinBox").value)
var angle = rand_range(0, 2 * PI)
var coord = Vector2 (cos(angle), sin(angle)) * radius * 3
render_recursive (start + coord, 70, get_node("HBoxContainer/IterationsSpinBox").value)
render_recursive (start + coord * 2, 60, get_node("HBoxContainer/IterationsSpinBox").value)
update()
get_node("blur").texture = get_viewport().get_texture()
# get_node("pixelate").texture = get_viewport().get_texture()
func _draw():
for c in circles:
draw_circle (c[0], c[1], c[2])
func _on_Button_pressed():
generate()