RootOfTheNull

Python Challenge! 14

Jan 26th, 2015
343
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Image
  2.  
  3. img = Image.new( 'RGB', ( 100, 100 ) )
  4. wire = Image.open( 'wire.png', 'r' )
  5.  
  6. xmin, xmax = 0, 99
  7. ymin, ymax = 0, 99
  8.  
  9. pos = [ 0, 0 ]
  10. place = 0
  11.  
  12. output = False
  13.  
  14. while not ( xmax - 1 == xmin or ymax - 1 == ymin ):
  15.  
  16.     for x in range( xmin, xmax + 1 ):
  17.         if output: print "x ", pos[0], " y ", pos[1]
  18.  
  19.         pos[0] = x
  20.         place += 1
  21.         img.putpixel( pos, wire.getpixel( ( place, 0) ) )
  22.  
  23.     ymin += 1
  24.  
  25.     for y in range( ymin, ymax + 1 ):
  26.         if output: print "x ", pos[0], " y ", pos[1]
  27.  
  28.         pos[1] = y
  29.         place += 1
  30.         img.putpixel( pos, wire.getpixel( ( place, 0) ) )
  31.     xmax -= 1
  32.  
  33.     for x in range( xmax, xmin - 1, -1 ):
  34.         if output: print "x ", pos[0], " y ", pos[1]
  35.  
  36.         pos[0] = x
  37.         place += 1
  38.         img.putpixel( pos, wire.getpixel( ( place, 0) ) )
  39.     ymax -= 1
  40.  
  41.     for y in range( ymax, ymin - 1, -1 ):
  42.         if output: print "x ", pos[0], " y ", pos[1]
  43.  
  44.         pos[1] = y
  45.         place += 1
  46.         img.putpixel( pos, wire.getpixel( ( place, 0) ) )
  47.     xmin += 1
  48.  
  49. img.save( "spiral.png" )
RAW Paste Data