This is a simple port of https://github.com/sug0/go-glitch to rust.
You can think of the image as a functor that you map an expression to, for each pixel's component colors, returning a new one. The allowed operators are:
ta pixel made up of a random color component from the neighboring 16 pixelsga pixel made up of a random color component from random locations in the imager{Num}a pixel made up of a random color component from the neighboringNumpixelsR{Num}the red color component defined byNum(i.e.R255is the same asR)G{Num}the green color component defined byNum(i.e.G255is the same asG)B{Num}the blue color component defined byNum(i.e.B255is the same asB)iinverts the color componentb{Num}the brightness of the color component defined byNum(i.e.b255is the same asb)
+plus-minus*multiplication/division%modulo#power of operator&bit and|bit or:bit and not^bit xor<bit left shift>bit right shift?returns 255 if left side is greater otherwise 0@attributes a weight in the range[0, 255]to the value on the left
The expressions are made up of operators, numbers, parenthesis, and a set of parameters:
cthe current value of each pixel component colorbthe blurred version ofchthe horizontally flipped version ofcvthe vertically flipped version ofcdthe diagonally flipped version ofcYthe luminosity, or grayscale component of each pixelNa noise pixel (i.e. a pixel where each component is a random value)Rthe red color (i.e. rgb(255, 0, 0))Gthe green color (i.e. rgb(0, 255, 0))Bthe blue color (i.e. rgb(0, 0, 255))sthe value of each pixel's last saved evaluated expressionra pixel made up of a random color component from the neighboring 8 pixelsethe difference of all pixels in a box, creating an edge-like effectxthe current x coordinate being evaluated normalized in the range[0, 255]ythe current y coordinate being evaluated normalized in the range[0, 255]Hthe highest valued color component in the neighboring 8 pixelsLthe lowest valued color component in the neighboring 8 pixels
128 & (c - ((c - 150 + s) > 5 < s))(c & (c ^ 55)) + 25128 & (c + 255) : (s ^ (c ^ 255)) + 25