Weird Attractors

Weird Attractors

A glitch by obscure variable names.

Demo: http://shuheikagawa.com/attractors/
Code: https://github.com/shuhei/attractors

Ca0ab6e450f894e06652ee257df9d647?s=128

Shuhei Kagawa

March 18, 2016
Tweet

Transcript

  1. 2.
  2. 4.

    Strange Attractors x' = x * sin(a * x) +

    cos(b * y) y' = y * sin(c * y) + cos(d * z) z' = z * sin(e * z) + cos(f * x)
  3. 5.

    x' = x * sin(a * x) + cos(b *

    y) y' = y * sin(c * y) + cos(d * z) z' = z * sin(e * z) + cos(f * x)
  4. 6.

    function calc(vertices, iterations, a, b, c, d, e, f) {

    // variable declarations // ... for (var i = 0; i < iterations; i++) { xNew = x * Math.sin(a * x) + Math.cos(b * y); yNew = y * Math.sin(c * y) + Math.cos(d * z); zNew = z * Math.sin(e * z) + Math.cos(f * x); x = xNew; y = yNew; z = zNew; vertices[i * 3] = x; vertices[i * 3 + 1] = y; vertices[i * 3 + 2] = z; } } Code
  5. 7.
  6. 9.
  7. 10.
  8. 11.
  9. 12.
  10. 13.
  11. 14.
  12. 15.
  13. 16.
  14. 17.
  15. 18.
  16. 19.
  17. 20.

    function calc(vertices, iterations, a, b, c, d, e, f) {

    // variable declarations // ... for (var i = 0; i < iterations; i++) { xNew = x * Math.sin(a * x) + Math.cos(b * y); yNew = y * Math.sin(c * y) + Math.cos(d * z); zNew = z * Math.sin(e * z) + Math.cos(f * x); x = xNew; y = yNew; z = zNew; vertices[i * 3] = x; vertices[i * 3 + 1] = y; vertices[i * 3 + 2] = z; } } Before
  18. 21.

    function calc(vertices, iterations, a, b, c, d, e, f) {

    // variable declarations for (var i = 0; i < iterations; i++) { xNew = x * Math.sin(a * x) + Math.cos(b * y); yNew = y * Math.sin(c * y) + Math.cos(d * z); zNew = z * Math.sin(e * z) + Math.cos(f * x); x = xNew; y = yNew; z = zNew; r = /* snip */; g = /* snip */; b = /* snip */; vertices[i * 6] = x; vertices[i * 6 + 1] = y; vertices[i * 6 + 2] = z; vertices[i * 6 + 3] = r; vertices[i * 6 + 4] = g; vertices[i * 6 + 5] = b; } } Adding color...
  19. 22.

    Obscure variable names // NG p = 123; a =

    2; t = p * a; // OK price = 123; amount = 2; total = price * amount;