Sha256: ac0239f81cc1aa996593430c2b6bcaa14266b7b8f543f5e81d76e2867104f5fc
Contents?: true
Size: 1.21 KB
Versions: 3
Compression:
Stored size: 1.21 KB
Contents
# An object that wraps the PShape class Wiggler include Processing::Proxy attr_reader :original, :x, :y, :s, :yoff, :xoff def initialize width, height @x = width/2 @y = height/2 @yoff = 0 # The "original" locations of the vertices make up a circle @original = [] (0 ... TAU).step(0.2) do |a| v = Vec2D.from_angle(a) v *= 100 original << v end # Now make the PShape with those vertices @s = create_shape s.begin_shape s.fill(127) s.stroke(0) s.stroke_weight(2) original.each do |v| s.vertex(v.x, v.y) end s.end_shape(CLOSE) end def wiggle @xoff = 0 # Apply an offset to each vertex (0 ... s.get_vertex_count).each do |i| # Calculate a new vertex location based on noise around "original" location pos = original[i] a = TAU*noise(xoff,yoff) r = Vec2D.from_angle(a) r *= 4 r += pos # Set the location of each vertex to the new one s.set_vertex(i, r.x, r.y) # increment perlin noise x value @xoff += 0.5 end # Increment perlin noise y value @yoff += 0.02 end def display push_matrix translate(x, y) shape(s) pop_matrix end end
Version data entries
3 entries across 3 versions & 1 rubygems