Slide 1

Slide 1 text

Weird Attractors A glitch by obscure variable names Shuhei Kagawa

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

webgl-workshop

Slide 4

Slide 4 text

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)

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

Demo

Slide 8

Slide 8 text

Suddenly became interesting when I added color

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

Demo

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

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...

Slide 22

Slide 22 text

Obscure variable names // NG p = 123; a = 2; t = p * a; // OK price = 123; amount = 2; total = price * amount;

Slide 23

Slide 23 text

'use strict'; const b = 10; b = 123; console.log(b); // 10 Use const

Slide 24

Slide 24 text

Thanks! • shuheikagawa.com • Twitter @shuheikagawa • GitHub @shuhei