#!/usr/bin/ruby -w # build four graphic images for rounded table corners if(ARGV.length < 2) puts "usage: radius bgColor [basename]" exit 0 end def createConvert(prefix,data,name) # build an XPM graphic file's contents xpm = prefix + data.join(",\n") + "\n};\n" # pipe result to "convert", part of ImageMagick com = "convert - -transparent #000000 #{name + '.gif'}" File.popen(com,"w") { |p| p.print xpm } end # read options, set up (radiusStr,bgColorStr,baseName) = ARGV baseName = "roundCorner" if !baseName radius = radiusStr.to_i right = Array.new left = Array.new # Generate quarter-circle graphic image 0.upto(radius-1) { |y| row = "\"" 0.upto(radius-1) { |x| qx = x.to_f / radius qy = Math.sqrt(1.0-(qx*qx)) * radius row += (qy > y)?".":" "; } row += "\"" right.push(row) left.push(row.reverse) } # Create XPM graphic file content header="/* XPM */\nstatic const char *grfixname[] = {\n/* columns rows colors chars-per-pixel */\n" prefix = header + "\"#{radius} #{radius} 2 1\",\n" # define XPM bg color prefix += "\" c #000000\",\n" # define XPM fg color prefix += "\". c ##{bgColorStr}\",\n" prefix += "/* pixels */\n" # create the four graphic images createConvert(prefix,left.reverse,baseName + "TL") createConvert(prefix,left,baseName + "BL") createConvert(prefix,right.reverse,baseName + "TR") createConvert(prefix,right,baseName + "BR")