Experiments with ruby-processing (processing-2.2.1) and JRubyArt for processing-3.0

Wednesday, 28 October 2009

HSB color palette in ruby processing

For some reason the default color palette in the context free ruby-processing DSL has been set to HSB mode (sensible in keeping with the context free HSB model). However the default range in the DSL version is set as 1 not the 360 as for vanilla context free, now that is also fair enough. But it means you need to keep your wits about you when dealing with the numbers, because you are now dealing with float as opposed to int and we all know what mayhem that can cause (particularly important when your creating a float from an int by division). Also unless you want a lot of black around, you will need to set the brightness and saturation levels to something sensible. Here is a ruby sketch exploring HSB colors in the range 0 to 1.0. Should you wish to use integer color values in your ruby-processing context free DSL, I think you may need to edit the context-free.rb script, you may find that setting the color_mode in the setup is not good enough, well at least thats what I found!!!

require 'ruby-processing'

def setup
  size 400, 400
  color_mode HSB, 1, 1, 1, 1
  20.times do |i|
    20.times do |j|
      col = (i + j)/40.0 # NB use of float divisor
      fill col, 0.9, 0.9 # NB need sat and brightness
      rect i*20, j*20, 20, 20



About Me

My photo
I have developed JRubyArt and propane new versions of ruby-processing for JRuby- and processing-3.2.2