Created
January 9, 2013 01:43
-
-
Save aligo/4489856 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
#= require jquery/jquery | |
#= require biginteger/biginteger | |
#= require_self | |
jQuery -> | |
# configure | |
design = | |
width: 10 | |
height: 10 | |
color_depth = 16 | |
# count | |
pixels_count = design.width * design.height | |
all_colors_count = new BigInteger Math.pow(color_depth, 3) | |
all_images_count = all_colors_count.pow pixels_count | |
pixel_no_to_position = (pixel_no) -> | |
x = Math.floor pixel_no / design.width | |
y = pixel_no % design.height | |
[x, y] | |
pixel_to_rgb = (pixel) -> | |
pixel_remain = [pixel].shift() | |
color_base = color_depth | |
rgb = [] | |
color_shift = color_depth / 2 | |
for channel_no in [0..2] | |
color = pixel_remain % color_depth | |
pixel_remain = (pixel_remain - color) / color_depth | |
rgb.push color * 256 / color_depth + color_shift / 2 | |
rgb | |
# example seed | |
# image_seed = new BigInteger 0 | |
image_seed = [all_images_count].shift().subtract 1 | |
# print loop | |
seed_remain = [image_seed].shift() | |
print_base = [all_colors_count].shift() | |
for pixel_no in [0..(pixels_count-1)] | |
la_pixel = seed_remain.remainder print_base | |
seed_remain = seed_remain.subtract(la_pixel).divide all_colors_count | |
console.log 'print (' + pixel_no_to_position(pixel_no) + ') to ' + pixel_to_rgb(la_pixel) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment