Sha256: 82e5ccefea4b731064b327b1025c303c6e92040d2ac0b838f240ff3f3d84aeda

Contents?: true

Size: 987 Bytes

Versions: 4

Compression:

Stored size: 987 Bytes

Contents

#
# Pixel Array. 
# 
# Click and drag the mouse up and down to control the signal and 
# press and hold any key to see the current pixel being read. 
# This program sequentially reads the color of every pixel of an image
# and displays this color to fill the window.  
#

 

attr_reader :signal, :img, :direction

def setup
  size(640, 360)
  no_fill
  stroke(255)
  frame_rate(30)
  @img = load_image("sea.jpg")
  @direction = 1
  @signal = 0
end

def draw
  if (signal > img.width * img.height - 1 || signal < 0)
    @direction = direction * -1 
  end

  if (mousePressed) 
    mx = constrain(mouse_x, 0, img.width-1)
    my = constrain(mouse_y, 0, img.height-1)
    @signal = my * img.width + mx
  else 
    @signal += 0.33 * direction
  end

  sx = signal.to_i % img.width
  sy = signal.to_i / img.width

  if (keyPressed) 
    set(0, 0, img)  # fast way to draw an image
    point(sx, sy)
    rect(sx - 5, sy - 5, 10, 10)
  else 
    c = img.get(sx, sy)
    background(c)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ruby-processing-2.4.4 samples/processing_app/topics/image_processing/pixel_array.rb
ruby-processing-2.4.3 samples/processing_app/topics/image_processing/pixel_array.rb
ruby-processing-2.4.2 samples/processing_app/topics/image_processing/pixel_array.rb
ruby-processing-2.4.1 samples/processing_app/topics/image_processing/pixel_array.rb