Sha256: fa7990dc2cac809c77528411bc05aa654bc294add70ccca9571e5a0459316287
Contents?: true
Size: 1.02 KB
Versions: 11
Compression:
Stored size: 1.02 KB
Contents
# The Nature of Code # Daniel Shiffman # http://natureofcode.com class Blanket extend Forwardable def_delegators(:@app, :width) attr_reader :particles, :springs, :physics def initialize(physics) @app = $app @particles = [] @springs = [] w = 20 h = 20 len = 10 strength = 0.125 h.times do |y| w.times do |x| p = Particle.new(TVec2D.new(width / 2 + x * len - w * len / 2, y * len)) physics.add_particle(p) particles << p if x > 0 previous = particles[particles.size - 2] c = Connection.new(p, previous, len, strength) physics.add_spring(c) springs << c end if y > 0 above = particles[particles.size - w - 1] c = Connection.new(p, above, len, strength) physics.add_spring(c) springs << c end end end topleft = particles[0] topleft.lock topright = particles[w - 1] topright.lock end def display springs.each(&:display) end end
Version data entries
11 entries across 11 versions & 1 rubygems