Using Ruby Time in JRubyArt
Color of fill from day of year:-
attr_reader :hue
def settings
full_screen
# pixel_density(2) # for hidpi displays only
end
def setup
text_size(height / 5)
text_align(CENTER)
color_mode(HSB, 360, 1, 1)
@hue = Time.now.yday % 360 # Using ruby Time it is so easy
end
def draw
background(0)
fill(hue, 1, 1) # hue depends on day of year when started
text('Hola Mundo!', width / 2, height / 2)
end
Cycle over 18 colors according to elapsed seconds
def settings
full_screen
# pixel_density(2) # for hidpi displays only
end
def setup
text_size(height / 5)
text_align(CENTER)
color_mode(HSB, 360, 1, 1)
end
def draw
hue = (Time.now.sec % 18) * 20 # Using ruby Time is so easy
background(0)
fill(hue, 1, 1) # 18 different hues depends on sec
text('Hola Mundo!', width / 2, height / 2)
end
Day of Week as a boolean
WEEKEND ||= 'Yes' # define WEEKEND unless defined already
WEEKDAY ||= 'No' # use this form when 'watch'-ing a sketch
attr_reader :weekend
def settings
size 200, 150
end
def setup
sketch_title 'Weekend?'
@weekend = weekend? ? WEEKEND : WEEKDAY
text_size(48)
text_align(CENTER)
end
def draw
background(0)
fill(200)
text(weekend, width / 2, height / 2)
end
# for atheists and christians, jews and muslims can agree to disagree
# mais aussi Ministère de la Culture France traditionnellement n'est-ce pas?
# a method that returns a boolean (substitute friday? for sunday? whatever!!)
def weekend?
t = Time.now
(t.saturday? || t.sunday?) # no need for explicit return in ruby
end