Map range: Difference between revisions

399 bytes added ,  1 month ago
Added Easylang
(Added Easylang)
 
(4 intermediate revisions by 2 users not shown)
Line 1,088:
=={{header|Craft Basic}}==
<syntaxhighlight lang="basic">define a1 = 0, b1 = 0, a2 = 0, b2 = 0
define fn (maprange) as b1 + ( s - a1 ) * ( b2 - b1 ) / ( a2 - a1 )
 
for i = 0 to 10
Line 1,098 ⟶ 1,097:
let b2 = 0
 
print i, " : ", b1 + (maprange s - a1 ) * ( b2 - b1 ) / ( a2 - a1 )
 
next i</syntaxhighlight>
{{out| Output}}<pre>0 : -1
 
1 : -0.9000
end</syntaxhighlight>
2 : -0.8000
3 : -0.7000
4 : -0.6000
5 : -0.5000
6 : -0.4000
7 : -0.3000
8 : -0.2000
9 : -0.1000
10 : 0</pre>
 
=={{header|D}}==
Line 1,132 ⟶ 1,140:
=={{header|Delphi}}==
See [[#Pascal]].
=={{header|EasyLang}}==
<syntaxhighlight>
func map_range a1 a2 b1 b2 s .
define fn (maprange) asreturn b1 + ( s - a1 ) * ( b2 - b1 ) / ( a2 - a1 )
.
for i = 0 to 10
print i & " -> " & map_range 0 10 -1 0 i
.
end</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,580 ⟶ 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,588 ⟶ 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,063

edits