-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathellipse.gd
38 lines (27 loc) · 855 Bytes
/
ellipse.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
@tool
extends Path2D
# Declare member variables here. Examples:
@export var segments = 32
@export var xAxis = 50
@export var yAxis = 70
# Called when the node enters the scene tree for the first time.
func _ready():
curve.clear_points()
calculateEllipse()
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
# based on https://www.youtube.com/watch?v=mQKGRoV_jBc
func calculateEllipse():
for i in range(segments):
var angle = (float(i) / segments) * deg_to_rad(360);
var x = sin(angle) * xAxis;
var y = cos(angle) * yAxis;
self.curve.add_point(Vector2(x,y))
#points.append(Vector2(x,y))
# close
self.curve.add_point(self.curve.get_point_position(0))
# debug
#for i in curve.get_point_count():
# print(curve.get_point_position(i))