Skip to content

Commit 640d331

Browse files
committed
maths
1 parent 0197ba0 commit 640d331

File tree

12 files changed

+162
-35
lines changed

12 files changed

+162
-35
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
surf_circle = surface_create(256, 256);
22
surf_curved = surface_create(256, 256);
33

4-
percentage = new ValueDelta(1, -0.01, 0, 1);
5-
alpha = new ValueDelta(1, -0.001, 0.25, 1);
4+
percentage = new ValueDelta(1, -0.01, 0, 1, VDLimitMode.CLAMP);
5+
alpha = new ValueDelta(1, -0.001, 0.25, 1, VDLimitMode.CLAMP);

current-scripts/Demos/useful-scripts/objects/obj_math_demo/Create_0.gml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ vec_B = new Vector2(-1, 2);
33
vec_C = new Vector3(-2, 3, 4);
44
vec_D = new Vector3(10, -5, 7);
55

6-
pulse_counter = new ValueDelta(0, 0.01, 0, 1);
6+
pulse_counter = new ValueDelta(0, 0.01, 0, 1, VDLimitMode.WRAP);
77
pulse_t = 0;

current-scripts/Demos/useful-scripts/objects/obj_math_demo/Draw_0.gml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
draw_set_font(fnt_title);
2+
draw_set_valign(fa_top);
23
draw_set_halign(fa_center);
34
draw_set_colour(c_white);
45
draw_text(room_width/2, 16, "Math Demo");
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
11
pulse_counter.update();
2-
pulse_t = pulse(pulse_counter.v, 0.5, 1);
3-
4-
if (pulse_counter.v == 1) {
5-
pulse_counter.v = 0;
6-
}
2+
pulse_t = pulse(pulse_counter.v, 0.5, 1);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
actual_xpos = new ValueDelta(start_v, start_d, actual_min, actual_max, VDLimitMode.NONE);
2+
soft_clamp_xpos = start_v;
3+
soft_ceiling_xpos = start_v;
4+
soft_floor_xpos = start_v;
5+
clamp_xpos = start_v;
6+
min_xpos = start_v;
7+
max_xpos = start_v;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
draw_set_color(c_white);
2+
draw_line(limit_min, y-16, limit_min, y+224);
3+
draw_line(limit_max, y-16, limit_max, y+224);
4+
5+
draw_set_color(c_gray);
6+
draw_line(actual_min, y-16, actual_min, y+224);
7+
draw_line(actual_max, y-16, actual_max, y+224);
8+
9+
draw_set_color(c_white);
10+
draw_set_font(fnt_demo);
11+
draw_set_valign(fa_center);
12+
draw_set_halign(fa_left);
13+
draw_text(16, y, "Raw");
14+
draw_circle(actual_xpos.v, y, 16, false);
15+
16+
draw_set_color($8080FF);
17+
draw_text(16, y+48, "Soft Clamp");
18+
draw_circle(soft_clamp_xpos, y+48, 16, false);
19+
20+
draw_set_color($80FFFF);
21+
draw_text(16, y+80, "Soft Ceiling");
22+
draw_circle(soft_ceiling_xpos, y+80, 16, false);
23+
24+
draw_set_color($80FF80);
25+
draw_text(16, y+112, "Soft Floor");
26+
draw_circle(soft_floor_xpos, y+112, 16, false);
27+
28+
draw_set_color($FFFF80);
29+
draw_text(16, y+160, "Clamp");
30+
draw_circle(clamp_xpos, y+160, 16, false);
31+
32+
draw_set_color($FF8080);
33+
draw_text(16, y+192, "Min");
34+
draw_circle(min_xpos, y+192, 16, false);
35+
36+
draw_set_color($FF80FF);
37+
draw_text(16, y+224, "Max");
38+
draw_circle(max_xpos, y+224, 16, false);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
actual_xpos.update();
2+
3+
if (actual_xpos.v <= actual_xpos.min_v || actual_xpos.v >= actual_xpos.max_v) {
4+
actual_xpos.d *= -1;
5+
}
6+
7+
soft_clamp_xpos = soft_clamp(actual_xpos.v, actual_xpos.d, limit_min, limit_max);
8+
soft_ceiling_xpos = soft_ceiling(actual_xpos.v, actual_xpos.d, limit_max);
9+
soft_floor_xpos = soft_floor(actual_xpos.v, actual_xpos.d, limit_min);
10+
clamp_xpos = clamp(actual_xpos.v, limit_min, limit_max);
11+
min_xpos = min(actual_xpos.v, limit_max);
12+
max_xpos = max(actual_xpos.v, limit_min);

current-scripts/Demos/useful-scripts/objects/obj_soft_mover/obj_soft_mover.yy

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

current-scripts/Demos/useful-scripts/rooms/room_math_demo/room_math_demo.yy

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

current-scripts/Demos/useful-scripts/scripts/math_functions/math_functions.gml

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,7 @@ function pulse(_t, _min, _max) {
7070
/// @param {real} delta
7171
/// @param {real} max
7272
function soft_ceiling(_value, _delta, _max) {
73-
var _new_value = _value + _delta;
74-
75-
if (_value > _max) {
76-
return _new_value;
77-
} else {
78-
return min(_new_value, _max);
79-
}
73+
return _value > _max && _delta > 0 ? min(_value, _max) : _value + _delta;
8074
}
8175

8276

@@ -86,13 +80,7 @@ function soft_ceiling(_value, _delta, _max) {
8680
/// @param {real} delta
8781
/// @param {real} min
8882
function soft_floor(_value, _delta, _min) {
89-
var _new_value = _value + _delta;
90-
91-
if (_value < _min) {
92-
return _new_value;
93-
} else {
94-
return max(_new_value, _min);
95-
}
83+
return _value < _min && _delta < 0 ? max(_value, _min) : _value + _delta;
9684
}
9785

9886

@@ -103,13 +91,7 @@ function soft_floor(_value, _delta, _min) {
10391
/// @param {real} min
10492
/// @param {real} max
10593
function soft_clamp(_value, _delta, _min, _max) {
106-
var _new_value = _value + _delta;
107-
108-
if (_value < _min || _value > _max) {
109-
return _new_value;
110-
} else {
111-
return clamp(_new_value, _min, _max);
112-
}
94+
return (_value > _max && _delta > 0) || (_value < _min && _delta < 0) ? clamp(_value, _min, _max) : _value + _delta;
11395
}
11496

11597

@@ -119,7 +101,7 @@ function soft_clamp(_value, _delta, _min, _max) {
119101
/// @apara {real} min
120102
/// @param {real} max
121103
function wrap(_value, _min, _max) {
122-
var _range = _max - _min + 1;
104+
var _range = _max - _min;
123105

124106
if (_range + _min == 0) return 0;
125107

0 commit comments

Comments
 (0)