-
Notifications
You must be signed in to change notification settings - Fork 1
/
Lissajour.gd
80 lines (67 loc) · 2.21 KB
/
Lissajour.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
extends Node2D
var amplitude_x = 50 # x 진폭
var amplitude_y = 50 # y 진폭
var frequency_x = 1 # x 각진동수
var frequency_y = 1 # y 각진동수
var delta_angle = PI/8 # 위상차 (90도)
var time = 0
var speed = 1.0 # 속도 조절 변수
var curves = []
var current_positions = []
func _ready():
for i in range(8):
for j in range(8):
frequency_x = i + 1
frequency_y = j + 1
curves.append(generate_curve(i, j))
current_positions.append(Vector2.ZERO)
func _process(delta):
time += delta * speed
update_current_positions()
queue_redraw()
func _draw():
var offset = Vector2(50, 50)
var spacing = Vector2(120, 120)
for i in range(8):
for j in range(8):
var pos = offset + Vector2(j, i) * spacing
draw_lissajous_curve(curves[i * 8 + j], pos)
draw_current_position(current_positions[i * 8 + j], pos)
func _input(event):
if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
var offset = Vector2(50, 50)
var spacing = Vector2(120, 120)
for i in range(8):
for j in range(8):
var pos = offset + Vector2(j, i) * spacing
var rect = Rect2(pos - Vector2(60, 60), Vector2(120, 120))
if rect.has_point(event.position):
print_formula(i, j)
func generate_curve(i, j):
var curve = []
for t in range(200):
var angle = t * PI / 100
var x = amplitude_x * sin((i + 1) * angle + j * delta_angle)
var y = amplitude_y * sin((j + 1) * angle)
curve.append(Vector2(x, y))
return curve
func update_current_positions():
for i in range(8):
for j in range(8):
var index = i * 8 + j
var angle = time * (i + 1)
var x = amplitude_x * sin(angle + j * delta_angle)
var y = amplitude_y * sin(time * (j + 1))
current_positions[index] = Vector2(x, y)
func draw_lissajous_curve(curve, position):
var points = PackedVector2Array()
for point in curve:
points.append(point + position)
draw_polyline(points, Color.WHITE, 1.0)
func draw_current_position(position, offset):
draw_circle(position + offset, 5, Color.RED)
func print_formula(i, j):
var formula = "x = %d * sin(%d * t + %d * %f)\ny = %d * sin(%d * t)" % [amplitude_x, i + 1, j, delta_angle, amplitude_y, j + 1]
print("Offset (%d, %d) formula:" % [i, j])
print(formula)
print()