July 2nd, 2008

You can use various Photoshop-style blend modes to composite two or more images by applying the “blend” method to an Image object.
require 'hotcocoa/graphics'
include HotCocoa
include Graphics
canvas = Canvas.new :type => :image, :filename => 'blend.png', :size => [400,730]
canvas.background(Color.white)
canvas.font('Skia')
canvas.fontsize(14)
w,h = [95,95]
x,y = [0,canvas.height - h - 10]
imgA = Image.new('v2.jpg').resize(w,h)
imgB = Image.new('italy.jpg').resize(w,h)
for blendmode in [:normal,:multiply,:screen,:overlay,:darken,:lighten,
:colordodge,:colorburn,:softlight,:hardlight,:difference,:exclusion,
:hue,:saturation,:color,:luminosity,:maximum,:minimum,:add,:atop,
:in,:out,:over] do
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
Posted in Examples, Images | No Comments »
June 30th, 2008

Radial or linear gradients may be drawn by first specifying their main constituent colors, then applying to the canvas with a start and endpoint. (warning: crashes in MacRuby 0.4)
require 'hotcocoa/graphics'
include HotCocoa
include Graphics
canvas = Canvas.new :type => :image, :filename => 'gradients.png', :size => [400,400]
canvas.background(Color.black)
gradient = Gradient.new
gradient.set(Color.black,Color.blue,Color.red.darken,Color.orange)
canvas.gradient(gradient, 50,50,200,200)
gradient.pre(false)
gradient.post(false)
canvas.radial(gradient, 200,200,100)
canvas.save
Posted in Color, Examples | No Comments »
June 30th, 2008

You can load an image, grab an array of colors from it, and then apply those colors to other objects on the canvas.
require 'hotcocoa/graphics'
include HotCocoa
include Graphics
canvas = Canvas.new :type => :image, :filename => 'parsing.png', :size => [400,400]
canvas.background(Color.black)
canvas.shadow
image = Image.new('italy.jpg')
randomcolors = image.colors(100)
square = Path.new.rect(0,0,20,20,:center)
square.randomize(:fill, randomcolors)
square.randomize(:scale, 1.0..5.0)
square.randomize(:rotation, 0..360)
canvas.grid(square,10,10)
image.fit(120,120)
canvas.draw(image)
canvas.save
Posted in Color, Examples | No Comments »
June 29th, 2008

Various sets of colors can be generated from a single starting color by using the various classical color harmony schemes. For more information, see Color Theory on Wikipedia.
require 'hotcocoa/graphics'
include HotCocoa
include Graphics
canvas = Canvas.new :type => :image, :filename => 'harmony.png', :size => [400,400]
canvas.background(Color.white)
canvas.font('Skia')
canvas.fontsize(12)
blue = Color.new(0.0,0.4,0.6,1.0)
canvas.translate(135,350)
canvas.text("original color",-115,10)
canvas.fill(blue)
canvas.rect(0,0,255,30)
canvas.fill(Color.black)
swatch = Path.new.rect(0,0,15,30)
swatch.increment(:x, 15)
for scheme in [
:complementary,:split_complementary,:left_complement,
:right_complement,:monochrome,:triad,:tetrad,:compound,
:flipped_compound
] do
canvas.translate(0,-38)
canvas.text(scheme,-115,10)
swatch.increment(:fill, blue.send(scheme).sort)
canvas.draw(swatch,0,0,17)
end
canvas.save
Posted in Color, Examples | 1 Comment »