Experiments with ruby-processing (processing-2.2.1) and JRubyArt for processing-3.0

Saturday 13 July 2013

Another 10 PRINT sketch translated to ruby-processing

Catch the live version here.
#####################
#                                      #
#    10 PRINT - Stacked 3D Version     #
#                                      #
#####################

# original by bit.craft

W = 400   # canvas size
N = 10    # number of grid cells
D = W/N   # diameter of a grid cell
DPT = 0.5 # relative cell depth

def setup
  size W, W, P3D
  rect_mode CENTER
  background 255
  stroke_weight 3
end

def draw
  # get coordinates
  xy = frame_count % (N*N)
  # shift image in z-direction
  if (xy == 0)
    img = get
    background 255
    push_matrix
    translate 0, 0, -D * DPT
    fill 204
    no_stroke
    image img, 0, 0
    pop_matrix
  end

  # scale and rotate the square
  scale D
  translate (xy % N) + 0.5, (xy/N).to_i + 0.5, - DPT * 0.5
  rotate_z QUARTER_PI - HALF_PI * rand(2)
  rotate_x HALF_PI

  # draw the square
  stroke 0
  fill 255
  rect 0, 0, sqrt(2), DPT
end

No comments:

Post a Comment

Followers

Blog Archive

About Me

My photo
I have developed JRubyArt and propane new versions of ruby-processing for JRuby-9.1.5.0 and processing-3.2.2