11// java
22package examples ;
33
4+ import java .util .Random ;
45import org .codejive .twinkle .ansi .Ansi ;
56import org .codejive .twinkle .core .text .Line ;
67import org .codejive .twinkle .core .widget .Panel ;
@@ -16,6 +17,28 @@ public static void main(String[] args) throws InterruptedException {
1617
1718 System .out .print (Ansi .hideCursor ());
1819 try {
20+ // random generator and mutable parameter bases/variations
21+ Random rng = new Random ();
22+ double a1Base , a2Base , a1Var , a2Var ;
23+ double k1Base , k2Base , k1Var , k2Var ;
24+ double speed1 , speed2 ;
25+
26+ a1Base = 0.5 + rng .nextDouble () * 0.7 ; // 0.5 .. 1.2
27+ a1Var = 0.2 + rng .nextDouble () * 0.6 ; // 0.2 .. 0.8
28+ a2Base = 0.3 + rng .nextDouble () * 0.6 ; // 0.3 .. 0.9
29+ a2Var = 0.1 + rng .nextDouble () * 0.5 ; // 0.1 .. 0.6
30+
31+ k1Base = 0.8 + rng .nextDouble () * 1.2 ; // 0.8 .. 2.0
32+ k1Var = 0.2 + rng .nextDouble () * 1.05 ; // 0.2 .. 1.2
33+ k2Base = 1.5 + rng .nextDouble () * 1.5 ; // 1.5 .. 3.0
34+ k2Var = 0.3 + rng .nextDouble () * 1.2 ; // 0.3 .. 1.5
35+
36+ speed1 = 0.6 + rng .nextDouble () * 1.6 ; // 0.6 .. 2.2
37+ speed2 = 0.3 + rng .nextDouble () * 1.1 ; // 0.3 .. 1.4
38+ if (Math .abs (speed1 - speed2 ) < 0.3 ) {
39+ speed2 += 0.4 ; // ensure noticeable difference
40+ }
41+
1942 for (int i = 0 ; i < 400 ; i ++) {
2043 if (i > 0 ) {
2144 System .out .print (Ansi .cursorMove (Ansi .CURSOR_PREV_LINE , 22 ));
@@ -25,17 +48,15 @@ public static void main(String[] args) throws InterruptedException {
2548 // time parameter
2649 double t = i * 0.08 ;
2750
28- // amplitudes vary slowly
29- double a1 = 0.8 + 0.4 * Math .sin (t * 0.7 );
30- double a2 = 0.6 + 0.3 * Math .cos (t * 0.5 );
51+ // amplitudes vary slowly around randomized bases
52+ double a1 = a1Base + a1Var * Math .sin (t * 0.7 );
53+ double a2 = a2Base + a2Var * Math .cos (t * 0.5 );
3154
32- // spatial frequencies (strides) vary with time
33- double k1 = 1.0 + 0.6 * Math .sin (t * 0.4 );
34- double k2 = 2.0 + 0.9 * Math .cos (t * 0.3 );
55+ // spatial frequencies (strides) vary with time around randomized bases
56+ double k1 = k1Base + k1Var * Math .sin (t * 0.4 );
57+ double k2 = k2Base + k2Var * Math .cos (t * 0.3 );
3558
36- // phases to make waves drift from right to left at differing speeds
37- double speed1 = 1.2 ; // faster wave
38- double speed2 = 0.6 ; // slower wave
59+ // phases to make waves drift from right to left at differing speeds (positive)
3960 double phase1 = t * speed1 ;
4061 double phase2 = t * speed2 ;
4162
0 commit comments