####
#  to run use
#    $ ruby preview/orangepixels.rb

require 'ordgen'




module Pixelart

class Image

  ## neon glow special effect
  def neon( color )
     ## find color - assume 1-bit (one color only)
     colors = pixels.uniq.sort    ## let 0 (transparent go first)

     if colors.size != 2 && colors[0] != 0
       puts "!! ERROR - 1-bit image expected; got #{colors.inspect}"
       exit 1
     end

    foreground = colors[1]


    ## transparent & white
    inverse1 = change_colors( {
              foreground => 'ffffff',  ## 1-bit color to white
            })

    ## transparent & color
    inverse2 = change_colors( {
                foreground => color,  ##  1-bit color to color
           })

####
# inspired by
#   https://css-tricks.com/how-to-create-neon-text-with-css/
#
# .neonText {
#    color: #fff;
#    text-shadow:
#      // white glow
#       0 0 7px #fff,
#       0 0 10px #fff,
#       0 0 21px #fff,
#      // green glow
#       0 0 42px #0fa,
#       0 0 82px #0fa,
#       0 0 92px #0fa,
#       0 0 102px #0fa,
#       0 0 151px #0fa;

    base = Image.new( width, height, Color::BLACK )
    base.compose!( inverse2.blur( 12 ) )  # -blur 21x21
    base.compose!( inverse2.blur( 6 ) )  # -blur 10x10
    base.compose!( inverse2.blur( 4 ) )   # -blur 7x7

    base.compose!( inverse1.blur( 2 ) )   # -blur 2x2
    base.compose!( inverse1 )
    base
  end
end # class Image
end # module Pixelart





## step 1 - read (local) spritesheet.png ("art layers")
orangepixels  =  Ordgen.read( './orangepixels/spritesheet.png',
                                          width: 24,
                                          height: 24 )


specs = [
  ## ordinal punk no. 1
  [128, 129, 130, 131, 132, 133, 134, 151, 159, 174, 184, 198, 208, 222, 232, 246, 256, 270, 272, 273, 274, 275, 276, 277, 278, 279, 280, 293, 294, 296, 297, 299, 300, 301, 303, 304, 316, 317, 320, 321, 322, 323, 324, 325, 326, 327, 328, 341, 342, 344, 345, 346, 347, 350, 351, 352, 366, 376, 390, 393, 394, 395, 396, 397, 398, 399, 400, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 437, 438, 439, 440, 441, 442, 446, 447, 448, 449, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, 521, 534, 536, 537, 538, 539, 540, 541, 542, 543, 544, 558, 562, 563, 564, 565, 566, 567],
  ## smile face
  [55, 56, 57, 58, 59, 77, 78, 84, 85, 100, 101, 109, 110, 123, 134, 146, 147, 150, 155, 158, 159, 170, 183, 194, 207, 208, 218, 225, 232, 242, 253, 256, 266, 270, 276, 277, 280, 290, 294, 300, 304, 314, 319, 320, 321, 322, 323, 328, 339, 352, 363, 364, 375, 376, 388, 389, 390, 399, 415, 416, 417, 421, 422, 441, 442, 443, 444],
  ## knight
  [100, 102, 104, 124, 125, 126, 127, 128, 148, 149, 150, 151, 152, 156, 157, 158, 159, 160, 172, 174, 176, 180, 181, 182, 183, 184, 198, 204, 208, 222, 226, 228, 229, 231, 232, 234, 246, 249, 250, 252, 253, 255, 256, 258, 259, 270, 273, 274, 276, 277, 278, 279, 280, 282, 283, 294, 297, 298, 306, 307, 317, 318, 319, 322, 323, 324, 325, 326, 327, 328, 329, 330, 341, 342, 343, 344, 346, 347, 348, 349, 350, 351, 352, 353, 354, 356, 365, 366, 367, 368, 371, 372, 373, 374, 375, 376, 377, 380, 390, 403, 404, 419, 420, 421, 422, 423, 424, 425, 427, 428, 443, 444, 445, 446, 447, 448, 449, 467, 468, 469, 471, 472, 473, 491, 492, 493, 495, 496, 497, 515, 516, 517, 519, 520, 521],
  ## frog
  [178, 179, 180, 182, 183, 184, 201, 205, 206, 209, 224, 225, 226, 228, 229, 230, 231, 233, 248, 249, 250, 252, 253, 254, 255, 257, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 295, 296, 297, 307, 319, 320, 322, 323, 324, 325, 326, 327, 328, 329, 331, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 366, 369, 370, 371, 372, 373, 374, 375, 376, 377, 389, 390, 391, 392, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 440, 441, 443, 445, 462, 463, 467, 469, 485, 486, 487, 488, 489, 492, 494],
  ## bitcoin money bag
  [128, 129, 130, 131, 132, 133, 134, 151, 159, 176, 182, 201, 202, 203, 204, 205, 224, 228, 230, 247, 252, 255, 270, 274, 280, 293, 296, 297, 298, 299, 305, 316, 321, 324, 330, 340, 345, 346, 347, 354, 364, 369, 372, 375, 378, 389, 392, 393, 394, 395, 398, 401, 414, 418, 424, 439, 447, 464, 465, 466, 467, 468, 469, 470],
  ## coffee
  [109, 134, 154, 155, 158, 177, 180, 181, 201, 226, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 330, 331, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 354, 355, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 378, 379, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 402, 403, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 426, 427, 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 487, 488, 489, 490, 491, 492, 493, 494],


  ## ???
  [115, 116, 117, 128, 129, 130, 131, 132, 133, 134, 139, 141, 151, 159, 163, 165, 174, 184, 187, 188, 189, 198, 208, 211, 213, 222, 232, 235, 237, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 259, 260, 261, 270, 271, 281, 283, 285, 293, 295, 297, 302, 305, 307, 309, 317, 319, 324, 329, 331, 332, 333, 342, 343, 347, 349, 353, 355, 357, 366, 368, 369, 370, 372, 374, 375, 376, 379, 381, 390, 400, 403, 404, 405, 414, 424, 427, 429, 438, 443, 444, 445, 446, 448, 450, 453, 462, 468, 471, 472, 473, 476, 486, 493, 499, 510, 514, 515, 516, 517, 518, 519, 520, 521, 522, 534, 538, 558, 562],

    [57, 58, 59, 60, 61, 80, 86, 103, 111, 127, 133, 135, 138, 139, 140, 141, 151, 153, 155, 157, 158, 159, 160, 161, 163, 165, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 182, 184, 186, 188, 189, 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 212, 217, 218, 220, 222, 224, 226, 228, 230, 231, 232, 233, 234, 235, 242, 243, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 268, 269, 270, 271, 280, 294, 295, 297, 298, 301, 302, 304, 318, 319, 321, 325, 328, 342, 343, 352, 367, 376, 391, 392, 395, 397, 400, 415, 416, 417, 423, 424, 439, 440, 443, 444, 445, 448, 464, 465, 471, 488, 489, 490, 494, 512, 513, 514, 515, 516, 517, 536, 537, 538, 539, 540, 560, 561, 562, 563, 564],
  ## more
  [128, 129, 130, 131, 132, 133, 134, 151, 159, 174, 177, 178, 179, 180, 181, 182, 184, 198, 200, 207, 208, 222, 223, 232, 246, 256, 270, 272, 273, 274, 278, 279, 280, 293, 296, 297, 298, 302, 303, 304, 317, 320, 321, 322, 326, 327, 328, 342, 352, 366, 376, 390, 391, 400, 414, 415, 420, 424, 438, 440, 444, 447, 448, 462, 465, 466, 470, 472, 486, 491, 492, 493, 495, 510, 514, 515, 516, 517, 518, 534, 538, 558, 562],
]


specs = [
  [129, 133, 150, 151, 153, 154, 155, 156, 157, 159, 175, 176, 177, 178, 179, 180, 181, 182, 200, 201, 202, 203, 204, 206, 225, 227, 228, 229, 230, 231, 249, 250, 251, 252, 253, 254, 256, 257, 273, 274, 275, 276, 277, 279, 280, 281, 282, 298, 299, 300, 301, 303, 305, 307, 321, 322, 323, 324, 327, 328, 329, 330, 331, 345, 347, 348, 369, 370, 371, 372, 392, 393, 394, 395, 414, 415, 416, 417, 419, 420, 437, 438, 440, 441, 442, 443, 444, 460, 462, 463, 464, 466, 468, 486, 488, 490, 492],
  [129, 133, 150, 151, 153, 154, 155, 156, 157, 159, 175, 176, 177, 178, 179, 180, 181, 182, 200, 201, 202, 203, 204, 206, 225, 227, 228, 229, 230, 231, 249, 250, 251, 252, 253, 254, 256, 257, 273, 274, 275, 276, 277, 279, 280, 281, 282, 298, 299, 300, 301, 303, 305, 307, 321, 322, 323, 324, 327, 328, 329, 330, 331, 345, 347, 348, 369, 370, 371, 372, 392, 393, 394, 395, 414, 415, 416, 417, 419, 420, 437, 438, 440, 441, 442, 443, 444, 460, 462, 463, 464, 466, 468, 486, 488, 490, 492],
  [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
  11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
  21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
  31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
  41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
  51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
  61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
  71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
  81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
  91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
  101, 102, 103, 104, 105, 106, 107, 108, 109, 110,
  111, 112, 113, 114, 115, 116, 117, 118, 119, 120,
  121, 122, 123, 124, 125, 126, 127, 128, 129, 130,
  131, 132, 133, 134, 135, 136, 137, 138, 139, 140,
  141, 142, 143, 144, 145, 146, 147, 148, 149, 161,
  162, 163, 164, 165, 166, 167, 168, 169, 170, 171,
  172, 186, 187, 188, 189, 190, 191, 192, 193, 194,
  195, 196, 210, 211, 212, 213, 214, 215, 216, 217,
  225, 226, 227, 231, 232, 237, 238, 239, 240, 241,
  244, 245, 246, 249, 250, 251, 252, 253, 254, 255,
  256, 258, 259, 261, 262, 263, 264, 265, 268, 269,
  270, 273, 274, 276, 277, 278, 280, 282, 283, 285,
  286, 287, 288, 289, 292, 293, 294, 297, 298, 300,
  301, 302, 304, 309, 310, 311, 312, 313, 316, 317,
  318, 321, 322, 323, 324, 325, 326, 327, 328, 329,
  331, 333, 334, 335, 336, 337, 345, 346, 347, 349,
  350, 351, 352, 353, 357, 358, 359, 360, 361, 362,
  363, 364, 369, 370, 371, 372, 379, 380, 381, 382,
  383, 384, 385, 386, 387, 388, 394, 395, 396, 397,
  398, 399, 400, 402, 403, 404, 405, 406, 407, 408,
  409, 410, 411, 412, 413, 425, 426, 427, 428, 429,
  430, 431, 432, 433, 434, 435, 436, 437, 438, 439,
  440, 441, 442, 443, 444, 445, 446, 447, 448, 449,
  450, 451, 452, 453, 454, 455, 456, 457, 458, 459,
  460, 461, 462, 463, 464, 465, 466, 467, 468, 469,
  470, 471, 472, 473, 474, 475, 476, 477, 478, 479,
  480, 481, 482, 483, 484, 485, 486, 487, 488, 489,
  490, 491, 492, 493, 494, 495, 496, 497, 498, 499,
  500, 501, 502, 503, 504, 505, 506, 507, 508, 509,
  510, 511, 512, 513, 514, 515, 516, 517, 518, 519,
  520, 521, 522, 523, 524, 525, 526, 527, 528, 529,
  530, 531, 532, 533, 534, 535, 536, 537, 538, 539]
]



specs.each do |attributes|
  puts "==> orange #{attributes.inspect}"
  img = orangepixels.generate( *attributes )

  ## note: use first five numbers and add pix(el) count
  path = "./preview/tmp3/orange-#{attributes[0,5].join('_')}-pix#{attributes.count}"
  img.save( path+'.png' )
  img.zoom(4).save( path+'@4x.png' )

=begin
  neon = img.neon( 'ff9900' )    ## bitcoin orange
  neon.save( path+'_neon.png' )
  neon.zoom(4).save( path+'_neon@4x.png' )
  neon.zoom(8).save( path+'_neon@8x.png' )

  neon = img.neon( '00ff00' )    ## fed green
  neon.save( path+'_neon-green.png' )
  neon.zoom(4).save( path+'_neon-green@4x.png' )
  neon.zoom(8).save( path+'_neon-green@8x.png' )
=end
end


puts "bye"

