Sha256: 705f7aab7aa4f16821268451291dd59900dc5a1a40cb4893af3cf74d32d04a38
Contents?: true
Size: 1.22 KB
Versions: 6
Compression:
Stored size: 1.22 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 = PVector.from_angle(a) v.mult(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 = PVector.from_angle(a) r.mult(4) r.add(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
6 entries across 6 versions & 1 rubygems