# effect/heathazeeffect (vanilla-engine 0.4.0)

> https://vanillapunch.com/docs/vanilla-engine/0.4.0/api/effect/heathazeeffect/

Heat haze effect component. (HeatHazeEffect of the original effect/heathazeeffect.js)
- Copies what was drawn on screen before this node, as large as the node area, and redraws it shaking each row left and right along a sine curve.
  So it shows only when attached to a node drawn at the top (last) of the scene. Child nodes are drawn over the effect.
- Like the original, it flushes the batch, copies the node's screen area (pixels) into a texture with copyTexSubImage2D, and draws one quad per row as vertex color quads (draw_colored_quads).
  When the node area goes off screen, the edge pixels of the screen are stretched. (CLAMP_TO_EDGE)
- Like the original, it is a component attached to a node, and sets the node content_size to 300 x 300 when attached if it is empty.
- Differences from the original:
  - The copied texture is a GL resource, so call destroy() when done. Like the original it holds the context that made the texture (a weak handle) so it takes no argument,
    and it also deletes it by itself when the component is dropped (Drop, when the node is removed or the scene is unloaded). (same as ScreenEffect)
  - When a row exceeds the vertex count that can be drawn at once (the Graphic limit), it is drawn in parts. The original grows the array and draws at once.

## HeatHazeEffect (struct) (Default, Drop, Component)

Heat haze effect component.
- Attached to the node drawn last. Pushes the screen drawn before it in that node's area left and right per row by sin(clock + row y x frequency) x amplitude.

Example: Attach to a node and set the amplitude and frequency

```rust
use vanilla::{HeatHazeEffect, NodeTree, Vector2};

let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let haze_id = node_tree.create_child(root_id, "HeatHaze");
let heat_haze_effect = node_tree.add_component(haze_id, HeatHazeEffect::new()).expect("heat haze");
heat_haze_effect.set_amplitude(6.0);
heat_haze_effect.set_frequency(0.08);
assert_eq!(heat_haze_effect.calculate_row_offset(0.0), 0.0);
assert!(heat_haze_effect.calculate_row_offset(10.0).abs() <= 6.0);
assert_eq!(node_tree[haze_id].get_content_size(), Vector2::create(300.0, 300.0));
```

- `pub fn new() -> HeatHazeEffect` (constructor, since 0.3.2): Creates. (speed 2, amplitude 3, frequency 0.05)
  - returns HeatHazeEffect: An effect with the clock at 0 and no copied texture.
- `pub fn set_speed(&mut self, value: f64)` (method, since 0.3.2): Sets the speed.
  - `value` f64: Speed at which the sway clock runs. (radians per second, advances by time_delta x speed every tick. default 2)
- `pub fn get_speed(&self) -> f64` (method, since 0.3.2): Returns the speed.
  - returns f64: Speed at which the sway clock runs. (radians per second)
- `pub fn set_amplitude(&mut self, value: f64)` (method, since 0.3.2): Sets the intensity.
  - `value` f64: Largest amplitude a row is pushed left or right. (node coordinate pixels, default 3)
- `pub fn get_amplitude(&self) -> f64` (method, since 0.3.2): Returns the strength.
  - returns f64: Largest amplitude a row is pushed left or right. (node coordinate pixels)
- `pub fn set_frequency(&mut self, value: f64)` (method, since 0.3.2): Sets the frequency.
  - `value` f64: Frequency multiplied by the row position. (radians per vertical node pixel, larger means denser waves. default 0.05)
- `pub fn get_frequency(&self) -> f64` (method, since 0.3.2): Returns the frequency.
  - returns f64: Frequency multiplied by the row position. (radians per vertical node pixel)
- `pub fn get_timer(&self) -> f64` (method, since 0.3.2): Returns the sway clock. (advances by time_delta * speed every tick)
  - returns f64: Sway clock. (radians, initially 0)
- `pub fn calculate_row_offset(&self, local_y: f64) -> f64` (method, since 0.3.2): Horizontal wobble of a line. (sin(clock + line position * frequency) * amplitude)
  - `local_y` f64: Node local y of the row. (top of the node is 0)
  - returns f64: x distance to push the row. (node coordinates, -amplitude ~ amplitude)
- `pub fn destroy(&mut self)` (method, since 0.3.2): Releases GL resources. (the copied texture, the original destroy)
  - Also called by itself when dropped (Drop). If the GL context is already gone, the texture is gone with it, so it only forgets it.
