initial and starry sky
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
extends Node2D
|
||||
|
||||
const STAR_COLOR_DISTRIBUTION = [
|
||||
[700, '#8FA8FFFF'],
|
||||
[1700, '#8FA8FFD8'],
|
||||
[3400, '#8FA8FFA0'],
|
||||
[6000, '#A0B5FFFF'],
|
||||
[9900, '#A0B5FFD0'],
|
||||
[16400, '#A0B5FF90'],
|
||||
[17300, '#B0C5FFFF'],
|
||||
[18600, '#B0C5FFC8'],
|
||||
[20800, '#B0C5FF88'],
|
||||
[26000, '#D0DBFFFF'],
|
||||
[33800, '#D0DBFFC0'],
|
||||
[46800, '#D0DBFF80'],
|
||||
[57200, '#F8F7FFE0'],
|
||||
[72900, '#F8F7FFA8'],
|
||||
[99000, '#F8F7FF70'],
|
||||
[114700, '#FFF4EAD0'],
|
||||
[138200, '#FFF4EA98'],
|
||||
[177400, '#FFF4EA60'],
|
||||
[180000, '#FFD280F0'],
|
||||
[183000, '#FFD280B8'],
|
||||
[189000, '#FFD28078'],
|
||||
[191000, '#FFA64DF8'],
|
||||
[194000, '#FFA64DC0'],
|
||||
[199000, '#FFA64D80'],
|
||||
[225000, '#FFE4B5C0'],
|
||||
[264000, '#FFE4B588'],
|
||||
[309000, '#FFE4B550'],
|
||||
[364000, '#FFCC99A0'],
|
||||
[441000, '#FFCC9968'],
|
||||
[604000, '#FFCC9940'],
|
||||
[658000, '#FFB36690'],
|
||||
[753000, '#FFB3665C'],
|
||||
[893000, '#FFB36630'],
|
||||
[914000, '#E8F4FF80'],
|
||||
[946000, '#E8F4FF50'],
|
||||
[1000000, '#E8F4FF28'],
|
||||
]
|
||||
|
||||
@export_group("Visual Settings")
|
||||
@export var Star_Count: int = 5000: set = set_star_count
|
||||
@export var Background_Image_Size: Vector2 = Vector2(4096, 4096): set = set_Background_Image_Size
|
||||
@export var background_color: Color = Color.BLACK
|
||||
|
||||
@export_group("Animation")
|
||||
@export var auto_rotate: bool = false
|
||||
@export var rotation_speed: float = 0.1
|
||||
|
||||
var rotation_angle: float = 0.0
|
||||
|
||||
func _ready():
|
||||
queue_redraw()
|
||||
|
||||
func _draw():
|
||||
draw_rect(Rect2(Vector2.ZERO, Background_Image_Size), background_color)
|
||||
|
||||
# Сохраняем текущее состояние трансформации
|
||||
var transform = Transform2D().rotated(rotation_angle)
|
||||
draw_set_transform_matrix(transform)
|
||||
|
||||
draw_galaxy()
|
||||
|
||||
func draw_galaxy():
|
||||
for ind1 in range(Star_Count):
|
||||
var star_coords = Vector2(randi_range(0, Background_Image_Size.x),
|
||||
randi_range(0, Background_Image_Size.y))
|
||||
var star_color = get_star_color()
|
||||
draw_circle(star_coords, 1, star_color)
|
||||
|
||||
func _process(delta):
|
||||
if auto_rotate:
|
||||
rotation_angle += rotation_speed * delta
|
||||
queue_redraw()
|
||||
|
||||
if Engine.is_editor_hint():
|
||||
queue_redraw()
|
||||
|
||||
func get_star_color() -> Color:
|
||||
#var star_color = {"rgb": Colo, "alpha": 0}
|
||||
var rnd_seed = randi_range(0, STAR_COLOR_DISTRIBUTION[-1][0])
|
||||
for item:Array in STAR_COLOR_DISTRIBUTION:
|
||||
if rnd_seed <= item[0]:
|
||||
return Color.html(item[1])
|
||||
return Color.BLACK
|
||||
|
||||
#region Сеттеры для автоматического обновления
|
||||
func set_Background_Image_Size(value: Vector2):
|
||||
Background_Image_Size = value
|
||||
queue_redraw()
|
||||
|
||||
func set_star_count(value: int):
|
||||
Star_Count = value
|
||||
queue_redraw()
|
||||
|
||||
#endregion
|
||||
Reference in New Issue
Block a user