Sha256: 6216f5e64d846612a18b7cb38ab6bb50da2ad1365a94a498b4ecf86b9165a57a

Contents?: true

Size: 1.07 KB

Versions: 5

Compression:

Stored size: 1.07 KB

Contents

# Triangle Flower 
# by Ira Greenberg. 
# 
# Using rotate() and triangle() functions generate a pretty 
# flower. Uncomment the line "# rotate(rot+=radians(spin));"
# in the triBlur() function for a nice variation.

attr_reader :pt, :shift, :spin, :fade

def setup    
  size 200, 200    
  background 0
  @fill_color = 0.0
  @shift = 1.0
  @rot = 0.0
  @fade = 255.0 / (width / 2.0 / shift)
  @spin = 360.0 / (width / 2.0 / shift)    
  @pt = []
  pt << Point.new(-width / 2.0, height / 2.0)
  pt << Point.new(width / 2.0, height / 2.0)  
  pt << Point.new(0.0, -height / 2.0)   
  no_stroke
  translate width/2, height/2    
  while pt[0].x < 0 do
    tri_blur
	end
end

def tri_blur    
  fill @fill_color
  @fill_color += fade  	
  rotate spin  	
  # try these lines also ..
  #@rot += radians spin
  #rotate @rot  	
  pt[0].x += shift
  pt[0].y -= shift / 2
  pt[1].x -= shift
  pt[1].y -= shift / 2
  pt[2].y += shift  	
  triangle pt[0].x, pt[0].y, pt[1].x, pt[1].y, pt[2].x, pt[2].y
end



class Point    
	attr_accessor :x, :y
	
	def initialize (x, y)	    
		@x, @y = x, y
	end	
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ruby-processing-2.5.0 samples/processing_app/basics/transform/triangle_flower.rb
ruby-processing-2.4.4 samples/processing_app/basics/transform/triangle_flower.rb
ruby-processing-2.4.3 samples/processing_app/basics/transform/triangle_flower.rb
ruby-processing-2.4.2 samples/processing_app/basics/transform/triangle_flower.rb
ruby-processing-2.4.1 samples/processing_app/basics/transform/triangle_flower.rb