Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Weird Attractors

Weird Attractors

A glitch by obscure variable names.

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

Shuhei Kagawa

March 18, 2016
Tweet

More Decks by Shuhei Kagawa

Other Decks in Programming

Transcript

  1. 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)
  2. 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. 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
  4. 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
  5. 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...
  6. Obscure variable names // NG p = 123; a =

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