Thinking about ruby-2.0 and structure got me thinking about processing color, but then I though about Struct and OStruct, as easy way to add structure to these processing sketches, see how this gives meaning to fill for example:-
Hue
require 'ostruct'
attr_reader :bar_width, :color_array
def setup
size 640, 360
color_mode HSB, 360
no_stroke
@bar_width = 20
@color_array = (0..width / bar_width).map do
OpenStruct.new(hue: height, saturation: height, brightness: height)
end
end
def draw
color_array.each_with_index do |col, i|
n = i * bar_width
range = (n..n + bar_width)
color_array[i].hue = mouse_y if range.include?(mouse_x)
fill col.hue, col.saturation, col.brightness
rect n, 0, bar_width, height
end
end
Saturation
require 'ostruct'
attr_reader :bar_width, :color_array
def setup
size 640, 360
color_mode HSB, 360
no_stroke
@bar_width = 20
@color_array = (0..width / bar_width).map do |n|
OpenStruct.new(hue: n * bar_width, saturation: height, brightness: height / 1.5)
end
end
def draw
color_array.each_with_index do |col, i|
n = i * bar_width
range = (n..n + bar_width)
color_array[i].saturation = mouse_y if range.include? mouse_x
fill col.hue, col.saturation, col.brightness
rect n, 0, bar_width, height
end
end
Brightness
require 'ostruct'
attr_reader :bar_width, :color_array
def setup
size 640, 360
no_stroke
color_mode HSB, width, 100, height
@bar_width = 20
@color_array = (0..width / bar_width).map do |n|
OpenStruct.new(hue: n * bar_width, saturation: 100, brightness: height)
end
end
def draw
color_array.each_with_index do |col, i|
n = i * bar_width
range = (n..n + bar_width)
color_array[i].brightness = mouse_y if range.include? mouse_x
fill col.hue, col.saturation, col.brightness
rect n, 0, bar_width, height
end
end