--Boundary-00 DEbGBYN+9Py7Ho Content-Type: Multipart/Mixed; boundaryoundary-00 DEbGBYN+9Py7Ho" --Boundary-00 DEbGBYN+9Py7Ho Content-Type: text/plain; charset tf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline On Sunday 10 June 2007 12:38, Tim Hunter wrote: > Very cool! I'm always tickled when I see somebody using RMagick for > something besides just making thumbnails. > > You're right, drawing each pixel would be slow. You could speed it up by > creating each row as an array of Pixels, then using import_pixels or > store_pixels to "draw" an entire row. Not only is doing things a row at > a time faster, these methods are much, much faster than Draw#draw, which > has to interpret the drawing primitives. Check the get_pixels.rb example > in the RMagick distribution. > > Again, very cool! > > Tim Right you are Tim. Attached is my new blanket_image.rb improved in the way you suggested (blanket_draw.rb can be discarded now). Quite a difference: $ time ./mexican_blanket.orig.rb 800 800 --format png Wrote blanket to blanket_800x800.png real 0m28.706s user 0m25.757s sys 0m0.454s $ time ./mexican_blanket.rb 800 800 --format png Wrote blanket to blanket_800x800.png real 0m7.687s user 0m7.452s sys 0m0.070s (BTW, your message appears to have been sent to just me, not the list. Not sure if this was intentional. If so, hope you don't mind me moving to the list.) -- Jesse Merriman jessemerriman / warpmail.net http://www.jessemerriman.com/ --Boundary-00 DEbGBYN+9Py7Ho Content-Type: application/x-ruby; namelanket_image.rb" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filenamelanket_image.rb" # Ruby Quiz 127: Mexican Blanket # blanket_image.rb require 'blanket' require 'RMagick' include Magick class BlanketImage < Magick::Image # Colors from http://library.thinkquest.org/05aug/01280/Images/flag.jpg # Not sure how accurate that is though.. StringToColor 'R' '#fe0000', 'B' '#0333a1', 'Y' '#ffff49', 'O' '#ea6520', 'G' '#039e36', 'W' '#ffffff' } def initialize blanket super blanket.width, blanket.height draw_blanket blanket self end def draw_blanket blanket # Fill in the colors row-by-row (thanks Tim Hunter). blanket.each_row_with_index do |row, y| pixels ] row.split(//).each do |color_char| pixels << Pixel.from_color(StringToColor[color_char]) end store_pixels 0, y, pixels.size, 1, pixels end end end --Boundary-00 DEbGBYN+9Py7Ho-- --Boundary-00 DEbGBYN+9Py7Ho--