The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Color Donut with Cairo

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
Color Donut with Cairo Posted: Jul 8, 2006 2:04 PM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: Color Donut with Cairo
Feed Title: Travis Griggs - Blog
Feed URL: http://www.cincomsmalltalk.com/rssBlog/travis-rss.xml
Feed Description: This TAG Line is Extra
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Travis Griggs - Blog

Advertisement

Alpha-Hue Circle Gradient More Cairo fun. This is really just a variant of my last post on the same subject. It uses a radial gradient in both the alpha channel and the hue spectrum. What is more signficant, is that the code to do this has all been "reified" so that doing it is starting to look like Smalltalk code, instead of a bunch of DLLCC invocations.

diameter := 128.
data := CIntegerType unsignedChar gcCalloc: diameter * 4 * diameter.
surface := ImageSurface 
			format: #alphaColor
			extent: diameter asPoint
			usingBits: data
			stride: diameter * 4.
center := surface extent half.
radius := diameter half asDouble.
colorGradient := RadialGradient 
			from: center
			radius: 0
			to: center
			radius: radius.
0 to: radius
	do: 
		[:n | 
		colorGradient addStopAt: n / radius
			colorValue: (ColorValue hue: n / radius)].
alphaGradient := RadialGradient 
			from: center
			radius: 0
			to: center
			radius: radius.
alphaGradient addStopAt: 0 alpha: 0.
alphaGradient addStopAt: 0.5 alpha: 1.
alphaGradient addStopAt: 1 alpha: 0.
cc := surface context.
cc source: colorGradient.
cc mask: alphaGradient.
surface saveAsPng: '/home/travis/cairo_circle.png'

The one unfortunate aspect currently is that for whatever reason, I have to use an ImageSurface where I've allocated the memory locally. Otherwise, the image comes out with undefined artifacts.

Read: Color Donut with Cairo

Topic: I've Been Published (Again) Previous Topic   Next Topic Topic: Agile Development and DSM at XP2006

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use