Skip to content

Instantly share code, notes, and snippets.

@akoskovacs
Created November 28, 2012 23:15
Show Gist options
  • Save akoskovacs/4165455 to your computer and use it in GitHub Desktop.
Save akoskovacs/4165455 to your computer and use it in GitHub Desktop.
pgm picture generator (gray gradient pattern)
#!/usr/bin/env ruby
HEIGHT = 1024
WIDTH = 1024
f = File.new("sample.pgm", "w")
f.puts "P2"
f.puts "#{HEIGHT} #{WIDTH}"
f.puts 255
f.puts "# Generated by pgen.rb (C) Akos Kovacs"
HEIGHT.times do |row|
f.puts "# row #{row}"
i = 0
b = 0
WIDTH.times do
if (i == 255)
i = 0
end
b += 1
if (b == 20)
f.print "\n"
b = 0
end
f.print "#{i += 1} "
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment