Sha256: e4643a0c896d333f3d4fb5989e3ce93baed98ebe3b32d12eb2831174b3fc2c6c
Contents?: true
Size: 838 Bytes
Versions: 4
Compression:
Stored size: 838 Bytes
Contents
require 'ruby-processing' class Pixels2dSketch < Processing::App def setup # load the pixels array load_pixels # Two loops allow us to visit every column (x) and every row (y). # Loop through every pixel column width.times do |x| # Loop through every pixel row height.times do |y| # Use the formula to find the 1D location # The location in the pixel array is calculated via our formula: 1D pixel location = x + y * width loc = x + y * width # We use the even-or-odd-ness of the column number (x) to determine whether the color should be black or white. pixels[loc] = (x % 2 == 0) ? color(255) : color(0) end end # update the pixels on screen update_pixels end end Pixels2dSketch.new :title => "Pixels 2d", :width => 200, :height => 200
Version data entries
4 entries across 4 versions & 1 rubygems