Skip to content

Instantly share code, notes, and snippets.

@jawdatls
Created May 10, 2018 09:24
Show Gist options
  • Save jawdatls/ec96f20e9b41d1955ba97e3f1e07e253 to your computer and use it in GitHub Desktop.
Save jawdatls/ec96f20e9b41d1955ba97e3f1e07e253 to your computer and use it in GitHub Desktop.
Shape Grid Calculation
// Base
let w = width; // shape width
let h = height; // shape height
let r = row; // grid row start by 0
let c = column; // grid column start by 0
// Square
let left = r * w; // transform left position
let top = j * h; // transform top position
// Diamond
let left = ((r%2) * (-1) * (w/2)) + (c * w); // transform left position
let top = (r * h/2) - (h/2); // transform top position
// Hexagonal
let left = ((r%2) * (-1) * (w/2)) + (c * w); // transform left position
let top = (r * 3 * h/4) - (h/2); // transform top position
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment