class Particle attr_accessor :x, :y def initialize(x, y) @x, @y = x, y end end
show require 'ruby2d' set width: 800, height: 600
svg.rect(x: 0, y: 0, width: '100%', height: '100%', fill: '#111')
draw_circle(400, 300, 250, 1) show require 'ruby2d' require 'ruby_noise' # gem install ruby_noise set width: 800, height: 600, fps_cap: 30
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
show a) Recursive circles (Apollonian-like) require 'ruby2d' set width: 800, height: 600, background: 'black'
500.times particles << Particle.new(rand(800), rand(600))
Browse our fantastic teaching materials. Here you can find our wonderful educational resources for Finland.