annotate game/Interpolate.java @ 106:41c6cca69d60

Make new pieces appear gradually, and same effect for swapping.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 03 Mar 2011 21:21:35 +0200
parents 59ff451750fb
children 4c0dec72e2f0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * Class for smooth non-linear interpolation between two given values in N steps
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * (C) Copyright 2011 Matti 'ccr' Hämäläinen <ccr@tnsp.org>
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 */
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 package game;
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 import java.util.*;
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 public class Interpolate
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
13 public Interpolate(float start, float end, float steps)
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 {
15
59ff451750fb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
15 this.start = start;
59ff451750fb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
16 this.end = end;
59ff451750fb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
17 this.steps = steps;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 }
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
20 public float getValue(float step)
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 {
15
59ff451750fb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
22 float n = step / steps;
59ff451750fb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
23 float v = n * n * (3.0f - 2.0f * n);
59ff451750fb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
24 return (start * v) + (end * (1.0f - v));
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 }
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 }