Class: SparkleMotion::Nodes::Generators::Perlin

Inherits:
SparkleMotion::Nodes::Generator show all
Defined in:
lib/sparkle_motion/nodes/generators/perlin.rb

Overview

Manage and run a Perlin-noise based simulation.

TODO: Play with octaves / persistence, etc.

Constant Summary

Constants inherited from SparkleMotion::Node

SparkleMotion::Node::DEBUG_SCALE, SparkleMotion::Node::FRAME_PERIOD

Instance Attribute Summary

Attributes inherited from SparkleMotion::Node

#debug, #history, #lights

Instance Method Summary collapse

Methods inherited from SparkleMotion::Node

#[], #[]=, #snapshot_to!

Constructor Details

#initialize(lights:, speed:) ⇒ Perlin

Returns a new instance of Perlin.



10
11
12
13
14
15
# File 'lib/sparkle_motion/nodes/generators/perlin.rb', line 10

def initialize(lights:, speed:)
  super(lights: lights)
  @speed  = speed
  # TODO: See if we need/want to tinker with the `interval` option...
  @perlin = ::Perlin::Noise.new(2, seed: 0)
end

Instance Method Details

#update(t) ⇒ Object



17
18
19
20
21
22
# File 'lib/sparkle_motion/nodes/generators/perlin.rb', line 17

def update(t)
  @lights.times do |n|
    self[n] = @perlin[n * @speed.x, t * @speed.y]
  end
  super(t)
end