Sha256: 469c4be65e3c1e65eb9b6bd6c51db400cb132a52b62d6f916bbfe1fdda478290
Contents?: true
Size: 693 Bytes
Versions: 6
Compression:
Stored size: 693 Bytes
Contents
# Sine Wave # by Daniel Shiffman. # # Render a simple sine wave. def setup size 640, 360 frame_rate 30 color_mode RGB, 255, 255, 255, 100 @w = width + 16 @period = 500.0 @x_spacing = 8 @dx = (TAU / @period) * @x_spacing @y_values = [] @theta = 0.0 @amplitude = 75.0 end def draw background 0 calc_wave draw_wave end def calc_wave @theta += 0.02 x = @theta (0...(@w/@x_spacing)).each do |i| @y_values[i] = sin(x) * @amplitude x += @dx end end def draw_wave no_stroke fill 255, 50 ellipse_mode CENTER @y_values.each_with_index do |v, x| ellipse x*@x_spacing, height/2+v, 16, 16 end end
Version data entries
6 entries across 6 versions & 1 rubygems