ruby-processingでProcessing->Examples->Basic->TransFormの写経
写経してみたw;
case :TriangleFlower when :TriangleFlower class Point attr_accessor :x,:y def initialize x,y @x,@y = x,y end end def setup @shift = 1.0 @fade = 0 @fill_col = 0 @rot = 0 @spin = 0 size 200,200 background 0 smooth @p = Array.new @fade = 255.0/(width/2.0/@shift) @spin = 360.0/(width/2.0/@shift) @p << Point.new(-width/2, height/2) @p << Point.new(width/2, height/2) @p << Point.new(0, -height/2) no_stroke translate width/2,height/2 tri_blur no_loop end def draw end def tri_blur fill @fill_col @fill_col += @fade rotate @spin triangle @p[0].x+=@shift,@p[0].y-=@shift/2, @p[1].x-=@shift,@p[1].y-=@shift/2, @p[2].x,@p[2].y+=@shift tri_blur if @p[0].x <0 end when :Translate def setup @x = 0 @size = 40.0 size 200,200 no_stroke frame_rate 30 end def draw background 102 @x += 0.8 @x = -@size if @x > (width+@size) translate @x,height/2-@size/2 fill 255 rect -@size/2,-@size/2,@size,@size translate @x,@size fill 0 rect -@size/2,-@size/2,@size,@size end when :Scale def setup size 200,200 no_stroke rect_mode CENTER frame_rate 30 @a = @s = 0.0 end def draw background 102 @a += 0.04 @s = cos(@a) * 2 translate width/2, height/2 scale @s#width/2,height/2を中心にスケール、0で中心に潰れて、マイナスの時反転 fill 51 rect 0,0,50,50 translate 75,0 fill 255 scale @s rect 0,0,50,50 end when :Rotate def setup size 200,200 no_stroke fill 255 frame_rate 30 @angle = 0 @jitter = 0 end def draw background 102 @jitter = random(-0.1,0.1) if (second % 2) == 0 @angle += @jitter translate width/2, height/2 rotate(cos(@angle)) rect_mode CENTER rect 0,0,115,115 end when :Arm def setup @x,@y = 50,100 @angle1 = @angle2 = 0.0 @seg_length = 50 size 200,200 smooth stroke_weight 20.0 stroke 0,100 end def draw background 226 @angle1 = (mouse_x/width.to_f - 0.5) * -PI @angle2 = (mouse_y/height.to_f - 0.5) * PI push_matrix segment @x,@y,@angle1 segment @seg_length,0,@angle2 pop_matrix end def segment x,y,a translate x,y rotate a line 0,0, @seg_length,0 end end
TriangleFlowerがruby-processingとProcessingで一寸形が違っているw;