! Copyright © 2017 Alex Maestas. ! See http://factorcode.org/license.txt for BSD license. USING: accessors byte-arrays combinators.random fry grouping images images.normalization images.png io.encodings.binary io.files kernel locals math math.vectors random sequences sequences.deep sequences.rotated tools.continuations ; IN: pnglitch CONSTANT: bpp 4 ; inline PRIVATE> : ( -- image ) RGBA >>component-order ubyte-components >>component-type ; : imbue ( bitmap dim -- image ) -rot [ B{ } flatten-as >>bitmap ] [ >>dim ] bi* ; : consume ( path -- normalized-image ) binary load-png loading-png>image normalize-image ; ! explode with misalignment :: explode* ( image offset -- bitmap dim ) image bitmap>> offset [ ] unless-zero pixelate image image-dim ; : explode ( image -- bitmap dim ) 0 explode* ; inline : row-clump ( bitmap dim -- bitmap' dim ) [ first ] keep ; : row-group ( bitmap dim -- bitmap' dim ) [ first ] keep ; : jitterbug ( bitmap dim -- bitmap dim ) [ pixelate ] dip row-group [ first 4 / >integer '[ _ random ] map ] keep ;