Mercurial > hg > ristipolku
annotate game/Interpolate.java @ 111:53d153de5beb
Misc docs.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 06 Apr 2011 21:48:26 +0300 |
parents | 41c6cca69d60 |
children | 4c0dec72e2f0 |
rev | line source |
---|---|
1 | 1 /* |
2 * Class for smooth non-linear interpolation between two given values in N steps | |
3 * (C) Copyright 2011 Matti 'ccr' Hämäläinen <ccr@tnsp.org> | |
4 */ | |
5 package game; | |
6 | |
7 import java.util.*; | |
8 | |
9 public class Interpolate | |
10 { | |
106
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
11 public float start, end, steps; |
1 | 12 |
7 | 13 public Interpolate(float start, float end, float steps) |
1 | 14 { |
15 | 15 this.start = start; |
16 this.end = end; | |
17 this.steps = steps; | |
1 | 18 } |
19 | |
7 | 20 public float getValue(float step) |
1 | 21 { |
15 | 22 float n = step / steps; |
23 float v = n * n * (3.0f - 2.0f * n); | |
24 return (start * v) + (end * (1.0f - v)); | |
1 | 25 } |
26 } |