Map range: Difference between revisions

291 bytes added ,  1 month ago
Added Easylang
(Added Easylang)
 
(2 intermediate revisions by one other user not shown)
Line 1,140:
=={{header|Delphi}}==
See [[#Pascal]].
=={{header|EasyLang}}==
<syntaxhighlight>
func map_range a1 a2 b1 b2 s .
return b1 + (s - a1) * (b2 - b1) / (a2 - a1)
.
for i = 0 to 10
print i & " -> " & map_range 0 10 -1 0 i
.
</syntaxhighlight>
{{out}}
<pre>
0 -> -1
1 -> -0.90
2 -> -0.80
3 -> -0.70
4 -> -0.60
5 -> -0.50
6 -> -0.40
7 -> -0.30
8 -> -0.20
9 -> -0.10
10 -> 0
</pre>
 
=={{header|EchoLisp}}==
EchoLisp provides several native interpolation functions: smoothstep, s-curve, .. and '''linear''' which performs linear interpolation.
Line 3,588 ⟶ 3,612:
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Fmt
 
var mapRange = Fn.new { |a, b, s| b.from + (s - a.from) * (b.to - b.from) / (a.to - a.from) }
Line 3,596 ⟶ 3,620:
for (s in a) {
var t = mapRange.call(a, b, s)
var f = Fmt.print(t"$2d >=maps 0)to ?$ h", "s, : ""t)
System.print("%(Fmt.d(2, s)) maps to %(f)%(t)")
}</syntaxhighlight>
 
2,069

edits