Files
processing4/mobile/web/reference/API/lerp.xml
2005-01-27 06:48:42 +00:00

87 lines
1.6 KiB
XML

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<name>lerp()</name>
<category>Math</category>
<subcategory>Calculation</subcategory>
<usage>Web &amp; Application</usage>
<example>
<image>lerp_.gif</image>
<code>
float a = 20;
float b = 80;
float c = lerp(a, b, .2);
float d = lerp(a, b, .5);
float e = lerp(a, b, .8);
beginShape(POINTS);
vertex(a, 50);
vertex(b, 50);
vertex(c, 50);
vertex(d, 50);
vertex(e, 50);
endShape();
</code>
</example>
<example>
<image>lerp_2.gif</image>
<code>
int x1 = 15;
int y1 = 10;
int x2 = 80;
int y2 = 90;
line(x1, y1, x2, y2);
for(int i=0; i&lt;=10; i++) {
float x = lerp(x1, x2, i/10.0) + 10;
float y = lerp(y1, y2, i/10.0);
point(x, y);
}
</code>
</example>
<description>
Calculates a number between two numbers at a specific increment. The <b>amt</b> parameter is the amount to interpolate between the two values where 0.0 equal to the first point, 0.1 is very near the first point, 0.5 is half-way in between, etc. The lerp function is convenient for creating motion along a strait path and for drawing dotted lines.
</description>
<syntax>
lerp(<c>value1</c>, <c>value2</c>, <c>amt</c>)
</syntax>
<parameter>
<label>value1</label>
<description>float or int: first value</description>
</parameter>
<parameter>
<label>value2</label>
<description>float or int: second value</description>
</parameter>
<parameter>
<label>amt</label>
<description>float: between 0.0 and 1.0</description>
</parameter>
<returns>float</returns>
<related>
curvePoint()
bezierPoint()
</related>
<availability>1.0</availability>
<type>Function</type>
<partof>Core</partof>
<level>Extended</level>
</root>