Monorepo for Aesthetic.Computer
aesthetic.computer
1;;; pixels.lisp — Animated pixel noise with color drift
2
3(defpackage :piece.pixels
4 (:use :cl))
5(in-package :piece.pixels)
6
7(defvar *frame* 0)
8(defvar *rng* (make-random-state t))
9
10(defun paint (graph screen-w screen-h audio)
11 "Paint one frame of pixel noise."
12 (incf *frame*)
13 ;; Don't wipe — let pixels accumulate and drift
14 (let* ((density (+ 50 (round (* 200 (abs (sin (/ *frame* 120.0)))))))
15 (hue-base (mod (* *frame* 2) 360)))
16 (dotimes (i density)
17 (let* ((x (random screen-w *rng*))
18 (y (random screen-h *rng*))
19 (hue (mod (+ hue-base (random 60 *rng*)) 360))
20 (r (min 255 (max 0 (round (* 255 (max 0 (sin (* hue 0.0174))))))))
21 (g (min 255 (max 0 (round (* 255 (max 0 (sin (* (+ hue 120) 0.0174))))))))
22 (b (min 255 (max 0 (round (* 255 (max 0 (sin (* (+ hue 240) 0.0174)))))))))
23 (ac-native.graph:graph-ink graph
24 (ac-native.color:make-color :r r :g g :b b :a 255))
25 (ac-native.graph:graph-plot graph x y)))
26 ;; Sonify: tone based on average hue
27 (when (and audio (zerop (mod *frame* 15)))
28 (let ((freq (+ 100 (* 3 hue-base))))
29 (ac-native.audio:audio-synth audio 0 freq 0.04 0.2 0.002 0.04 0.0)))))