Created
August 31, 2024 12:04
-
-
Save artyom-poptsov/72fe27b7441f984262c99ee2b27082a8 to your computer and use it in GitHub Desktop.
Another Guile-PNG generative art.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env -S guile -L modules -e main -s | |
!# | |
(use-modules (rnrs bytevectors) | |
(png) | |
(png image) | |
(png graphics pixel)) | |
(define (main args) | |
(let* ((image (png->scm (current-input-port))) | |
(image-height (png-image-height image))) | |
(set! *random-state* (random-state-from-platform)) | |
(for-each | |
(lambda (column-index) | |
(for-each (lambda (row-index) | |
(let* ((pixel (png-image-pixel-ref image | |
column-index | |
row-index)) | |
(red (bytevector-u8-ref pixel 0)) | |
(green (bytevector-u8-ref pixel 1)) | |
(blue (bytevector-u8-ref pixel 2)) | |
(gen-color | |
(lambda (color) | |
(euclidean-remainder (+ (abs (- 255 color)) | |
(random (+ row-index 1))) | |
255)))) | |
(bytevector-u8-set! pixel 0 (gen-color red)) | |
(bytevector-u8-set! pixel 1 (gen-color green)) | |
(bytevector-u8-set! pixel 2 (gen-color blue)) | |
(png-image-pixel-set! image column-index row-index pixel))) | |
(iota (random image-height)))) | |
(iota (- (png-image-width image) 1))) | |
(scm->png image))) |
Author
artyom-poptsov
commented
Aug 31, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment