Sha256: 79514133a5217675962a747a04375f34bfd112366da391ae705c4525b8489b55

Contents?: true

Size: 894 Bytes

Versions: 5

Compression:

Stored size: 894 Bytes

Contents

#  * An array is a list of data. Each piece of data in an array 
#  * is identified by an index number representing its position in 
#  * the array. Arrays are zero based, which means that the first 
#  * element in the array is [0], the second element is [1], and so on. 
#  * In this example, an array named "coswav" is created and
#  * filled with the cosine values. This data is displayed three 
#  * separate ways on the screen.  



def setup
  size 640, 360
  coswave = []
  
  0.upto( width ) do |i|
    amount = map i, 0, width, 0, PI
    coswave[i] = cos( amount ).abs
  end
  
  0.upto( width ) do |i|
    stroke( coswave[i] * 255 )
    line i, 0, i, height/3
  end
  
  0.upto( width ) do |i|
    stroke( coswave[i] * 255 / 4 )
    line i, height/3, i, height/3*2
  end
  
  0.upto( width ) do |i|
    stroke( 255 - coswave[i] * 255 )
    line i, height/3*2, i, height
  end
  
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ruby-processing-2.5.0 samples/processing_app/basics/arrays/array.rb
ruby-processing-2.4.4 samples/processing_app/basics/arrays/array.rb
ruby-processing-2.4.3 samples/processing_app/basics/arrays/array.rb
ruby-processing-2.4.2 samples/processing_app/basics/arrays/array.rb
ruby-processing-2.4.1 samples/processing_app/basics/arrays/array.rb