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.
FlappyParty AI project - play at http://www.flappyparty.com/

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.

Keyboard shortcuts are blocked on the page, use right click -> instead to open the inspector.

$('canvas').keydown()
// apparently 'click' doesn't work, but keydown works fine.
// might want to cache $('canvas') into $canvas or similar for performance.
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
// 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];
// 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
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment