Ruby Sketch [portable] -

show require 'ruby2d' set title: "Interactive Sketch"

Run: ruby test.rb a) Drawing primitives (Ruby2D) require 'ruby2d' set width: 800, height: 600, background: 'black' Shapes Circle.new(x: 200, y: 200, radius: 80, sectors: 32, color: 'red') Rectangle.new(x: 400, y: 100, width: 150, height: 150, color: 'blue') Line.new(x: 0, y: 500, x2: 800, y2: 400, width: 5, color: 'lime') Triangle.new(x1: 600, y1: 400, x2: 700, y2: 500, x3: 500, y3: 500, color: 'yellow') ruby sketch

Run: ruby sketch.rb Draw. Experiment. Break things. Repeat. show require 'ruby2d' set title: "Interactive Sketch" Run:

on :key_down do |event| clear if event.key == 'c' end Repeat

100.times do Circle.new( x: rand(800), y: rand(600), radius: rand(5..30), color: ['red', 'green', 'blue', 'yellow', 'purple'].sample, opacity: rand(0.3..0.8) ) end

def draw_circle(x, y, radius, depth) return if depth > 5 || radius < 2 Circle.new(x: x, y: y, radius: radius, color: "hsl(#depth * 60, 100%, 50%)") draw_circle(x + radius/2, y, radius/2, depth + 1) draw_circle(x - radius/2, y, radius/2, depth + 1) draw_circle(x, y + radius/2, radius/2, depth + 1) end

on :mouse_down do |event| Circle.new(x: event.x, y: event.y, radius: 10, color: 'fuchsia') @points << [event.x, event.y] end