Sha256: 8e782e8c09c45da8ca0e95ed31bb0632738018ef04797aa4acc8173ffb1265da

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

# encoding: utf-8
# frozen_string_literal: true
require 'propane'
# Linear Image.
#
# Click and drag mouse up and down to control the signal.
#
# Note in ruby-processing to access booleans use
#       mouse_pressed? and key_pressed?
#
# Press and hold any key to view the image scanning
class LinearImage < Propane::App
  attr_reader :signal, :img, :direction

  def setup
    size(640, 360)
    stroke(255)
    @img = loadImage('sea.jpg')
    @direction = 1
    @signal = 0
    img.load_pixels
    load_pixels
  end

  def draw
    @direction = direction * -1 if signal > img.height - 1 || signal < 0
    if mouse_pressed?
      @signal = (mouse_y % img.height).abs
    else
      @signal += (0.3 * direction)
    end
    if key_pressed?
      set(0, 0, img)
      line(0, signal, img.width, signal)
    else
      signal_offset = signal.to_i * img.width
      (0...img.height).each do |y|
        java.lang.System.arraycopy(
          img.pixels.to_java,
          signal_offset,
          pixels,
          y * width,
          img.width
        )
      end
      update_pixels
    end
  end
end

LinearImage.new title: 'Linear Image'

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
propane-0.7.0-java examples/complete/linear_image.rb
propane-0.6.0-java examples/complete/linear_image.rb