Skip to content

Instantly share code, notes, and snippets.

@rhwlo
Last active August 29, 2015 14:10
Show Gist options
  • Save rhwlo/51dcdaedb3decb51c84a to your computer and use it in GitHub Desktop.
Save rhwlo/51dcdaedb3decb51c84a to your computer and use it in GitHub Desktop.
It doesn’t mean anything.
-- just for fun
-- compiled and uploaded to http://rhwlo.com/dancingPixels
import Bitwise as B
type ColorGrid = [[Color]]
actualWidth = 300
drawGrid : ColorGrid -> Element
drawGrid grid = let gridWidth = (length grid)
cellSize = actualWidth / (toFloat gridWidth)
xOffset = -(actualWidth - cellSize) / 2
yOffset = (actualWidth - cellSize) / 2 in
collage actualWidth actualWidth ((zip grid [0..(gridWidth - 1)]) |> map (\row ->
(zip (fst row) [0..(gridWidth - 1)]) |> map (\column ->
let squareSize = actualWidth / (toFloat gridWidth)
x = xOffset + (toFloat (snd column)) * cellSize
y = yOffset - (toFloat (snd row)) * cellSize
thisColor = (fst column)
in
square (squareSize + 1)
|> filled thisColor
|> move (x, y)
)
) |> foldr (++) [])
-- this is a function that is arbitrary and only as meaningful as you want it to be
f : Int -> Int
f x = (floor ((toFloat x) ^ pi)) `B.xor` (x ^ x) % 512
makeColors : Int -> Color -> Color
makeColors x col = let colorShift = (x // 4)
applyShift = (x % 4)
colRgb = toRgb col in
if | applyShift == 1 -> rgb ((colRgb.red + colorShift) % 256) colRgb.green colRgb.blue
| applyShift == 2 -> rgb colRgb.red ((colRgb.green + colorShift) % 256) colRgb.blue
| applyShift == 3 -> rgb colRgb.red colRgb.green ((colRgb.blue + colorShift) % 256)
| otherwise -> col
g : Int -> Int -> Int
-- g x y = (f x) `B.xor` (f y)
g _ y = f y
primes : [Int]
primes = [11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73]
primeGrid : [[Int]]
primeGrid = map (\x -> tail <| scanl g x primes) (tail primes)
initialGrid : ColorGrid
initialGrid = primeGrid |> map (\row -> tail (row |> scanl makeColors white))
foldGrid : ColorGrid -> ColorGrid
foldGrid grid = (zip primeGrid grid) |> map (\row ->
let numRow = (fst row)
colorRow = (snd row)
in
(zip numRow colorRow) |> map (\col ->
let numCol = (fst col)
colorCol = (snd col) in
makeColors numCol colorCol))
main : Signal Element
main = drawGrid <~ (foldp (\time -> foldGrid) initialGrid (every <| 200 * millisecond))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment