1- // / @desc Examples
2-
3- // New Vector2
4- var vector2 = new Vector2(324 , 567 );
5-
6- // Vector2 to_string()
7- // returns a document, you can supply your own separator as input, by default ":"
8- // first x then y
9- log (vector2.to_string()); // Outuput: 324:567
10- log (vector2.to_string(" ][" )); // Outuput: 324][567
11-
12- // Vector2 negative()
13- // makes vector values negative
14- vector2.negative();
15- log (vector2.to_string()); // Outuput: -324:-567
16-
17- // Vector2 set()
18- // sets values for x & y a vector
19- vector2.set(35 , 60 ); // or vector2.set(new Vector2(35, 60));
20- log (vector2.to_string()); // Outuput: 35:60
21-
22- // Vector2 add()
23- // summing one vector by another, or alternatively takes two coordinates
24- vector2.add(35 , 60 );
25- log (vector2.to_string()); // Outuput: 70:120
26-
27- // I did not create a function for subtraction,
28- // you can simply use the negative() function and the vector itself to be subtracted
29- var some_vector = new Vector2(-35 , -60 );
30- vector2.add(some_vector);
31- log (vector2.to_string()); // Outuput: 35:60
32-
33- // Vector2 multi()
34- // multiply one vector by another, or alternatively takes two coordinates
35- vector2.multi(2 , 2 );
36- log (vector2.to_string()); // Outuput: 70:120
37- vector2.multi(new Vector2(2 , 2 ));
38- log (vector2.to_string()); // Outuput: 140:240
39- // Division can be done through multiplication
40- vector2.multi(0.1 , 0.1 );
41- log (vector2.to_string()); // Outuput: 7:12
42-
43- // Vector2 zero()
44- // Nullifies the vector
45- vector2.zero();
46- log (vector2.to_string()); // Outuput: 0:0
47-
48- // Vector2 _min() _max() _clamp()
49- // accepts either a vector or numeric values as input and returns
50- vector2.set(vector2._max(10 , 10 )); // Set max to vector
51- log (vector2.to_string()); // Outuput: 10:10
52- log ((vector2._min(new Vector2(0 , 11 ))).to_string()); // Outuput: 0:10
53- log ((vector2._clamp(4 , 10 , 3 , 5 )).to_string()); // Outuput: 3:5
54-
55- // Vector2 _length()
56- // returns the length of the vector according to the formula
57- // sqr(x * x + y * y)
58- // P.S. the function returns a real number, but the log automatically converts to a string
59- log (vector2._length()); // Outuput: 4000
60-
61- // Vector2 _lerp() & not Vector2 fumction vector2_to_string()
62- // this also works for either numbers or vector
63- log (vector2_to_string(vector2, " Juju " )); // Outuput: 10 Juju 10
64- log (vector2_to_string(vector2._lerp(100 , 100 , 0.5 ), " - ")); // Outuput: 55 - 55
65-
66-
67- // ########################### DIR EXAMPLE ##########################
68- // Vector2 dir_set()
69- // for info look: https://tornado-technology.github.io/Vectors/#/latest/methods?id=installed-dir
70- vector2.dir_set(vector2_dir.down, 13 );
71- log (vector2.to_string()) // Outuput: 10:-13
72-
73- vector2.dir_add(vector2_dir.right, 100 );
74- log (vector2.to_string()) // Outuput: 110:-13
75-
76- vector2.dir_multi(vector2_dir.one, 0.1 );
77- log (vector2.to_string()) // Outuput: 11:-1.30
1+ var vector = Vector2(10 , 15 );
2+
3+ // Converts
4+ log (" Converts" );
5+
6+ log (vector.to_string());
7+ log (vector.to_string(" - " ));
8+
9+ log (vector.to_array());
10+ log (vector.to_array(true ));
11+
12+ // Console can't normaly print list
13+ log (vector.to_list());
14+ log (vector.to_list(true ));
15+
16+ delete vector;
17+ log (" ==========" );
18+
19+ // Set
20+ log (" Sets" );
21+
22+ // If you do not write a Y value, it will default to the X value,
23+ // And if you do not write anything, the vector will take on the value 0, 0
24+ var shortVector = Vector2(10 );
25+
26+ // Zero - x: 0, y: 0
27+ // One - x: 1, y: 1
28+ // Negative - x: -x, y: -y
29+ log (shortVector.zero().to_string());
30+ log (shortVector.one().to_string());
31+ log (shortVector.negative().to_string());
32+
33+ delete shortVector;
34+ log (" ==========" );
35+
36+ // Math - Base
37+ var mathBaseVector = Vector2();
38+ log (" Math - Base" );
39+
40+ // I will say once all these functions
41+ // Can take as input both a vector and two numbers separated by a comma
42+ log (mathBaseVector.set(70 , 70 ).to_string());
43+ log (mathBaseVector.add(10 , 10 ).to_string());
44+ log (mathBaseVector.sub(20 , 20 ).to_string());
45+ log (mathBaseVector.multi(10 , 10 ).to_string());
46+ log (mathBaseVector.divis(20 , 20 ).to_string());
47+
48+ delete mathBaseVector;
49+ log (" ==========" );
50+
51+ // Math - Base
52+ var mathVector = Vector2(10 , 30 );
53+ log (" Math" );
54+
55+ log (mathVector.math_length());
56+ log (mathVector.math_min(100 , 100 ));
57+ log (mathVector.math_max(2 , 2 ));
58+ log (mathVector.math_clamp(2 , 50 , 2 , 50 ));
59+ log (mathVector.math_lerp(60 , 60 , 0.2 ));
60+
61+ delete mathVector;
62+ log (" ==========" );
63+
64+ // Utils
65+ var utilsVector = Vector2(15 , 35 );
66+ log (" Utils" );
67+
68+ log (utilsVector.to_string());
69+ log (utilsVector.copy().add(1 , 1 ).to_string());
70+ log (utilsVector.to_string());
71+
72+ delete utilsVector;
73+ log (" ==========" );
74+
75+ var dirVector = Vector2(17 );
76+ log (" Dirs" );
77+
78+ // For more info look: https://tornado-technology.github.io/Vectors/#/latest/methods?id=installed-dir
79+ log (dirVector.dir_set(vector2_dir.down, 13 ).to_string());
80+ log (dirVector.dir_add(vector2_dir.right, 100 ).to_string());
81+ log (dirVector.dir_multi(vector2_dir.one, 0.1 ).to_string());
82+
83+ delete dirVector;
84+ log (" ==========" );
85+
86+ // Look to Draw event and obj_square for more functionality!
0 commit comments