Class: CryptopunksGui

Inherits:
Object
  • Object
show all
Includes:
Glimmer
Defined in:
app/cryptopunks_gui.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCryptopunksGui

Returns a new instance of CryptopunksGui.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/cryptopunks_gui.rb', line 14

def initialize
  @punk_directory = File.join(Dir.home, '.cryptopunks')
  FileUtils.mkdir_p(@punk_directory)
  @punk_file = File.join(@punk_directory, 'punks.png')
  File.write(@punk_file, Net::HTTP.get(URI('https://raw.githubusercontent.com/larvalabs/cryptopunks/master/punks.png'))) unless File.exist?(@punk_file)
  @punks = Punks::Image::Composite.read(@punk_file)
  @zoom = 12
  
  observer = Glimmer::DataBinding::Observer.proc do
    generate_image
  end
  observer.observe(self, :punk_index)
  observer.observe(self, :zoom)
  
  create_gui
  self.punk_index = 0
  @root.open
end

Instance Attribute Details

#punk_indexObject

Returns the value of attribute punk_index.



12
13
14
# File 'app/cryptopunks_gui.rb', line 12

def punk_index
  @punk_index
end

#zoomObject

Returns the value of attribute zoom.



12
13
14
# File 'app/cryptopunks_gui.rb', line 12

def zoom
  @zoom
end

Instance Method Details

#create_guiObject



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
# File 'app/cryptopunks_gui.rb', line 43

def create_gui
  @root = root {
    title 'CryptoPunks GUI'
    iconphoto File.expand_path('../icons/cryptopunks-gui.png', __dir__)
    
    frame {
      label {
        text 'Select Punk Index and Zoom To Mint Cryptopunk'
        font weight: 'bold'
      }
      
      label {
        text 'Punk Index:'
      }
      spinbox {
        from 0
        to @punks.size - 1
        text <=> [self, :punk_index]
      }
      
      label {
        text 'Zoom:'
      }
      spinbox {
        from 1
        to 72
        text <=> [self, :zoom]
      }
      
      label {
        text 'Output Location:'
      }
      @message_entry = entry {
        readonly true
      }
      
      @image_label = label {
        grid row_weight: 1
      }
    }
  }
end

#generate_imageObject



33
34
35
36
37
38
39
40
41
# File 'app/cryptopunks_gui.rb', line 33

def generate_image
  image_location = File.join(@punk_directory, "punk-#{@punk_index}#{"x#{@zoom}" if @zoom.to_i > 1}.png")
  puts "Writing punk image to #{image_location}"
  selected_punk = @punks[@punk_index.to_i]
  selected_punk = selected_punk.zoom(@zoom.to_i)
  selected_punk.save(image_location)
  @image_label.image = image_location
  @message_entry.text = image_location
end