<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: graphics code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 27 Jul 2008 03:45:19 GMT</pubDate>
    <description>DZone Snippets: graphics code</description>
    <item>
      <title>Patchwork quilt pattern in Ruby (from Knuth TAoCP 4 - 7.1.3)</title>
      <link>http://snippets.dzone.com/posts/show/5181</link>
      <description>In Donald Knuth's TAoCP Pre-Fascicle 1a: Bitwise Tricks and Techniques, he shows a patchwork quilt defined by f(x, y) = ((x ^ y) &amp; ((y - 350) &gt;&gt; 3)) ** 2, designed by D. Sleator in 1976. I wanted to recreate this quilt myself using Ruby. The following program generates a PNG file of the "quilt."&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'rubygems'&lt;br /&gt;require 'png'&lt;br /&gt;&lt;br /&gt;def f(x, y)&lt;br /&gt;  ( (x ^ y) &amp; ((y - 350) &gt;&gt; 3) ) ** 2&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;canvas = PNG::Canvas.new(500, 500)&lt;br /&gt;&lt;br /&gt;0.upto(499) do |y|&lt;br /&gt;  0.upto(499) do |x|&lt;br /&gt;    canvas[x, 499 - y] = ((f(x, y) &gt;&gt; 12) &amp; 1) == 1 ? PNG::Color::Black : PNG::Color::White&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;png = PNG.new(canvas)&lt;br /&gt;png.save 'pattern.png'&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 27 Feb 2008 10:17:32 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5181</guid>
      <author>peter (Peter Cooperx)</author>
    </item>
    <item>
      <title>Java - JFreeChart Example</title>
      <link>http://snippets.dzone.com/posts/show/2945</link>
      <description>&lt;code&gt;&lt;br /&gt;import java.awt.Font;&lt;br /&gt;&lt;br /&gt;import javax.swing.JFrame;&lt;br /&gt;import javax.swing.JPanel;&lt;br /&gt;&lt;br /&gt;import org.jfree.chart.ChartFactory;&lt;br /&gt;import org.jfree.chart.ChartPanel;&lt;br /&gt;import org.jfree.chart.JFreeChart;&lt;br /&gt;import org.jfree.chart.plot.PiePlot;&lt;br /&gt;import org.jfree.data.general.DefaultPieDataset;&lt;br /&gt;&lt;br /&gt;public class jfcExample extends JFrame&lt;br /&gt;{&lt;br /&gt;	private static final long serialVersionUID = 1L;&lt;br /&gt;	&lt;br /&gt;	private DefaultPieDataset dataset;&lt;br /&gt;	private JFreeChart jfc;&lt;br /&gt;&lt;br /&gt;	public jfcExample()&lt;br /&gt;	{&lt;br /&gt;		dataset = new DefaultPieDataset();&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	public void setValue(String title, Double numDouble)&lt;br /&gt;	{&lt;br /&gt;		dataset.setValue(title, numDouble);&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	public void setChar(String title)&lt;br /&gt;	{&lt;br /&gt;		jfc = ChartFactory.createPieChart(title, dataset, true, true, false);&lt;br /&gt;		&lt;br /&gt;		PiePlot pp = (PiePlot) jfc.getPlot();&lt;br /&gt;		pp.setSectionOutlinesVisible(false);&lt;br /&gt;		pp.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));&lt;br /&gt;		pp.setNoDataMessage("Nessun Dato Inserito");&lt;br /&gt;		pp.setCircular(false);&lt;br /&gt;		pp.setLabelGap(0.02);&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	private JPanel createPanel()&lt;br /&gt;	{&lt;br /&gt;		return new ChartPanel(jfc);&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	public void Show()&lt;br /&gt;	{&lt;br /&gt;		setContentPane(createPanel());&lt;br /&gt;		setVisible(true);&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	public static void main(String[] args)&lt;br /&gt;	{&lt;br /&gt;		jfcExample j = new jfcExample();&lt;br /&gt;		j.setTitle("Example Chart...");&lt;br /&gt;		j.setSize(640, 430);&lt;br /&gt;		&lt;br /&gt;		j.setValue("UNO", new Double(20.0));&lt;br /&gt;		j.setValue("DUE", new Double(10.0));&lt;br /&gt;		j.setValue("TRE", new Double(20.0));&lt;br /&gt;		j.setValue("QUATTRO", new Double(30.0));&lt;br /&gt;		j.setValue("CINQUE", new Double(20.0));&lt;br /&gt;		&lt;br /&gt;		j.setChar("Example Chart...");&lt;br /&gt;		&lt;br /&gt;		j.Show();&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 01 Nov 2006 19:03:27 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2945</guid>
      <author>whitetiger ()</author>
    </item>
    <item>
      <title>image resize</title>
      <link>http://snippets.dzone.com/posts/show/486</link>
      <description>This function will resize any input file restricting the width and height to be no more than the specified pixels, and output a binary stream.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;function resize_jpg($inputFilename, $new_side){&lt;br /&gt;	$imagedata = getimagesize($inputFilename);&lt;br /&gt;	$w = $imagedata[0];&lt;br /&gt;	$h = $imagedata[1];&lt;br /&gt;	&lt;br /&gt;	if ($h &gt; $w) {&lt;br /&gt;		$new_w = ($new_side / $h) * $w;&lt;br /&gt;		$new_h = $new_side;	&lt;br /&gt;	} else {&lt;br /&gt;		$new_h = ($new_side / $w) * $h;&lt;br /&gt;		$new_w = $new_side;&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	$im2 = ImageCreateTrueColor($new_w, $new_h);&lt;br /&gt;	$image = ImageCreateFromJpeg($inputFilename);&lt;br /&gt;	imagecopyResampled ($im2, $image, 0, 0, 0, 0, $new_w, $new_h, $imagedata[0], $imagedata[1]);&lt;br /&gt;	return $im2;&lt;br /&gt;}&lt;/pre&gt;</description>
      <pubDate>Wed, 20 Jul 2005 21:53:09 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/486</guid>
      <author>evitiello (Eric Vitiello)</author>
    </item>
    <item>
      <title>Installing libjpeg on OS X</title>
      <link>http://snippets.dzone.com/posts/show/38</link>
      <description>Get http://www.ijg.org/files/jpegsrc.v6b.tar.gz, and then:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;tar zxvf jpegsrc.v6b.tar.gz&lt;br /&gt;cd jpeg-6b&lt;br /&gt;cp /usr/share/libtool/config.sub .&lt;br /&gt;cp /usr/share/libtool/config.guess .&lt;br /&gt;./configure --enable-shared --enable-static&lt;br /&gt;make&lt;br /&gt;sudo make install&lt;br /&gt;sudo ranlib /usr/local/lib/libjpeg.a&lt;/code&gt;</description>
      <pubDate>Tue, 05 Apr 2005 20:21:21 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/38</guid>
      <author>peter (Peter Cooperx)</author>
    </item>
    <item>
      <title>Thumbnailer in Ruby and RMagick</title>
      <link>http://snippets.dzone.com/posts/show/36</link>
      <description>&lt;code&gt;require 'RMagick'&lt;br /&gt;&lt;br /&gt;maxwidth = 120&lt;br /&gt;maxheight = 160&lt;br /&gt;aspectratio = maxwidth.to_f / maxheight.to_f&lt;br /&gt;imgfile = 'world'&lt;br /&gt;&lt;br /&gt;pic = Magick::Image.read(imgfile + '.jpg').first&lt;br /&gt;imgwidth = pic.columns&lt;br /&gt;imgheight = pic.rows&lt;br /&gt;imgratio = imgwidth.to_f / imgheight.to_f&lt;br /&gt;imgratio &gt; aspectratio ? scaleratio = maxwidth.to_f / imgwidth : scaleratio = maxheight.to_f / imgheight&lt;br /&gt;thumb = pic.resize(scaleratio)&lt;br /&gt;&lt;br /&gt;white_bg = Magick::Image.new(maxwidth, thumb.height)&lt;br /&gt;pic = white_bg.composite(thumb, Magick::CenterGravity, Magick::OverCompositeOp)&lt;br /&gt;pic.write(imgfile + '.thumb.jpg')&lt;/code&gt;</description>
      <pubDate>Mon, 04 Apr 2005 06:41:44 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/36</guid>
      <author>peter (Peter Cooperx)</author>
    </item>
  </channel>
</rss>
