Yup, so just run mix run image.exs
on this sucker. You'll have to open the image manually if you're on a mac, and hey, storing it in my home dir might not work either :)
Last active
August 29, 2015 14:04
-
-
Save knewter/36efdb12a6b066cdecd3 to your computer and use it in GitHub Desktop.
This file contains 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
defmodule Image do | |
@pixel_size 1 | |
@pixel_count 255*255*255 | |
@width 800 | |
@height 800 | |
@num_shades 50 | |
@colors for r <- 0..@num_shades, | |
g <- 0..@num_shades, | |
b <- 0..@num_shades, | |
do: {r, g, b} | |
@num_colors Enum.count(@colors) | |
@pixel_positions for x <- 0..@width, | |
y <- 0..@height, | |
do: [x, y] | |
def run do | |
image = :egd.create(@width, @height) | |
red = :egd.color({255, 0, 0}) | |
for [x, y] <- @pixel_positions do | |
:egd.filledRectangle(image, {x, y}, {x, y}, :egd.color(Enum.at(@colors, x+y))) | |
""" | |
:egd.filledRectangle(image, {x, y}, {x, y}, :egd.color({ | |
:crypto.rand_uniform(0, 255), | |
:crypto.rand_uniform(0, 255), | |
:crypto.rand_uniform(0, 255) | |
})) | |
""" | |
end | |
:egd.save(:egd.render(image, :png), '/home/jadams/tmp/test.png') | |
end | |
end | |
Image.run | |
System.cmd("gnome-open ~/tmp/test.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment