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

Friday, 5 July 2013

Setting texture sampling ruby-processing-2.0

Here is a little pixel manipulation sketch that uses and off screen image for efficiency:-
# Taken from processing discussion board, a little sketch by Amnon Owed
# Illustrates use of offscreen image, texture sampling, mouse_pressed?,
# load_pixels, displayWidth and displayHeight (do not snake case the last two)

SCALE = 5
attr_reader :grid
COLOR_RANGE = 16581375 # 255 * 255 * 255

def setup
  size(displayWidth, displayHeight, P2D)
  @grid = create_image(width/SCALE, height/SCALE, RGB)
  g.texture_sampling(2)       # 2 = POINT mode sampling
end

def draw
  unless mouse_pressed?
    grid.load_pixels
    grid.pixels.length.times do |i|
      grid.pixels[i] = rand(COLOR_RANGE)
    end
    grid.update_pixels
  end
  image(grid, 0, 0, width, height)
  frame.set_title("#{frame_rate.to_i}+ fps")
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