Class: CryptopunksGui
- Inherits:
-
Object
- Object
- CryptopunksGui
- Includes:
- Glimmer
- Defined in:
- app/cryptopunks_gui.rb
Constant Summary collapse
- PALETTES =
['Standard'] + (Palette8bit.constants).map(&:name).map {|palette| palette.split('_').map(&:capitalize).join(' ')}.reject { |palette| palette.include?(' ') }.sort
- STYLES =
['Normal', 'Led', 'Sketch']
Instance Attribute Summary collapse
-
#flip ⇒ Object
Returns the value of attribute flip.
-
#led_round_corner ⇒ Object
Returns the value of attribute led_round_corner.
-
#led_spacing ⇒ Object
Returns the value of attribute led_spacing.
-
#mirror ⇒ Object
Returns the value of attribute mirror.
-
#palette ⇒ Object
Returns the value of attribute palette.
-
#punk_index ⇒ Object
Returns the value of attribute punk_index.
-
#sketch_line ⇒ Object
Returns the value of attribute sketch_line.
-
#style ⇒ Object
Returns the value of attribute style.
-
#zoom ⇒ Object
Returns the value of attribute zoom.
Instance Method Summary collapse
- #add_style_options ⇒ Object
- #create_gui ⇒ Object
- #generate_image ⇒ Object
-
#initialize ⇒ CryptopunksGui
constructor
A new instance of CryptopunksGui.
- #initialize_defaults ⇒ Object
- #initialize_punks ⇒ Object
- #observe_image_attribute_changes ⇒ Object
- #palette_options ⇒ Object
- #style_options ⇒ Object
Constructor Details
#initialize ⇒ CryptopunksGui
Returns a new instance of CryptopunksGui.
18 19 20 21 22 23 24 25 |
# File 'app/cryptopunks_gui.rb', line 18 def initialize initialize_punks initialize_defaults observe_image_attribute_changes create_gui self.punk_index = 0 @root.open end |
Instance Attribute Details
#flip ⇒ Object
Returns the value of attribute flip.
16 17 18 |
# File 'app/cryptopunks_gui.rb', line 16 def flip @flip end |
#led_round_corner ⇒ Object
Returns the value of attribute led_round_corner.
16 17 18 |
# File 'app/cryptopunks_gui.rb', line 16 def led_round_corner @led_round_corner end |
#led_spacing ⇒ Object
Returns the value of attribute led_spacing.
16 17 18 |
# File 'app/cryptopunks_gui.rb', line 16 def led_spacing @led_spacing end |
#mirror ⇒ Object
Returns the value of attribute mirror.
16 17 18 |
# File 'app/cryptopunks_gui.rb', line 16 def mirror @mirror end |
#palette ⇒ Object
Returns the value of attribute palette.
16 17 18 |
# File 'app/cryptopunks_gui.rb', line 16 def palette @palette end |
#punk_index ⇒ Object
Returns the value of attribute punk_index.
16 17 18 |
# File 'app/cryptopunks_gui.rb', line 16 def punk_index @punk_index end |
#sketch_line ⇒ Object
Returns the value of attribute sketch_line.
16 17 18 |
# File 'app/cryptopunks_gui.rb', line 16 def sketch_line @sketch_line end |
#style ⇒ Object
Returns the value of attribute style.
16 17 18 |
# File 'app/cryptopunks_gui.rb', line 16 def style @style end |
#zoom ⇒ Object
Returns the value of attribute zoom.
16 17 18 |
# File 'app/cryptopunks_gui.rb', line 16 def zoom @zoom end |
Instance Method Details
#add_style_options ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'app/cryptopunks_gui.rb', line 188 def .content { .children.each(&:destroy) if @style == 'Led' frame { padding 0 label { grid row: 0, column: 0, column_weight: 0 text 'Spacing:' } spinbox { grid row: 0, column: 1 from 1 to 72 text <=> [self, :led_spacing] } { grid row: 0, column: 2 variable <=> [self, :led_round_corner] } label { grid row: 0, column: 3 text 'Round Corner' on('Button-1') do self.led_round_corner = !led_round_corner end } } elsif @style == 'Sketch' frame { padding 0 label { grid row: 0, column: 0, column_weight: 0 text 'Line:' } spinbox { grid row: 0, column: 1 from 1 to 72 text <=> [self, :sketch_line] } } else frame { # filler padding 0 height 0 width 0 } end } end |
#create_gui ⇒ Object
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 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'app/cryptopunks_gui.rb', line 95 def create_gui @root = root { title 'CryptoPunks GUI' iconphoto File.('../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 'Palette:' } combobox { readonly true text <=> [self, :palette] } label { text 'Style:' } combobox { readonly true text <=> [self, :style, after_write: ->(val) {}] } = frame { padding 0 } frame { padding 0 { grid row: 0, column: 0, column_weight: 0 variable <=> [self, :mirror] } label { grid row: 0, column: 1 text 'Mirror' on('Button-1') do self.mirror = !mirror end } { grid row: 0, column: 2 variable <=> [self, :flip] } label { grid row: 0, column: 3 text 'Flip' on('Button-1') do self.flip = !flip end } } label { text 'Output Location:' } = entry { readonly true } @image_label = label { grid row_weight: 1 } } } end |
#generate_image ⇒ Object
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 |
# File 'app/cryptopunks_gui.rb', line 67 def generate_image return if @punk_index.to_i > 9999 image_location = File.join(@punk_directory, "punk-#{@punk_index}#{"x#{@zoom}" if @zoom.to_i > 1}#{"-#{@palette.underscore}" if @palette != PALETTES.first}#{"-#{@style.underscore}" if @style != STYLES.first}.png") puts "Writing punk image to #{image_location}" selected_punk = @punks[@punk_index.to_i] selected_punk = selected_punk.change_palette8bit(Palette8bit.const_get(@palette.gsub(' ', '_').upcase.to_sym)) if @palette != PALETTES.first @original_zoom = @zoom if @style != STYLES.first = {} if @style == 'Led' [:spacing] = @led_spacing.to_i [:round_corner] = @led_round_corner end if @style == 'Sketch' [:line] = @sketch_line.to_i end selected_punk = selected_punk.send(@style.underscore, @zoom.to_i, **) end selected_punk = selected_punk.mirror if @mirror selected_punk = selected_punk.flip if @flip selected_punk = selected_punk.zoom(@zoom.to_i) if @style == STYLES.first selected_punk.save(image_location) @image_label.image = image_location .text = image_location @previous_style = @style notify_observers(:zoom) if @zoom != @original_zoom end |
#initialize_defaults ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'app/cryptopunks_gui.rb', line 43 def initialize_defaults @zoom = 12 @palette = PALETTES.first @style = STYLES.first @led_spacing = 2 @led_round_corner = false @sketch_line = 1 @mirror = false @flip = false end |
#initialize_punks ⇒ Object
35 36 37 38 39 40 41 |
# File 'app/cryptopunks_gui.rb', line 35 def initialize_punks @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) end |
#observe_image_attribute_changes ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/cryptopunks_gui.rb', line 54 def observe_image_attribute_changes observer = Glimmer::DataBinding::Observer.proc { generate_image } observer.observe(self, :punk_index) observer.observe(self, :zoom) observer.observe(self, :palette) observer.observe(self, :style) observer.observe(self, :led_spacing) observer.observe(self, :led_round_corner) observer.observe(self, :sketch_line) observer.observe(self, :mirror) observer.observe(self, :flip) end |
#palette_options ⇒ Object
27 28 29 |
# File 'app/cryptopunks_gui.rb', line 27 def PALETTES end |
#style_options ⇒ Object
31 32 33 |
# File 'app/cryptopunks_gui.rb', line 31 def STYLES end |