Skip to content

Instantly share code, notes, and snippets.

@jdtaylor
Created April 3, 2017 16:23
Show Gist options
  • Save jdtaylor/4be9fdc4b99946820ce28dea03289bb5 to your computer and use it in GitHub Desktop.
Save jdtaylor/4be9fdc4b99946820ce28dea03289bb5 to your computer and use it in GitHub Desktop.
Texas flag at new location for reddit's /r/place
var colors = [
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3,
3, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3,
3, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3,
3, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3,
3, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3,
3, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3,
3, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3,
3, 13, 13, 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, 5, 5, 5, 5, 3,
3, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 3,
3, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 3,
3, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 3,
3, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 3,
3, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
];
var colorsABGR = [];
var flag = {
x: 371, // Remember the Alamo!
y: 136,
width: 35,
height: 24
};
var placed = 0;
// hooks
var client;
var canvasse;
var jQuery;
var test = false;
r.placeModule("TexasFlag", function(e){
client = e("client");
canvasse = e("canvasse");
jQuery = e("jQuery");
for(var i=0; i<client.palette.length; i++){
colorsABGR[i] = client.getPaletteColorABGR(i);
}
// Start
if(!test){
attempt();
} else {
//getCurrentFlag();
drawTestFlag();
}
});
function attempt(){
var badPixels = [];
var toWait = client.getCooldownTimeRemaining();
if(toWait===0){
for(var i=0; i<colors.length; i++){
if(colors[i] === -1){
continue;
}
var targetPoint = getPoint(i);
var pixelColor = getPixel(targetPoint.x, targetPoint.y);
if(pixelColor !== colorsABGR[colors[i]]){
badPixels = badPixels.concat(i);
var pt = getPoint(i);
var clr = findPalette(pixelColor);
console.log("Bad pixel @ (" + (pt.x - flag.x) + "," + (pt.y - flag.y) + ")" + " color: " + clr);
}
}
if(badPixels.length > 0) {
var pixToFix = badPixels[Math.floor(Math.random() * badPixels.length)];
var targetPoint = getPoint(pixToFix);
client.setColor(colors[pixToFix]);
client.drawTile(targetPoint.x, targetPoint.y);
console.log('Texas pixel placed at: (' + targetPoint.x + ',' + targetPoint.y + ')');
}
}
setTimeout(attempt, toWait + Math.round(Math.random() * 1500));
}
function drawTestFlag(){
for(var i=0; i<colors.length; i++){
if(colors[i] === -1){
continue;
}
var targetPoint = getPoint(i);
canvasse.drawTileAt(targetPoint.x, targetPoint.y, colorsABGR[colors[i]]);
}
}
function getPoint(i){
var x = i % flag.width;
return {
x: flag.x + x,
y: flag.y + (i - x) / flag.width
};
}
function getPixel(x, y){
return canvasse.writeBuffer[canvasse.getIndexFromCoords(x, y)];
}
function findPalette(c){
for(var i = 0; i < colorsABGR.length; i++){
if(c === colorsABGR[i]){
return i;
}
}
return 0;
}
function getCurrentFlag(){
for(var y = 0; y < flag.height; y++){
var line = "";
for(var x = 0; x < flag.width; x++){
line += findPalette(getPixel(flag.x + x, flag.y + y)) + ", ";
}
console.log(line);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment