Skip to content

Instantly share code, notes, and snippets.

@nddrylliog
Last active August 29, 2015 13:57
Show Gist options
  • Save nddrylliog/9403338 to your computer and use it in GitHub Desktop.
Save nddrylliog/9403338 to your computer and use it in GitHub Desktop.

Revisions

  1. nddrylliog revised this gist Mar 7, 2014. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion 00_rules.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    There's an IS_DEV global variable that'll give you access to Game. Don't use it.

    Read canvas pixels instead, it's much funnier! This gist should contain all you need.
    Read canvas pixels instead, it's much funnier! This gist should contain all you need.

    Keyboard shortcuts are blocked on the page, use right click -> instead to open the inspector.
  2. nddrylliog revised this gist Mar 7, 2014. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions 00_rules.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    There's an IS_DEV global variable that'll give you access to Game. Don't use it.

    Read canvas pixels instead, it's much funnier! This gist should contain all you need.
  3. nddrylliog renamed this gist Mar 7, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. nddrylliog revised this gist Mar 7, 2014. 4 changed files with 11 additions and 4 deletions.
    4 changes: 4 additions & 0 deletions 01_flap.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    $('canvas').keydown()

    // apparently 'click' doesn't work, but keydown works fine.
    // might want to cache $('canvas') into $canvas or similar for performance.
    File renamed without changes.
    3 changes: 0 additions & 3 deletions flap.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +0,0 @@
    $('canvas').keydown()

    // apparently 'click' doesn't work.
    8 changes: 7 additions & 1 deletion grab_pixels.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,10 @@
    var data = $('canvas')[0].getContext("2d").getImageData(0, 0, 800, 512)

    // data.width and data.height are 800 and 512
    // data.data is a native RGBA uint8 array, origin is top-left
    // data.data is a native RGBA uint8 array, origin is top-left
    // getting pixel at x, y could be done with:

    var r = data.data[(x + y * data.width) * 4 + 0];
    var g = data.data[(x + y * data.width) * 4 + 1];
    var b = data.data[(x + y * data.width) * 4 + 2];
    var a = data.data[(x + y * data.width) * 4 + 3];
  5. nddrylliog created this gist Mar 7, 2014.
    18 changes: 18 additions & 0 deletions detect_pipes.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    // the color of a pipe boundary is (84, 56, 72)
    // apparently red = 84 is unique anywhere else on canvas

    for (var x = 0; x < data.width; x++) {
    var red = data.data[x * 4];
    if (red != 84) {
    continue
    }
    console.log("pipe x = ", x);
    for (var y = 0; y < data.height; y++) {
    var red2 = data.data[(x + y * data.width) * 4];
    if (red2 == 84) {
    console.log("pipe y = ", y);
    continue
    }
    break
    }
    }
    3 changes: 3 additions & 0 deletions flap.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    $('canvas').keydown()

    // apparently 'click' doesn't work.
    4 changes: 4 additions & 0 deletions grab_pixels.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    var data = $('canvas')[0].getContext("2d").getImageData(0, 0, 800, 512)

    // data.width and data.height are 800 and 512
    // data.data is a native RGBA uint8 array, origin is top-left