From 957b89e49db0f01f24b989772592d2dd897218bf Mon Sep 17 00:00:00 2001 From: JailDoctor Date: Tue, 7 Dec 2021 17:47:03 +0100 Subject: [PATCH] Add 'mid' --- mid.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 mid.md diff --git a/mid.md b/mid.md new file mode 100644 index 0000000..aae4b99 --- /dev/null +++ b/mid.md @@ -0,0 +1,46 @@ +# mid(x,y,z) +Dels tres valors que se li passen, ens torna el que està en mig. És com un "*clamp*". És útil per a restringir un valor entre un màxim i un mínim, per exemple `mid(maxim, valor, minim)`. + +### Paràmetres + +`x` +Un dels valors a comparar. +`y` +Altre valor a comparar. +`z` +L'ultim valor a comparar. + +### Exemple +``` +function init() + setmode(2) + x,y=10,7 + color(COLOR_YELLOW, COLOR_BLUE) +end + +function update() + cls() + if btn(KEY_UP) then + y = max(0, y-1) + elseif btn(KEY_DOWN) then + y = min(y+1, 14) + end + if btn(KEY_LEFT) then + x = max(0, x-1) + elseif btn(KEY_RIGHT) then + x = min(x+1, 19) + end + print("\224",x,y) +end +``` +### Vore també +* [abs(x)](abs) +* [ceil(x)](ceil) +* [flr(x)](flr) +* [sgn(x)](sgn) +* [sin(x)](sin) +* [cos(x)](cos) +* [atan2(x,y)](atan2) +* [sqrt(x)](sqrt) +* [max(x,y)](max) +* [min(x,y)](min)