void local fn HueToRGB( hue as double, sat as double, buffer as ptr ) double x int c = 255 * sat hue /= 60.0 x = (1 - abs((hue % 2) - 1)) * 255 xref p(1) as unsigned char p = buffer select ( fix(hue) ) case 0 : p(0) = c : p(1) = x : p(2) = 0 case 1 : p(0) = x : p(1) = c : p(2) = 0 case 2 : p(0) = 0 : p(1) = c : p(2) = x case 3 : p(0) = 0 : p(1) = x : p(2) = c case 4 : p(0) = x : p(1) = 0 : p(2) = c case 5 : p(0) = c : p(1) = 0 : p(2) = x end select end fn ImageRef local fn CreateImage int size = 512, i, j ptr colors = fn malloc( size * 3 ) ptr pix = fn malloc( size * size * 3 ) for i = 0 to size - 1 fn HueToRGB( i * 240.0 / size, i * 1.0 / size, (ptr)(colors + 3 * i) ) next for i = 0 to size - 1 for j = 0 to size - 1 fn memcpy( pix + ( ( i * size + j ) * 3 ), colors + ( ( i ^^ j ) * 3 ), 3 ) next next BitmapImageRepRef bitmap = fn BitmapImageRepWithBitmapDataPlanes( @pix, size, size, 8, 3, NO, NO, NSCalibratedRGBColorSpace, 3 * size, 24 ) ImageRef image = fn ImageWithSize( fn CGSizeMake(size,size) ) ImageAddRepresentation( image, bitmap ) free( colors ) free( pix ) end fn = image void local fn DoIt window 1, @"Munching squares", (0,0,512,512) imageview 1,,, (0,0,512,512) ViewSetAutoresizingMask( 1, NSViewWidthSizable | NSViewHeightSizable ) ImageRef image = fn CreateImage imageview 1,, image end fn fn DoIt HandleEvents