In this very short episode of the Hooray! Trip Log series, we review four patches that tweak some constants, all in order to try to improve our standing in the checklist. Not that the checklist is so important, but anyway the process is. (Or at least, it seems important to demonstrate.)
1 commit 09dddc33d6e6f04b6230f769feef5b6f6fa8c245 2 Author: Thien-Thi Nguyen <ttn@gnuvola.org> 3 Date: 2022-02-05 07:07:49 -0500 4 5 Tweak initial position 6 7 * hooray.scm (hooray! random-c): 8 Reduce dispersal by about half. 9 --- 10 hooray.scm | 2 +- 11 1 file changed, 1 insertion(+), 1 deletion(-) 12 13 diff --git a/hooray.scm b/hooray.scm 14 index e4a8ae8..356bc93 100644 15 --- a/hooray.scm 16 +++ b/hooray.scm 17 @@ -233,7 +233,7 @@ (define hooray! 18 (/2 FG-EDGE-LENGTH))))) 19 ;; rv 20 (lambda () 21 - (+ origin (random 29) -14)))) 22 + (+ origin (random 9) -4)))) 23 24 (define (random-v bias) 25 ;; rv
Line 8 says it all. The result is a tighter clustering at the beginning, so that the sprite seems to originate from the top of the center tile.
1 commit 52cbbbb2d8c7d51eea13d8823f33eaafe9cad1e6
2 Author: Thien-Thi Nguyen <ttn@gnuvola.org>
3 Date: 2022-02-05 07:15:06 -0500
4
5 Tweak initial velocity
6
7 * hooray.scm (hooray! random-v):
8 Reduce dispersal by about 20 percent.
9 (hooray!): Reduce range of ‘vy
’ by about 20 percent,
10 but increase its negative bias by 30 percent.
11 ---
12 hooray.scm | 4 ++--
13 1 file changed, 2 insertions(+), 2 deletions(-)
14
15 diff --git a/hooray.scm b/hooray.scm
16 index 356bc93..dc6cdbb 100644
17 --- a/hooray.scm
18 +++ b/hooray.scm
19 @@ -238,7 +238,7 @@ (define hooray!
20 (define (random-v bias)
21 ;; rv
22 (lambda ()
23 - (+ (random 9) -4 bias)))
24 + (+ (random 7) -3 bias)))
25
26 (define (random-gravity)
27 (random 0.420))
28 @@ -276,7 +276,7 @@ (define hooray!
29 (array-map! x (random-c +))
30 (array-map! y (random-c -))
31 (array-map! vx (random-v 0))
32 - (array-map! vy (random-v (random -4.20)))
33 + (array-map! vy (random-v (- (random -3.33) 1.23)))
34 (array-map! gravity random-gravity)
35 (array-for-each
36 (lambda (fg w/2 h/2 dst)
Again, the description (lines 8-10) is accurate enough to leave alone. The result is less randomness (both horizontal and vertical) but more bias upwards (vertical direction only).
1 commit b5d897cf934f37b46e59e57932056b418521bf89 2 Author: Thien-Thi Nguyen <ttn@gnuvola.org> 3 Date: 2022-02-05 07:18:09 -0500 4 5 Tweak gravity 6 7 * hooray.scm (hooray! random-gravity): 8 Reduce range by about half. 9 --- 10 hooray.scm | 2 +- 11 1 file changed, 1 insertion(+), 1 deletion(-) 12 13 diff --git a/hooray.scm b/hooray.scm 14 index dc6cdbb..6072498 100644 15 --- a/hooray.scm 16 +++ b/hooray.scm 17 @@ -241,7 +241,7 @@ (define hooray! 18 (+ (random 7) -3 bias))) 19 20 (define (random-gravity) 21 - (random 0.420)) 22 + (random 0.222)) 23 24 (define (bump! orig delta) 25 (array-map! orig + orig delta))
Woo hoo, line 8 to the fore, again! The result is that the sprite “floats” a bit more than before.
1 commit fd1a362ff80cfddfe01c82fdd3475754e84820a0 2 Author: Thien-Thi Nguyen <ttn@gnuvola.org> 3 Date: 2022-02-05 07:22:38 -0500 4 5 Tweak growth 6 7 * hooray.scm (hooray! fg-step s-curve): New proc. 8 (hooray! fg-step shift-up): New proc. 9 (hooray! size/rotate!): Use ‘s-curve
’, ‘shift-up
’. 10 --- 11 hooray.scm | 12 +++++++++++- 12 1 file changed, 11 insertions(+), 1 deletion(-) 13 14 diff --git a/hooray.scm b/hooray.scm 15 index 6072498..55f6317 100644 16 --- a/hooray.scm 17 +++ b/hooray.scm 18 @@ -208,10 +208,20 @@ (define hooray! 19 (imfi-sub-c surface surface c) 20 surface)) 21 22 + (define (s-curve x) 23 + (define beta (exp 0.8)) 24 + (/ 1.0 25 + (+ 1.0 (expt (/ x 26 + (- 1.0 x)) 27 + (- beta))))) 28 + 29 + (define (shift-up x) 30 + (+ 0.1 (* 0.9 x))) 31 + 32 (define (size/rotate! surface) 33 (roto-zoom-surface surface 34 (+ 21.5 (* -42.0 fraction)) 35 - (* 4.20 fraction) 36 + (* 4.20 (shift-up (s-curve fraction))) 37 #t)) 38 39 (dim! (size/rotate! put)))
This patch actually does more than tweak a constant, but it still has tweak nature, so we include it in this grouping. In it, we swap out the linear growth function (line 35), for a shifted-up (lines 29-30) S-curve (lines 22-27) function. Here's what it looks like, in a plot:
Note that the domain and range in the plot are both ‘[0,1]
’; it shows a
cumulative distribution function
(I think).
The result is that the sprite grows very quickly (high slope) in the middle and more slowly at the beginning and end.
This produces a nice (IMHO) “pop” effect that is both interesting and easy to see.
So, let's update the checklist now.
* PipeWalker fg behavior (to reproduce if possible) - [X] starts near top of center tile - [X] mostly upward velocity - [X] rotates clockwise slightly - [X] starts smaller than 32x32 - [X] grows quickly - [ ] non synchronized (all aspects) - [x] fades to transparent
We've graduated from small “x” to big “X” for “mostly upward velocity” and “grows quickly”. Cool! I'll end this episode by pointing people to the Guile-SDL 0.6.0 release announcement and urging people to try it out, especially those who want to follow along w/ the penultimate episode, Part 11, coming Real Soon Now.
Copyright (C) 2022 Thien-Thi Nguyen