[macruby-changes] [838] MacRuby/trunk/sample-macruby/HotCocoa/graphics

source_changes at macosforge.org source_changes at macosforge.org
Fri Mar 6 18:09:02 PST 2009


Revision: 838
          http://trac.macosforge.org/projects/ruby/changeset/838
Author:   lsansonetti at apple.com
Date:     2009-03-06 18:09:02 -0800 (Fri, 06 Mar 2009)
Log Message:
-----------
reorganizing the hotcocoa graphics examples

Modified Paths:
--------------
    MacRuby/trunk/sample-macruby/HotCocoa/graphics/drawing.rb
    MacRuby/trunk/sample-macruby/HotCocoa/graphics/iterate.rb
    MacRuby/trunk/sample-macruby/HotCocoa/graphics/particle.rb
    MacRuby/trunk/sample-macruby/HotCocoa/graphics/pdf.rb
    MacRuby/trunk/sample-macruby/HotCocoa/graphics/randomize.rb
    MacRuby/trunk/sample-macruby/HotCocoa/graphics/text.rb

Added Paths:
-----------
    MacRuby/trunk/sample-macruby/HotCocoa/graphics/image-blendmodes.rb
    MacRuby/trunk/sample-macruby/HotCocoa/graphics/image-colors.rb
    MacRuby/trunk/sample-macruby/HotCocoa/graphics/image-effects.rb
    MacRuby/trunk/sample-macruby/HotCocoa/graphics/image-moving.rb
    MacRuby/trunk/sample-macruby/HotCocoa/graphics/rope-hair.rb
    MacRuby/trunk/sample-macruby/HotCocoa/graphics/rope-ribbon.rb

Removed Paths:
-------------
    MacRuby/trunk/sample-macruby/HotCocoa/graphics/color.rb
    MacRuby/trunk/sample-macruby/HotCocoa/graphics/hotcocoa.rb
    MacRuby/trunk/sample-macruby/HotCocoa/graphics/image.rb
    MacRuby/trunk/sample-macruby/HotCocoa/graphics/rope.rb

Deleted: MacRuby/trunk/sample-macruby/HotCocoa/graphics/color.rb
===================================================================
--- MacRuby/trunk/sample-macruby/HotCocoa/graphics/color.rb	2009-03-07 01:32:13 UTC (rev 837)
+++ MacRuby/trunk/sample-macruby/HotCocoa/graphics/color.rb	2009-03-07 02:09:02 UTC (rev 838)
@@ -1,124 +0,0 @@
-#!/usr/bin/env macruby
-
-require 'hotcocoa/graphics'
-require 'test/unit'
-include HotCocoa::Graphics
-
-
-PRECISION = 0.0000001
-
-class TestHSB < Test::Unit::TestCase
-  
-  def test_hsba
-    
-    # new named color
-    c = Color.blue
-    assert_in_delta(c.hue, 0.6666666, PRECISION)
-    assert_in_delta(c.saturation,1.0, PRECISION)
-    assert_in_delta(c.brightness,1.0, PRECISION)
-    assert_in_delta(c.a,1.0, PRECISION)
-    
-    # new HSBA color
-    c = Color.hsb(0.5,0.4,0.3,0.2)
-    assert_in_delta(c.hue, 0.5, PRECISION)
-    assert_in_delta(c.saturation, 0.4, PRECISION)
-    assert_in_delta(c.brightness, 0.3, PRECISION)
-    assert_in_delta(c.a, 0.2, PRECISION)
-    
-    # new RGBA color
-    c = Color.new(0.5,0.4,0.3,1.0)
-    assert_in_delta(c.hue, 0.08333333, PRECISION)
-    assert_in_delta(c.saturation, 0.3999999, PRECISION)
-    assert_in_delta(c.brightness, 0.5, PRECISION)
-    assert_in_delta(c.a, 1.0, PRECISION)
-    
-    # darken
-    c = Color.blue
-    c.darken(0.1)
-    assert_in_delta(c.hue, 0.6666666, PRECISION)
-    assert_in_delta(c.saturation,1.0, PRECISION)
-    assert_in_delta(c.brightness, 0.8999999, PRECISION)
-    assert_in_delta(c.a,1.0, PRECISION)
-    
-    # lighten
-    c = Color.new(0.5,0.4,0.3,1.0)
-    c.lighten(0.1)
-    assert_in_delta(c.hue, 0.08333333, PRECISION)
-    assert_in_delta(c.saturation, 0.4, PRECISION)
-    assert_in_delta(c.brightness, 0.6, PRECISION)
-    assert_in_delta(c.a, 1.0, PRECISION)
-  
-    # saturate
-    c = Color.new(0.5,0.4,0.3,1.0)
-    c.saturate(0.1)
-    assert_in_delta(c.hue, 0.08333333, PRECISION)
-    assert_in_delta(c.saturation, 0.5, PRECISION)
-    assert_in_delta(c.brightness, 0.5, PRECISION)
-    assert_in_delta(c.a, 1.0, PRECISION)
-    
-    # desaturate
-    c = Color.new(0.5,0.4,0.3,1.0)
-    c.desaturate(0.1)
-    assert_in_delta(c.hue, 0.08333333, PRECISION)
-    assert_in_delta(c.saturation, 0.2999999, PRECISION)
-    assert_in_delta(c.brightness, 0.5, PRECISION)
-    assert_in_delta(c.a, 1.0, PRECISION)
-    
-    # set HSB
-    c.set_hsb(0.5,0.4,0.3,0.2)
-    assert_in_delta(c.hue, 0.5, PRECISION)
-    assert_in_delta(c.saturation, 0.4, PRECISION)
-    assert_in_delta(c.brightness, 0.3, PRECISION)
-    assert_in_delta(c.a, 0.2, PRECISION)
-    
-    # get HSB
-    h,s,b,a = c.get_hsb
-    assert_in_delta(h, 0.5, PRECISION)
-    assert_in_delta(s, 0.4, PRECISION)
-    assert_in_delta(b, 0.3, PRECISION)
-    assert_in_delta(a, 0.2, PRECISION)
-    
-    # adjust HSB
-    c.adjust_hsb(0.1,0.1,0.1,0.1)
-    assert_in_delta(c.hue, 0.6, PRECISION)
-    assert_in_delta(c.saturation, 0.5, PRECISION)
-    assert_in_delta(c.brightness, 0.4, PRECISION)
-    assert_in_delta(c.a, 0.3, PRECISION)
-    
-  end
-  
-  def test_rgba
-    
-    # new named color
-    c = Color.blue
-    assert_in_delta(c.r, 0.0, PRECISION)
-    assert_in_delta(c.g, 0.0, PRECISION)
-    assert_in_delta(c.b, 1.0, PRECISION)
-    assert_in_delta(c.a, 1.0, PRECISION)
-    
-    # new RGBA color
-    c = Color.new(0.5,0.4,0.3,0.2)
-    assert_in_delta(c.r, 0.5, PRECISION)
-    assert_in_delta(c.g, 0.4, PRECISION)
-    assert_in_delta(c.b, 0.3, PRECISION)
-    assert_in_delta(c.a, 0.2, PRECISION)
-
-    # new RGBA color
-    c = Color.rgb(0.5,0.4,0.3,0.2)
-    assert_in_delta(c.r, 0.5, PRECISION)
-    assert_in_delta(c.g, 0.4, PRECISION)
-    assert_in_delta(c.b, 0.3, PRECISION)
-    assert_in_delta(c.a, 0.2, PRECISION)
-
-    # adjust RGBA
-    c.adjust_rgb(0.1,0.1,0.1,0.1)
-    assert_in_delta(c.r, 0.6, PRECISION)
-    assert_in_delta(c.g, 0.5, PRECISION)
-    assert_in_delta(c.b, 0.4, PRECISION)
-    assert_in_delta(c.a, 0.3, PRECISION)
-
-    
-  end
-  
-  
-end
\ No newline at end of file

Modified: MacRuby/trunk/sample-macruby/HotCocoa/graphics/drawing.rb
===================================================================
--- MacRuby/trunk/sample-macruby/HotCocoa/graphics/drawing.rb	2009-03-07 01:32:13 UTC (rev 837)
+++ MacRuby/trunk/sample-macruby/HotCocoa/graphics/drawing.rb	2009-03-07 02:09:02 UTC (rev 838)
@@ -2,7 +2,8 @@
 
 require 'hotcocoa/graphics'
 require 'test/unit'
-include HotCocoa::Graphics
+include HotCocoa
+include Graphics
 
 class TestDrawing < Test::Unit::TestCase
   
@@ -132,4 +133,4 @@
     #c.open
   end
   
-end
\ No newline at end of file
+end

Deleted: MacRuby/trunk/sample-macruby/HotCocoa/graphics/hotcocoa.rb
===================================================================
--- MacRuby/trunk/sample-macruby/HotCocoa/graphics/hotcocoa.rb	2009-03-07 01:32:13 UTC (rev 837)
+++ MacRuby/trunk/sample-macruby/HotCocoa/graphics/hotcocoa.rb	2009-03-07 02:09:02 UTC (rev 838)
@@ -1,10 +0,0 @@
-#!/usr/bin/env macruby
-
-require 'hotcocoa'
-include HotCocoa
-
- at table = table_view(
-  :columns => [ 
-    column(:id => :klass, :text => "Class"),
-    column(:id => :ancestors, :text => "Ancestors") 
-  ]  )
\ No newline at end of file

Added: MacRuby/trunk/sample-macruby/HotCocoa/graphics/image-blendmodes.rb
===================================================================
--- MacRuby/trunk/sample-macruby/HotCocoa/graphics/image-blendmodes.rb	                        (rev 0)
+++ MacRuby/trunk/sample-macruby/HotCocoa/graphics/image-blendmodes.rb	2009-03-07 02:09:02 UTC (rev 838)
@@ -0,0 +1,39 @@
+require 'hotcocoa/graphics'
+include HotCocoa
+include Graphics
+
+OUTFILE = 'image-blendmodes.png'
+
+canvas = Canvas.for_image(:size => [400,730], :filename => OUTFILE)
+canvas.background(Color.white)
+canvas.font('Skia')
+canvas.fontsize(14)
+
+# set image width,height
+w,h = [95,95]
+
+# set initial drawing position
+x,y = [0,canvas.height - h - 10]
+
+# load and resize two images
+imgA = Image.new('images/v2.jpg').resize(w,h)
+imgB = Image.new('images/italy.jpg').resize(w,h)
+
+# add image B to image A using each blending mode, and draw to canvas
+[:normal,:multiply,:screen,:overlay,:darken,:lighten,
+  :colordodge,:colorburn,:softlight,:hardlight,:difference,:exclusion,
+  :hue,:saturation,:color,:luminosity,:maximum,:minimum,:add,:atop,
+  :in,:out,:over].each do |blendmode|
+  imgA.reset.resize(w,h)
+  imgA.blend(imgB, blendmode)
+  canvas.draw(imgA,x,y)
+  canvas.text(blendmode,x,y-15)
+  x += w + 5
+  if (x > canvas.width - w + 5)
+    x = 0
+    y -= h + 25
+  end
+end
+canvas.save
+
+`open #{OUTFILE}`

Added: MacRuby/trunk/sample-macruby/HotCocoa/graphics/image-colors.rb
===================================================================
--- MacRuby/trunk/sample-macruby/HotCocoa/graphics/image-colors.rb	                        (rev 0)
+++ MacRuby/trunk/sample-macruby/HotCocoa/graphics/image-colors.rb	2009-03-07 02:09:02 UTC (rev 838)
@@ -0,0 +1,106 @@
+require 'hotcocoa/graphics'
+include HotCocoa
+include Graphics
+
+OUTFILE = 'image-colors.png'
+
+# set up the canvas
+canvas = Canvas.for_image(:size => [400,400], :filename => OUTFILE)
+canvas.background(Color.white)
+canvas.font('Skia')
+canvas.fontsize(14)
+canvas.fill(Color.black)
+
+# LOAD IMAGE
+img = Image.new('images/v2.jpg')
+
+w,h = [100,100]
+x,y = [0,290]
+xoffset = 105
+yoffset = 130
+
+# ORIGINAL image, resized to fit within w,h:
+img.fit(w,h)
+canvas.draw(img,x,y)
+canvas.text("original",x,y-15)
+x += xoffset
+
+# HUE: rotate color wheel by degrees
+img.reset.fit(w,h)
+img.hue(45)
+canvas.draw(img,x,y)
+canvas.text("hue",x,y-15)
+x += xoffset
+
+# EXPOSURE: increase/decrease exposure by f-stops
+img.reset.fit(w,h)
+img.exposure(1.0)
+canvas.draw(img,x,y)
+canvas.text("exposure",x,y-15)
+x += xoffset
+
+# SATURATION: adjust saturation by multiplier
+img.reset.fit(w,h)
+img.saturation(2.0)
+canvas.draw(img,x,y)
+canvas.text("saturation",x,y-15)
+x += xoffset
+
+# (go to next row)
+x = 0
+y -= yoffset
+
+# CONTRAST: adjust contrast by multiplier
+img.reset.fit(w,h)
+img.contrast(2.0)
+canvas.draw(img,x,y)
+canvas.text("contrast",x,y-15)
+x += xoffset
+
+# BRIGHTNESS: adjust brightness
+img.reset.fit(w,h)
+img.brightness(0.5)
+canvas.draw(img,x,y)
+canvas.text("brightness",x,y-15)
+x += xoffset
+
+# MONOCHROME: convert to a monochrome image
+img.reset.fit(w,h)
+img.monochrome(Color.orange)
+canvas.draw(img,x,y)
+canvas.text("monochrome",x,y-15)
+x += xoffset
+
+# WHITEPOINT: remap the white point
+img.reset.fit(w,h)
+img.whitepoint(Color.whiteish)
+canvas.draw(img,x,y)
+canvas.text("white point",x,y-15)
+x += xoffset
+
+# (go to next row)
+x = 0
+y -= yoffset
+
+# CHAINING: apply multiple effects at once
+img.reset.fit(w,h)
+img.hue(60).saturation(2.0).contrast(2.5)
+canvas.draw(img,x,y)
+canvas.text("multi effects",x,y-15)
+x += xoffset
+
+# COLORS: sample random colors from the image and render as a gradient
+img.reset.fit(w,h)              # reset the image and scale to fit within w,h
+colors = img.colors(10).sort!   # select 10 random colors and sort by brightness
+# gradient
+gradient = Gradient.new(colors) # create a new gradient using the selected colors
+rect = Path.new.rect(x,y,img.width,img.height) # create a rectangle the size of the image
+canvas.beginclip(rect)          # begin clipping so the gradient will only fill the rectangle
+canvas.gradient(gradient,x,y,x+img.width,y+img.height) # draw the gradient between opposite corners of the rectangle
+canvas.endclip                  # end clipping so we can draw on the rest of the canvas
+canvas.text("get colors",x,y-15)    # add text label
+x += xoffset
+
+canvas.save
+
+`open #{OUTFILE}`

Added: MacRuby/trunk/sample-macruby/HotCocoa/graphics/image-effects.rb
===================================================================
--- MacRuby/trunk/sample-macruby/HotCocoa/graphics/image-effects.rb	                        (rev 0)
+++ MacRuby/trunk/sample-macruby/HotCocoa/graphics/image-effects.rb	2009-03-07 02:09:02 UTC (rev 838)
@@ -0,0 +1,119 @@
+require 'hotcocoa/graphics'
+include HotCocoa
+include Graphics
+
+OUTFILE = 'image-effects.png'
+
+# set up the canvas
+canvas = Canvas.for_image(:size => [400,400], :filename => OUTFILE)
+canvas.background(Color.white)
+canvas.font('Skia')
+canvas.fontsize(14)
+canvas.fill(Color.black)
+
+# load image file
+img = Image.new('images/v2.jpg')
+
+# set image width/height, starting position, and increment position
+w,h = [100,100]
+x,y = [0,290]
+xoffset = 105
+yoffset = 130
+
+# ORIGINAL image, resized to fit within w,h:
+img.fit(w,h)
+canvas.draw(img,x,y)
+canvas.text("original",x,y-15)
+x += xoffset
+
+# CRYSTALLIZE: apply a "crystallize" effect with the given radius
+img.reset.fit(w,h)
+img.crystallize(5.0)
+canvas.draw(img,x,y)
+canvas.text("crystallize",x,y-15)
+x += xoffset
+
+# BLOOM: apply a "bloom" effect with the given radius and intensity
+img.reset.fit(w,h)
+img.bloom(10, 1.0)
+canvas.draw(img,x,y)
+canvas.text("bloom",x,y-15)
+x += xoffset
+
+# EDGES: detect edges
+img.reset.fit(w,h)
+img.edges(10)
+canvas.draw(img,x,y)
+canvas.text("edges",x,y-15)
+x += xoffset
+
+# (go to next row)
+x = 0
+y -= yoffset
+
+# POSTERIZE: reduce image to the specified number of colors
+img.reset.fit(w,h)
+img.posterize(8)
+canvas.draw(img,x,y)
+canvas.text("posterize",x,y-15)
+x += xoffset
+
+# TWIRL: rotate around x,y with radius and angle
+img.reset.fit(w,h)
+img.twirl(35,50,40,90)
+canvas.draw(img,x,y)
+canvas.text("twirl",x,y-15)
+x += xoffset
+
+# EDGEWORK: simulate a woodcut print
+img.reset.fit(w,h)
+canvas.rect(x,y,img.width,img.height) # needs a black background
+img.edgework(0.5)
+canvas.draw(img,x,y)
+canvas.text("edgework",x,y-15)
+x += xoffset
+
+# DISPLACEMENT: use a second image as a displacement map
+img.reset.fit(w,h)
+img2 = Image.new('images/italy.jpg').resize(img.width,img.height)
+img.displacement(img2, 30.0)
+canvas.draw(img,x,y)
+canvas.text("displacement",x,y-15)
+x += xoffset
+
+# (go to next row)
+x = 0
+y -= yoffset
+
+# DOTSCREEN: simulate a dot screen: center point, angle(0-360), width(1-50), and sharpness(0-1)
+img.reset.fit(w,h)
+img.dotscreen(0,0,45,5,0.7)
+canvas.draw(img,x,y)
+canvas.text("dotscreen",x,y-15)
+x += xoffset
+
+# SHARPEN: sharpen using the given radius and intensity
+img.reset.fit(w,h)
+img.sharpen(2.0,2.0)
+canvas.draw(img,x,y)
+canvas.text("sharpen",x,y-15)
+x += xoffset
+
+# BLUR: apply a gaussian blur with the given radius
+img.reset.fit(w,h)
+img.blur(3.0)
+canvas.draw(img,x,y)
+canvas.text("blur",x,y-15)
+x += xoffset
+
+# MOTION BLUR: apply a motion blur with the given radius and angle
+img.reset.fit(w,h)
+img.motionblur(10.0,90)
+canvas.draw(img,x,y)
+canvas.text("motion blur",x,y-15)
+x += xoffset
+
+# save the canvas
+canvas.save
+
+`open #{OUTFILE}`

Added: MacRuby/trunk/sample-macruby/HotCocoa/graphics/image-moving.rb
===================================================================
--- MacRuby/trunk/sample-macruby/HotCocoa/graphics/image-moving.rb	                        (rev 0)
+++ MacRuby/trunk/sample-macruby/HotCocoa/graphics/image-moving.rb	2009-03-07 02:09:02 UTC (rev 838)
@@ -0,0 +1,63 @@
+require 'hotcocoa/graphics'
+include HotCocoa
+include Graphics
+
+PRECISION = 0.0000001
+
+OUTFILE = 'image-moving.png'
+
+# setup the canvas
+canvas = Canvas.for_image(:size => [400,400], :filename => OUTFILE)
+canvas.background(Color.white)
+canvas.font('Skia')
+canvas.fontsize(14)
+canvas.fill(Color.black)
+canvas.stroke(Color.red)
+
+# load an image
+img = Image.new('images/v2.jpg')
+
+# SCALE (multiply both dimensions by a scaling factor)
+img.scale(0.2)
+canvas.draw(img,0,240)  # draw the image at the specified coordinates
+canvas.text("scale to 20%",0,220)
+
+# FIT (scale to fit within the given dimensions, maintaining original aspect ratio)
+img.reset               # first reset the image to its original size
+img.fit(100,100)
+canvas.fill(Color.white)
+canvas.rect(120,240,100,100)
+canvas.fill(Color.black)
+canvas.draw(img,133,240)
+canvas.text("fit into 100x100",120,220)
+
+# RESIZE (scale to fit exactly within the given dimensions)
+img.reset
+img.resize(100,100)
+canvas.draw(img,240,240)
+canvas.text("resize to 100x100",240,220)
+
+# CROP (to the largest square containing image data)
+img.reset
+img.scale(0.2).crop
+canvas.draw(img,0,100)
+canvas.text("crop max square",0,80)
+
+# CROP (within a rectangle starting at x,y with width,height)
+img.reset
+img.scale(0.3).crop(0,0,100,100)
+canvas.draw(img,120,100)
+canvas.text("crop to 100x100",120,80)
+
+# ROTATE
+img.origin(:center)
+img.rotate(45)           
+canvas.draw(img,300,140)
+canvas.text("rotate 45 degrees",250,50)
+
+#img.origin(:center)   # center the image
+#img.translate(0,-150)    # move the image
+
+canvas.save
+
+`open #{OUTFILE}`

Deleted: MacRuby/trunk/sample-macruby/HotCocoa/graphics/image.rb
===================================================================
--- MacRuby/trunk/sample-macruby/HotCocoa/graphics/image.rb	2009-03-07 01:32:13 UTC (rev 837)
+++ MacRuby/trunk/sample-macruby/HotCocoa/graphics/image.rb	2009-03-07 02:09:02 UTC (rev 838)
@@ -1,332 +0,0 @@
-#!/usr/bin/env macruby
-
-require 'hotcocoa/graphics'
-require 'test/unit'
-include HotCocoa::Graphics
-
-
-#PRECISION = 0.000000000000001
-PRECISION = 0.0000001
-
-class TestImage < Test::Unit::TestCase
-  
-  def test_image_moving
-    
-    # setup the canvas
-    File.delete('images/test-image-moving.png') if File.exists?('images/test-image-moving.png')
-    canvas = Canvas.for_image(:size => [400,400], :filename => 'images/test-image-moving.png')
-    canvas.background(Color.white)
-    canvas.font('Skia')
-    canvas.fontsize(14)
-    canvas.fill(Color.black)
-    canvas.stroke(Color.red)
-
-    # load an image
-    img = Image.new('images/v2.jpg')
-
-    # SCALE (multiply both dimensions by a scaling factor)
-    img.scale(0.2)
-    canvas.draw(img,0,240)  # draw the image at the specified coordinates
-    canvas.text("scale to 20%",0,220)
-
-    # FIT (scale to fit within the given dimensions, maintaining original aspect ratio)
-    img.reset               # first reset the image to its original size
-    img.fit(100,100)
-    canvas.fill(Color.white)
-    canvas.rect(120,240,100,100)
-    canvas.fill(Color.black)
-    canvas.draw(img,133,240)
-    canvas.text("fit into 100x100",120,220)
-
-    # RESIZE (scale to fit exactly within the given dimensions)
-    img.reset
-    img.resize(100,100)
-    canvas.draw(img,240,240)
-    canvas.text("resize to 100x100",240,220)
-
-    # CROP (to the largest square containing image data)
-    img.reset
-    img.scale(0.2).crop
-    canvas.draw(img,0,100)
-    canvas.text("crop max square",0,80)
-
-    # CROP (within a rectangle starting at x,y with width,height)
-    img.reset
-    img.scale(0.3).crop(0,0,100,100)
-    canvas.draw(img,120,100)
-    canvas.text("crop to 100x100",120,80)
-
-    # ROTATE
-    img.origin(:center)
-    img.rotate(45)           
-    canvas.draw(img,300,140)
-    canvas.text("rotate 45 degrees",250,50)
-
-    #img.origin(:center)   # center the image
-    #img.translate(0,-150)    # move the image
-
-    assert(true, canvas.save)
-    assert_equal('', `diff images/test-image-moving.png images/fixture-image-moving.png`)
-    #canvas.open
-  end
-  
-  def test_image_effects
-    # set up the canvas
-    File.delete('images/test-image-effects.png') if File.exists?('images/test-image-effects.png')
-    canvas = Canvas.for_image(:size => [400,400], :filename => 'images/test-image-effects.png')
-    canvas.background(Color.white)
-    canvas.font('Skia')
-    canvas.fontsize(14)
-    canvas.fill(Color.black)
-
-    # load image file
-    img = Image.new('images/v2.jpg')
-
-    # set image width/height, starting position, and increment position
-    w,h = [100,100]
-    x,y = [0,290]
-    xoffset = 105
-    yoffset = 130
-
-    # ORIGINAL image, resized to fit within w,h:
-    img.fit(w,h)
-    canvas.draw(img,x,y)
-    canvas.text("original",x,y-15)
-    x += xoffset
-
-    # CRYSTALLIZE: apply a "crystallize" effect with the given radius
-    img.reset.fit(w,h)
-    img.crystallize(5.0)
-    canvas.draw(img,x,y)
-    canvas.text("crystallize",x,y-15)
-    x += xoffset
-
-    # BLOOM: apply a "bloom" effect with the given radius and intensity
-    img.reset.fit(w,h)
-    img.bloom(10, 1.0)
-    canvas.draw(img,x,y)
-    canvas.text("bloom",x,y-15)
-    x += xoffset
-
-    # EDGES: detect edges
-    img.reset.fit(w,h)
-    img.edges(10)
-    canvas.draw(img,x,y)
-    canvas.text("edges",x,y-15)
-    x += xoffset
-
-    # (go to next row)
-    x = 0
-    y -= yoffset
-
-    # POSTERIZE: reduce image to the specified number of colors
-    img.reset.fit(w,h)
-    img.posterize(8)
-    canvas.draw(img,x,y)
-    canvas.text("posterize",x,y-15)
-    x += xoffset
-
-    # TWIRL: rotate around x,y with radius and angle
-    img.reset.fit(w,h)
-    img.twirl(35,50,40,90)
-    canvas.draw(img,x,y)
-    canvas.text("twirl",x,y-15)
-    x += xoffset
-
-    # EDGEWORK: simulate a woodcut print
-    img.reset.fit(w,h)
-    canvas.rect(x,y,img.width,img.height) # needs a black background
-    img.edgework(0.5)
-    canvas.draw(img,x,y)
-    canvas.text("edgework",x,y-15)
-    x += xoffset
-
-    # DISPLACEMENT: use a second image as a displacement map
-    img.reset.fit(w,h)
-    img2 = Image.new('images/italy.jpg').resize(img.width,img.height)
-    img.displacement(img2, 30.0)
-    canvas.draw(img,x,y)
-    canvas.text("displacement",x,y-15)
-    x += xoffset
-
-    # (go to next row)
-    x = 0
-    y -= yoffset
-
-    # DOTSCREEN: simulate a dot screen: center point, angle(0-360), width(1-50), and sharpness(0-1)
-    img.reset.fit(w,h)
-    img.dotscreen(0,0,45,5,0.7)
-    canvas.draw(img,x,y)
-    canvas.text("dotscreen",x,y-15)
-    x += xoffset
-
-    # SHARPEN: sharpen using the given radius and intensity
-    img.reset.fit(w,h)
-    img.sharpen(2.0,2.0)
-    canvas.draw(img,x,y)
-    canvas.text("sharpen",x,y-15)
-    x += xoffset
-
-    # BLUR: apply a gaussian blur with the given radius
-    img.reset.fit(w,h)
-    img.blur(3.0)
-    canvas.draw(img,x,y)
-    canvas.text("blur",x,y-15)
-    x += xoffset
-
-    # MOTION BLUR: apply a motion blur with the given radius and angle
-    img.reset.fit(w,h)
-    img.motionblur(10.0,90)
-    canvas.draw(img,x,y)
-    canvas.text("motion blur",x,y-15)
-    x += xoffset
-
-    # save the canvas
-    assert(true, canvas.save)
-    assert_equal('', `diff images/test-image-effects.png images/fixture-image-effects.png`)
-    #canvas.open
-  end
-  
-  def test_image_colors
-    
-    # set up the canvas
-    File.delete('images/test-image-colors.png') if File.exists?('images/test-image-colors.png')
-    canvas = Canvas.for_image(:size => [400,400], :filename => 'images/test-image-colors.png')
-    canvas.background(Color.white)
-    canvas.font('Skia')
-    canvas.fontsize(14)
-    canvas.fill(Color.black)
-
-    # LOAD IMAGE
-    img = Image.new('images/v2.jpg')
-
-    w,h = [100,100]
-    x,y = [0,290]
-    xoffset = 105
-    yoffset = 130
-
-    # ORIGINAL image, resized to fit within w,h:
-    img.fit(w,h)
-    canvas.draw(img,x,y)
-    canvas.text("original",x,y-15)
-    x += xoffset
-
-    # HUE: rotate color wheel by degrees
-    img.reset.fit(w,h)
-    img.hue(45)
-    canvas.draw(img,x,y)
-    canvas.text("hue",x,y-15)
-    x += xoffset
-    
-    # EXPOSURE: increase/decrease exposure by f-stops
-    img.reset.fit(w,h)
-    img.exposure(1.0)
-    canvas.draw(img,x,y)
-    canvas.text("exposure",x,y-15)
-    x += xoffset
-    
-    # SATURATION: adjust saturation by multiplier
-    img.reset.fit(w,h)
-    img.saturation(2.0)
-    canvas.draw(img,x,y)
-    canvas.text("saturation",x,y-15)
-    x += xoffset
-    
-    # (go to next row)
-    x = 0
-    y -= yoffset
-    
-    # CONTRAST: adjust contrast by multiplier
-    img.reset.fit(w,h)
-    img.contrast(2.0)
-    canvas.draw(img,x,y)
-    canvas.text("contrast",x,y-15)
-    x += xoffset
-    
-    # BRIGHTNESS: adjust brightness
-    img.reset.fit(w,h)
-    img.brightness(0.5)
-    canvas.draw(img,x,y)
-    canvas.text("brightness",x,y-15)
-    x += xoffset
-    
-    # MONOCHROME: convert to a monochrome image
-    img.reset.fit(w,h)
-    img.monochrome(Color.orange)
-    canvas.draw(img,x,y)
-    canvas.text("monochrome",x,y-15)
-    x += xoffset
-    
-    # WHITEPOINT: remap the white point
-    img.reset.fit(w,h)
-    img.whitepoint(Color.whiteish)
-    canvas.draw(img,x,y)
-    canvas.text("white point",x,y-15)
-    x += xoffset
-    
-    # (go to next row)
-    x = 0
-    y -= yoffset
-    
-    # CHAINING: apply multiple effects at once
-    img.reset.fit(w,h)
-    img.hue(60).saturation(2.0).contrast(2.5)
-    canvas.draw(img,x,y)
-    canvas.text("multi effects",x,y-15)
-    x += xoffset
-    
-    # COLORS: sample random colors from the image and render as a gradient
-    img.reset.fit(w,h)              # reset the image and scale to fit within w,h
-    colors = img.colors(10).sort!   # select 10 random colors and sort by brightness
-    # gradient
-    gradient = Gradient.new(colors) # create a new gradient using the selected colors
-    rect = Path.new.rect(x,y,img.width,img.height) # create a rectangle the size of the image
-    canvas.beginclip(rect)          # begin clipping so the gradient will only fill the rectangle
-    canvas.gradient(gradient,x,y,x+img.width,y+img.height) # draw the gradient between opposite corners of the rectangle
-    canvas.endclip                  # end clipping so we can draw on the rest of the canvas
-    canvas.text("get colors",x,y-15)    # add text label
-    x += xoffset
-
-    assert(true, canvas.save)
-    # hmm, can't use an image fixture if we're doing randomized things
-    # assert_equal('', `diff images/test-image-colors.png images/fixture-image-colors.png`)
-  end
-  
-  def test_image_blendmodes
-    
-    canvas = Canvas.for_image(:size => [400,730], :filename => 'images/test-image-blendmodes.png')
-    canvas.background(Color.white)
-    canvas.font('Skia')
-    canvas.fontsize(14)
-
-    # set image width,height
-    w,h = [95,95]
-
-    # set initial drawing position
-    x,y = [0,canvas.height - h - 10]
-
-    # load and resize two images
-    imgA = Image.new('images/v2.jpg').resize(w,h)
-    imgB = Image.new('images/italy.jpg').resize(w,h)
-
-    # add image B to image A using each blending mode, and draw to canvas
-    [:normal,:multiply,:screen,:overlay,:darken,:lighten,
-      :colordodge,:colorburn,:softlight,:hardlight,:difference,:exclusion,
-      :hue,:saturation,:color,:luminosity,:maximum,:minimum,:add,:atop,
-      :in,:out,:over].each do |blendmode|
-      imgA.reset.resize(w,h)
-      imgA.blend(imgB, blendmode)
-      canvas.draw(imgA,x,y)
-      canvas.text(blendmode,x,y-15)
-      x += w + 5
-      if (x > canvas.width - w + 5)
-        x = 0
-        y -= h + 25
-      end
-    end
-    canvas.save
-    
-  end
-  
-  
-end
\ No newline at end of file

Modified: MacRuby/trunk/sample-macruby/HotCocoa/graphics/iterate.rb
===================================================================
--- MacRuby/trunk/sample-macruby/HotCocoa/graphics/iterate.rb	2009-03-07 01:32:13 UTC (rev 837)
+++ MacRuby/trunk/sample-macruby/HotCocoa/graphics/iterate.rb	2009-03-07 02:09:02 UTC (rev 838)
@@ -1,45 +1,38 @@
-#!/usr/bin/env macruby
-
 require 'hotcocoa/graphics'
-require 'test/unit'
-include HotCocoa::Graphics
+include HotCocoa
+include Graphics
 
+OUTFILE = 'iterate.png'
 
-class TestIterate < Test::Unit::TestCase
-  
-  def test_iterate
+# create a new 400×400 pixel canvas to draw on
+canvas = Canvas.for_image(:size => [400,400], :filename => OUTFILE) do
+  background(Color.white)
 
-    # create a new 400×400 pixel canvas to draw on
-    canvas = Canvas.for_image(:size => [400,400], :filename => 'images/test-iterating.png') do
-      background(Color.white)
+  # create a petal shape with base at (0,0), size 40×150, and bulge at 30px
+  shape = Path.new
+  shape.petal(0,0,40,150,30)
+  # add a circle
+  shape.oval(-10,20,20,20)
+  # color it red
+  shape.fill(Color.red)
 
-      # create a petal shape with base at (0,0), size 40×150, and bulge at 30px
-      shape = Path.new
-      shape.petal(0,0,40,150,30)
-      # add a circle
-      shape.oval(-10,20,20,20)
-      # color it red
-      shape.fill(Color.red)
+  # increment shape parameters by the specified amount each iteration,
+  # or by a random value selected from the specified range
+  shape.increment(:rotation, 5.0)
+  #shape.increment(:scale, 0.95)
+  shape.increment(:scalex, 0.99)
+  shape.increment(:scaley, 0.96)
+  shape.increment(:x, 10.0)
+  shape.increment(:y, 12.0)
+  shape.increment(:hue,-0.02..0.02)
+  shape.increment(:saturation, -0.1..0.1)
+  shape.increment(:brightness, -0.1..0.1)
+  shape.increment(:alpha, -0.1..0.1)
 
-      # increment shape parameters by the specified amount each iteration,
-      # or by a random value selected from the specified range
-      shape.increment(:rotation, 5.0)
-      #shape.increment(:scale, 0.95)
-      shape.increment(:scalex, 0.99)
-      shape.increment(:scaley, 0.96)
-      shape.increment(:x, 10.0)
-      shape.increment(:y, 12.0)
-      shape.increment(:hue,-0.02..0.02)
-      shape.increment(:saturation, -0.1..0.1)
-      shape.increment(:brightness, -0.1..0.1)
-      shape.increment(:alpha, -0.1..0.1)
+  # draw 200 petals on the canvas starting at location 50,200
+  translate(50,220)
+  draw(shape,0,0,200)
+  save
+end
 
-      # draw 200 petals on the canvas starting at location 50,200
-      translate(50,220)
-      draw(shape,0,0,200)
-      save
-    end
-    
-  end
-  
-end
\ No newline at end of file
+`open #{OUTFILE}`

Modified: MacRuby/trunk/sample-macruby/HotCocoa/graphics/particle.rb
===================================================================
--- MacRuby/trunk/sample-macruby/HotCocoa/graphics/particle.rb	2009-03-07 01:32:13 UTC (rev 837)
+++ MacRuby/trunk/sample-macruby/HotCocoa/graphics/particle.rb	2009-03-07 02:09:02 UTC (rev 838)
@@ -1,76 +1,69 @@
-#!/usr/bin/env macruby
-
 require 'hotcocoa/graphics'
-require 'test/unit'
-include HotCocoa::Graphics
-
+include HotCocoa
+include Graphics
 include Math
 
-class TestParticle < Test::Unit::TestCase
-  
-  def test_particle
+OUTFILE = 'particule.png'
 
-    # initialize canvas
-    canvas = Canvas.for_image(:size => [1920,1200], :filename => 'images/test-particles.png')
-    canvas.background(Color.black)
+canvas = Canvas.for_image(:size => [1920,1200], :filename => OUTFILE)
+canvas.background(Color.black)
 
-    # load images and grab colors
-    img = Image.new('images/italy.jpg').saturation(1.9)
-    redcolors = img.colors(100)
-    img = Image.new('images/v2.jpg').saturation(1.9)
-    bluecolors = img.colors(100)
+# load images and grab colors
+img = Image.new('images/italy.jpg').saturation(1.9)
+redcolors = img.colors(100)
+img = Image.new('images/v2.jpg').saturation(1.9)
+bluecolors = img.colors(100)
 
-    # create flower head shape
-    head = Path.new.oval(0,0,10,10,:center)
-    petals = 3
-    petals.times do
-      head.rotate(360/petals)
-      head.oval(0,10,5,5,:center)
-      head.oval(0,17,2,2,:center)
-    end
-    # randomize head attributes
-    head.randomize(:fill,redcolors)
-    head.randomize(:stroke,bluecolors)
-    head.randomize(:scale,0.2..2.0)
-    head.randomize(:rotation,0..360)
+# create flower head shape
+head = Path.new.oval(0,0,10,10,:center)
+petals = 3
+petals.times do
+  head.rotate(360/petals)
+  head.oval(0,10,5,5,:center)
+  head.oval(0,17,2,2,:center)
+end
+# randomize head attributes
+head.randomize(:fill,redcolors)
+head.randomize(:stroke,bluecolors)
+head.randomize(:scale,0.2..2.0)
+head.randomize(:rotation,0..360)
 
-    # create particles
-    numparticles = 200
-    numframes = 200
-    particles = []
-    numparticles.times do |i|
-      # start particle at random point at bottom of canvas
-      x = random(canvas.width/2 - 50,canvas.width/2 + 50)
-      p = Particle.new(x,0)
-      p.velocity_x = random(-0.5,0.5)   # set initial x velocity
-      p.velocity_y = random(1.0,3.0)    # set initial y velocity
-      p.acceleration = 0.1            # set drag or acceleration
-      particles[i] = p          # add particle to array
-    end
+# create particles
+numparticles = 200
+numframes = 200
+particles = []
+numparticles.times do |i|
+  # start particle at random point at bottom of canvas
+  x = random(canvas.width/2 - 50,canvas.width/2 + 50)
+  p = Particle.new(x,0)
+  p.velocity_x = random(-0.5,0.5)   # set initial x velocity
+  p.velocity_y = random(1.0,3.0)    # set initial y velocity
+  p.acceleration = 0.1            # set drag or acceleration
+  particles[i] = p          # add particle to array
+end
 
-    # animate particles
-    numframes.times do |frame|
-      numparticles.times do |i|
-        particles[i].move
-      end
-    end
+# animate particles
+numframes.times do |frame|
+  numparticles.times do |i|
+    particles[i].move
+  end
+end
 
-    # draw particle trails and heads
-    numparticles.times do |i|
-      canvas.push
-      # choose a stem color
-      color = choose(bluecolors).a(0.7).analog(20,0.7)
-      canvas.stroke(color)
-      canvas.strokewidth(random(0.5,2.0))
-      # draw the particle
-      particles[i].draw(canvas)
-      # go to the last particle position and draw the flower head
-      canvas.translate(particles[i].points[-1][0],particles[i].points[-1][1])
-      canvas.draw(head)
-      canvas.pop
-    end
+# draw particle trails and heads
+numparticles.times do |i|
+  canvas.push
+  # choose a stem color
+  color = choose(bluecolors).a(0.7).analog(20,0.7)
+  canvas.stroke(color)
+  canvas.strokewidth(random(0.5,2.0))
+  # draw the particle
+  particles[i].draw(canvas)
+  # go to the last particle position and draw the flower head
+  canvas.translate(particles[i].points[-1][0],particles[i].points[-1][1])
+  canvas.draw(head)
+  canvas.pop
+end
 
-    canvas.save   
-  end
-  
-end
\ No newline at end of file
+canvas.save
+
+`open #{OUTFILE}`

Modified: MacRuby/trunk/sample-macruby/HotCocoa/graphics/pdf.rb
===================================================================
--- MacRuby/trunk/sample-macruby/HotCocoa/graphics/pdf.rb	2009-03-07 01:32:13 UTC (rev 837)
+++ MacRuby/trunk/sample-macruby/HotCocoa/graphics/pdf.rb	2009-03-07 02:09:02 UTC (rev 838)
@@ -1,8 +1,6 @@
-#!/usr/bin/env macruby
-
 require 'hotcocoa/graphics'
-require 'test/unit'
-include HotCocoa::Graphics
+include HotCocoa
+include Graphics
 
 
 class TestPdf < Test::Unit::TestCase
@@ -45,4 +43,4 @@
     GC.start
   end
 
-end
\ No newline at end of file
+end

Modified: MacRuby/trunk/sample-macruby/HotCocoa/graphics/randomize.rb
===================================================================
--- MacRuby/trunk/sample-macruby/HotCocoa/graphics/randomize.rb	2009-03-07 01:32:13 UTC (rev 837)
+++ MacRuby/trunk/sample-macruby/HotCocoa/graphics/randomize.rb	2009-03-07 02:09:02 UTC (rev 838)
@@ -1,46 +1,40 @@
 #!/usr/bin/env macruby
-
 require 'hotcocoa/graphics'
-require 'test/unit'
-include HotCocoa::Graphics
+include HotCocoa
+include Graphics
 
+OUTFILE = 'randomize.png'
 
-class TestRandomize < Test::Unit::TestCase
-  
-  def test_randomize
+# create a new 400×400 pixel canvas to draw on
+canvas = Canvas.for_image(:size => [400,400], :filename => OUTFILE)
+canvas.background(Color.white)
 
-    # create a new 400×400 pixel canvas to draw on
-    canvas = Canvas.for_image(:size => [400,400], :filename => 'images/test-randomize.png')
-    canvas.background(Color.white)
+# create a flower shape
+shape = Path.new
+petals = 5
+for i in 1..petals do
+  shape.petal(0, 0, 40, 100)       # petal at x,y with width,height
+  shape.rotate(360 / petals)       # rotate by 1/5th
+end
 
-    # create a flower shape
-    shape = Path.new
-    petals = 5
-    for i in 1..petals do
-      shape.petal(0,0,40,100)       # petal at x,y with width,height
-      shape.rotate(360 / petals)    # rotate by 1/5th
-    end
+# randomize shape parameters
+shape.randomize(:fill, Color.blue.complementary)
+shape.randomize(:stroke, Color.blue.complementary)
+shape.randomize(:strokewidth, 1.0..10.0)
+shape.randomize(:rotation, 0..360)
+shape.randomize(:scale, 0.5..1.0)
+shape.randomize(:scalex, 0.5..1.0)
+shape.randomize(:scaley, 0.5..1.0)
+shape.randomize(:alpha, 0.5..1.0)
+# shape.randomize(:hue, 0.5..0.8)
+shape.randomize(:saturation, 0.0..1.0)
+shape.randomize(:brightness, 0.0..1.0)
+shape.randomize(:x, -100.0..100.0)
+shape.randomize(:y, -100.0..100.0)
 
-    # randomize shape parameters
-    shape.randomize(:fill, Color.blue.complementary)
-    shape.randomize(:stroke, Color.blue.complementary)
-    shape.randomize(:strokewidth, 1.0..10.0)
-    shape.randomize(:rotation, 0..360)
-    shape.randomize(:scale, 0.5..1.0)
-    shape.randomize(:scalex, 0.5..1.0)
-    shape.randomize(:scaley, 0.5..1.0)
-    shape.randomize(:alpha, 0.5..1.0)
-    # shape.randomize(:hue, 0.5..0.8)
-    shape.randomize(:saturation, 0.0..1.0)
-    shape.randomize(:brightness, 0.0..1.0)
-    shape.randomize(:x, -100.0..100.0)
-    shape.randomize(:y, -100.0..100.0)
+# draw 50 flowers starting at the center of the canvas
+canvas.translate(200, 200)
+canvas.draw(shape, 0, 0, 100)
+canvas.save
 
-    # draw 50 flowers starting at the center of the canvas
-    canvas.translate(200,200)
-    canvas.draw(shape,0,0,100)
-    canvas.save
-    
-  end
-  
-end
\ No newline at end of file
+`open #{OUTFILE}`

Added: MacRuby/trunk/sample-macruby/HotCocoa/graphics/rope-hair.rb
===================================================================
--- MacRuby/trunk/sample-macruby/HotCocoa/graphics/rope-hair.rb	                        (rev 0)
+++ MacRuby/trunk/sample-macruby/HotCocoa/graphics/rope-hair.rb	2009-03-07 02:09:02 UTC (rev 838)
@@ -0,0 +1,36 @@
+require 'hotcocoa/graphics'
+include HotCocoa
+include Graphics
+
+OUTFILE = 'rope-hair.png'
+
+# initialize the canvas
+canvas = Canvas.for_image(:size => [400,400], :filename => OUTFILE)
+
+# choose a random color and set the background to a darker variant
+clr = Color.random.a(0.5)
+canvas.background(clr.copy.darken(0.6))
+
+# create a new rope with 200 fibers
+rope = Rope.new(canvas, :width => 100, :fibers => 200, :strokewidth => 0.4, :roundness => 3.0)
+
+# randomly rotate the canvas from its center
+canvas.translate(canvas.width/2, canvas.height/2)
+canvas.rotate(random(0, 360))
+canvas.translate(-canvas.width/2, -canvas.height/2)
+
+# draw 20 ropes
+ropes = 20
+ropes.times do
+  canvas.stroke(clr.copy.analog(20, 0.8))   # rotate hue up to 20 deg left/right, vary brightness/saturation by up to 70%
+  rope.x0 = -100                            # start rope off bottom left of canvas
+  rope.y0 = -100
+  rope.x1 = canvas.width + 100              # end rope off top right of canvas
+  rope.y1 = canvas.height + 100
+  rope.hair                                 # draw rope in organic “hair” style
+end
+
+# save the canvas
+canvas.save
+
+`open #{OUTFILE}`

Added: MacRuby/trunk/sample-macruby/HotCocoa/graphics/rope-ribbon.rb
===================================================================
--- MacRuby/trunk/sample-macruby/HotCocoa/graphics/rope-ribbon.rb	                        (rev 0)
+++ MacRuby/trunk/sample-macruby/HotCocoa/graphics/rope-ribbon.rb	2009-03-07 02:09:02 UTC (rev 838)
@@ -0,0 +1,36 @@
+require 'hotcocoa/graphics'
+include HotCocoa
+include Graphics
+
+OUTFILE = 'rope-ribbon.png'
+
+# initialize the canvas
+canvas = Canvas.for_image(:size => [400,400], :filename => OUTFILE)
+
+# choose a random color and set the background to a darker variant
+clr = Color.random.a(0.5)
+canvas.background(clr.copy.darken(0.6))
+
+# create a new rope with 200 fibers
+rope = Rope.new(canvas, :width => 500, :fibers => 200, :strokewidth => 1.0, :roundness => 1.5)
+
+# randomly rotate the canvas from its center
+canvas.translate(canvas.width/2, canvas.height/2)
+canvas.rotate(random(0, 360))
+canvas.translate(-canvas.width/2, -canvas.height/2)
+
+# draw 20 ropes
+ropes = 20
+ropes.times do |i|
+   canvas.stroke(clr.copy.analog(10, 0.7))   # rotate hue up to 10 deg left/right, vary brightness/saturation by up to 70%
+   rope.x0 = -100                            # start rope off bottom left of canvas
+   rope.y0 = -100
+   rope.x1 = canvas.width + 200              # end rope off top right of canvas
+   rope.y1 = canvas.height + 200
+   rope.ribbon                               # draw rope in smooth “ribbon” style
+end
+
+# save the canvas
+canvas.save
+
+`open #{OUTFILE}`

Deleted: MacRuby/trunk/sample-macruby/HotCocoa/graphics/rope.rb
===================================================================
--- MacRuby/trunk/sample-macruby/HotCocoa/graphics/rope.rb	2009-03-07 01:32:13 UTC (rev 837)
+++ MacRuby/trunk/sample-macruby/HotCocoa/graphics/rope.rb	2009-03-07 02:09:02 UTC (rev 838)
@@ -1,81 +0,0 @@
-#!/usr/bin/env macruby
-
-require 'hotcocoa/graphics'
-require 'test/unit'
-include HotCocoa::Graphics
-
-
-class TestRope < Test::Unit::TestCase
-  
-  def test_rope_hair
-
-    # initialize the canvas
-    canvas = Canvas.for_image(:size => [400,400], :filename => 'images/test-rope-hair.png')
-
-    # choose a random color and set the background to a darker variant
-    clr = Color.random.a(0.5)
-    canvas.background(clr.copy.darken(0.6))
-
-    # create a new rope with 200 fibers
-    rope = Rope.new(canvas, :width => 100, :fibers => 200, :strokewidth => 0.4, :roundness => 3.0)
-
-    # randomly rotate the canvas from its center
-    canvas.translate(canvas.width/2,canvas.height/2)
-    canvas.rotate(random(0,360))
-    canvas.translate(-canvas.width/2,-canvas.height/2)
-
-    # draw 20 ropes
-    ropes = 20
-    ropes.times do
-      canvas.stroke(clr.copy.analog(20, 0.8))   # rotate hue up to 20 deg left/right, vary brightness/saturation by up to 70%
-      rope.x0 = -100                            # start rope off bottom left of canvas
-      rope.y0 = -100
-      rope.x1 = canvas.width + 100              # end rope off top right of canvas
-      rope.y1 = canvas.height + 100
-      rope.hair                                 # draw rope in organic “hair” style
-    end
-
-    # save the canvas
-    canvas.save
-    
-  end
-  
-  
-  def test_rope_ribbon
-    
-    # initialize the canvas
-    canvas = Canvas.for_image(:size => [400,400], :filename => 'images/test-rope-ribbon.png')
-
-    # choose a random color and set the background to a darker variant
-    clr = Color.random.a(0.5)
-    canvas.background(clr.copy.darken(0.6))
-
-    # create a new rope with 200 fibers
-    rope = Rope.new(canvas, :width => 500, :fibers => 200, :strokewidth => 1.0, :roundness => 1.5)
-
-    # randomly rotate the canvas from its center
-    canvas.translate(canvas.width/2,canvas.height/2)
-    canvas.rotate(random(0,360))
-    canvas.translate(-canvas.width/2,-canvas.height/2)
-
-    # draw 20 ropes
-    ropes = 20
-    for i in 0..ropes do
-        canvas.stroke(clr.copy.analog(10, 0.7))   # rotate hue up to 10 deg left/right, vary brightness/saturation by up to 70%
-        rope.x0 = -100                            # start rope off bottom left of canvas
-        rope.y0 = -100
-        rope.x1 = canvas.width + 200              # end rope off top right of canvas
-        rope.y1 = canvas.height + 200
-        rope.ribbon                               # draw rope in smooth “ribbon” style
-    end
-
-    # save the canvas
-    canvas.save
-    
-  end
-  
-  
-  
-  
-  
-end
\ No newline at end of file

Modified: MacRuby/trunk/sample-macruby/HotCocoa/graphics/text.rb
===================================================================
--- MacRuby/trunk/sample-macruby/HotCocoa/graphics/text.rb	2009-03-07 01:32:13 UTC (rev 837)
+++ MacRuby/trunk/sample-macruby/HotCocoa/graphics/text.rb	2009-03-07 02:09:02 UTC (rev 838)
@@ -1,37 +1,31 @@
 #!/usr/bin/env macruby
-
 require 'hotcocoa/graphics'
-require 'test/unit'
-include HotCocoa::Graphics
+include HotCocoa
+include Graphics
 
+OUTFILE = 'spirograph.png'
 
-class TestText < Test::Unit::TestCase
-  
-  def test_text_spirograph
-    
-    # set up the canvas and font
-    canvas = Canvas.for_image(:size => [400,400], :filename => 'images/test-text-spirograph.png') do
-      background(Color.beige)
-      fill(Color.black)
-      font('Book Antiqua')
-      fontsize(12)
-      translate(200,200)
+# set up the canvas and font
+canvas = Canvas.for_image(:size => [400,400], :filename => OUTFILE) do
+  background(Color.beige)
+  fill(Color.black)
+  font('Book Antiqua')
+  fontsize(12)
+  translate(200,200)
 
-      # rotate, draw text, repeat
-      180.times do |frame|
-        new_state do
-          rotate((frame*2) + 120)
-          translate(70,0)
-          text('going...', 80, 0)
-          rotate(frame * 6)
-          text('Around and', 20, 0)
-        end
-      end
+  # rotate, draw text, repeat
+  180.times do |frame|
+    new_state do
+      rotate((frame*2) + 120)
+      translate(70,0)
+      text('going...', 80, 0)
+      rotate(frame * 6)
+      text('Around and', 20, 0)
     end
-
-    # save the canvas
-    canvas.save
-    
   end
-  
-end
\ No newline at end of file
+end
+
+# save the canvas
+canvas.save
+
+`open #{OUTFILE}`
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090306/046f3522/attachment-0001.html>


More information about the macruby-changes mailing list