How to resolve the algorithm Color wheel step by step in the FutureBasic programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Color wheel step by step in the FutureBasic programming language

Table of Contents

Problem Statement

Write a function to draw a HSV color wheel completely with code. This is strictly for learning purposes only. It's highly recommended that you use an image in an actual application to actually draw the color wheel   (as procedurally drawing is super slow). This does help you understand how color wheels work and this can easily be used to determine a color value based on a position within a circle.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Color wheel step by step in the FutureBasic programming language

Source code in the futurebasic programming language

_window = 1
begin enum output 1
  _colorwheelImageView
end enum

void local fn BuildWindow
  CGRect  r = fn CGRectMake( 0, 0, 400, 400 )
  window _window, @"Programmatic Color Wheel", r, NSWindowStyleMaskTitled + NSWindowStyleMaskClosable
  
  r = fn CGRectMake( 20, 20, 360, 360 )
  imageview _colorwheelImageView, YES, , r, NSImageScaleProportionallyUpOrDown, NSImageAlignCenter, NSImageFrameNone, _window
end fn

local fn CIImageToImageRef( ciImage as CIImageRef ) as ImageRef
  CIImageRepRef rep = fn CIImageRepWithCIImage( ciImage )
  CGSize       size = fn ImageRepSize( rep )
  ImageRef    image = fn ImageWithSize( size )
  ImageAddRepresentation( image, rep )
end fn = image

local fn ColorWheelImage( colorSpace as CGColorSpaceRef, dither as CFNumberRef, radius as CFNumberRef, softness as CFNumberRef, lightness as CFNumberRef ) as CIImageRef
  CIFilterRef filter = fn CIFilterWithName( @"CIHueSaturationValueGradient" )
  ObjectSetValueForkey( filter, colorSpace, @"inputColorSpace" )
  ObjectSetValueForkey( filter, dither,     @"inputDither"     )
  ObjectSetValueForkey( filter, radius,     @"inputRadius"     )
  ObjectSetValueForkey( filter, softness,   @"inputSoftness"   )
  ObjectSetValueForkey( filter, lightness,  @"inputValue"      )
  CIImageRef outputCIImage = fn CIFilterOutputImage( filter )
end fn = outputCIImage

local fn BuildColorWheel
  CIImageRef colorWheelCIImage = fn ColorWheelImage( fn CGColorSpaceCreateDeviceRGB, @0, @160, @0, @1 )
  ImageRef   colorWheelImage   = fn CIImageToImageRef( colorWheelCIImage )
  ImageViewSetImage( _colorwheelImageView, colorWheelImage )
end fn

fn BuildWindow
fn BuildColorWheel

HandleEvents

  

You may also check:How to resolve the algorithm Sort three variables step by step in the RPL programming language
You may also check:How to resolve the algorithm Sequence of non-squares step by step in the Fortran programming language
You may also check:How to resolve the algorithm Pascal matrix generation step by step in the Racket programming language
You may also check:How to resolve the algorithm Sequence of non-squares step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm String case step by step in the Seed7 programming language