parent 30a3e34b
#lang racket
#;(define (render-stars stars)
(require "braille-rast.rkt"
(prefix-in raart: raart))
;; Periods make perfectly fine starfields, it appears...
......@@ -13,24 +15,128 @@
;; Hm, only for the intro. It won't work for the game because what
;; will make the stars look nice is that they move at a different
;; speed that doesn't look like the objects I think
;; speed that doesn't look like the objects I think.
;; What we really ought to use is the unicode braille characters.
;; So that's what we do.
;; Note that this makes the wireworld proposal of using periods messier.
;; This may mean that we should move to something else like single/double
;; quotes, like so:
;; ''' "'
;; ' '
;; '@*''
(struct star (x y relative-speed on? blink-time))
(define (^starfield bcom width height
#:till-spawn-min [till-spawn-min 0.3]
#:till-spawn-max [till-spawn-max 2.4])
(define-cell stars
;; ''' ''
;; ' '
;; '@*''
(define (oob? x)
(<= x 0))
#;(struct star (speed distance on? blink-time))
(define (new-blink-on-time)
(* (random 1 100) .1))
(define (new-blink-off-time)
(* (random 2 400) .1))
#;(define (^starfield bcom width height)
(define (next stars)
(define (make-new-star initial-distance)
(define y
(random 0 height))
(define relative-speed
(+ (* (- (random 1 15) 10) .1) 1.0))
(define on?
(zero? (random 4)))
(define blink-time
(if on?
(star (- width initial-distance) y
relative-speed on? blink-time))
(define (new-till-spawn)
(random 3 15))
(define (next till-spawn stars)
(for/fold ([new-stars (set)])
([star stars])
[(advance speed)
;; we don't advance
[(zero? speed)
(define base-distance
(/ 1.0 speed))
(define new-stars
(for/fold ([new-stars (set)])
([this-star stars])
(define star-distance
(* base-distance (star-relative-speed this-star)))
(define new-x
(- (star-x this-star) star-distance))
;; drop this star
[(oob? new-x)
;; Otherwise, we'll add it back having updated some
;; properties
(define blink-time
(- (star-blink-time this-star) star-distance))
(define on?
(star-on? this-star))
(when (<= blink-time 0)
(set! blink-time
(if on?
(set! on? (not on?)))
(define new-star
(struct-copy star this-star
[x new-x]
[on? on?]
[blink-time blink-time]))
(set-add new-stars new-star)])))
(define next-till-spawn
(- till-spawn base-distance))
(when (<= next-till-spawn 0)
(set! new-stars (set-add new-stars (make-new-star base-distance)))
(set! next-till-spawn (new-till-spawn)))
(bcom (next next-till-spawn new-stars))])]
(define grid
(make-vector height #f))
(for ([i height])
(vector-set! grid i (make-vector width #f)))
(for ([star stars])
(define y (star-y star))
(define x
(inexact->exact (floor (star-x star))))
(vector-set! (vector-ref grid (star-y star))
x 'SS))
(define braille-lines
(brailleify-grid/list grid))
(map raart:text braille-lines))]))
(next (new-till-spawn) (set)))
(define (prime-starfield starfield width)
(for ([i (* width 5)])
($ starfield 'advance 1.0)))
(module+ main
(define am
(define starfield
(actormap-spawn! am ^starfield 100 45))
am (λ () (prime-starfield starfield 30)))
(raart:draw-here (actormap-peek am starfield 'render))
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment