Last active
April 3, 2017 04:55
-
-
Save tterrag1098/b6caa8655a72159115634d1012543918 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 3, | |
3, 12, 12, 3, 3, 12, 12, 12, 3, 12, 13, 13, 12, 10, 12, 12, 5, 12, 12, 12, 12, 3, | |
3, 12, 12, 3, 12, 3, 12, 12, 3, 12, 13, 12, 12, 10, 10, 12, 5, 5, 5, 12, 12, 3, | |
3, 12, 12, 3, 3, 12, 12, 3, 12, 12, 13, 13, 12, 10, 12, 12, 5, 12, 5, 12, 12, 3, | |
3, 12, 12, 3, 12, 3, 12, 3, 12, 12, 13, 12, 12, 10, 10, 12, 5, 5, 5, 12, 12, 3, | |
3, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 3, | |
3, 12, 12, 12, 12, 12, 12, 12, 12, 12, 3, 3, 12, 12, 12, 12, 12, 12, 12, 12, 12, 3, | |
3, 12, 12, 12, 12, 12, 12, 12, 3, 3, 1, 2, 3, 3, 12, 12, 12, 12, 12, 12, 12, 3, | |
3, 12, 12, 12, 12, 12, 12, 3, 2, 1, 1, 1, 2, 2, 3, 12, 12, 12, 12, 12, 12, 3, | |
3, 12, 12, 12, 12, 12, 3, 1, 2, 1, 2, 2, 1, 2, 2, 3, 12, 12, 12, 12, 12, 3, | |
3, 12, 12, 12, 12, 12, 3, 1, 1, 1, 1, 1, 1, 2, 2, 3, 12, 12, 12, 12, 12, 3, | |
3, 12, 12, 12, 12, 3, 1, 2, 2, 1, 1, 2, 2, 2, 2, 2, 3, 12, 12, 12, 12, 3, | |
3, 12, 12, 12, 12, 3, 2, 1, 1, 1, 2, 1, 1, 2, 2, 2, 3, 12, 12, 12, 12, 3, | |
3, 12, 12, 12, 12, 3, 2, 1, 1, 2, 2, 1, 2, 2, 2, 2, 3, 12, 12, 12, 12, 3, | |
3, 12, 12, 12, 12, 12, 3, 2, 2, 1, 1, 2, 2, 2, 2, 3, 12, 12, 12, 12, 12, 3, | |
3, 12, 12, 12, 12, 12, 12, 3, 3, 2, 2, 2, 2, 3, 3, 12, 12, 12, 12, 12, 12, 3, | |
3, 12, 12, 12, 12, 12, 12, 12, 12, 3, 3, 3, 3, 12, 12, 12, 12, 12, 12, 12, 12, 3, | |
3, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 3, | |
3, 12, 12, 12, 12, 12, 12, 12, 3, 3, 12, 12, 12, 3, 3, 12, 12, 12, 12, 12, 12, 3, | |
3, 12, 12, 12, 12, 12, 12, 3, 6, 6, 3, 12, 3, 6, 6, 3, 12, 12, 12, 12, 12, 3, | |
3, 3, 3, 3, 3, 3, 3, 5, 6, 5, 6, 3, 6, 8, 6, 6, 3, 3, 3, 3, 3, 3, | |
-1, -1, -1, -1, -1, -1, 3, 5, 8, 6, 5, 5, 6, 8, 8, 5, 3, -1, -1, -1, -1, -1, | |
-1, -1, -1, -1, -1, -1, 3, 5, 8, 6, 5, 6, 8, 8, 8, 5, 3, -1, -1, -1, -1, -1, | |
-1, -1, -1, -1, -1, -1, -1, 3, 6, 8, 6, 5, 8, 8, 5, 3, -1, -1, -1, -1, -1, -1, | |
-1, -1, -1, -1, -1, -1, -1, -1, 3, 6, 8, 8, 8, 5, 3, -1, -1, -1, -1, -1, -1, -1, | |
-1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 5, 8, 5, 3, -1, -1, -1, -1, -1, -1, -1, -1, | |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 5, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
]; | |
var colorsABGR = []; | |
var balance = { | |
x: 492, | |
y: 726, | |
width: 22, | |
height: 29 | |
}; | |
var placed = 0; | |
// hooks | |
var client; | |
var canvasse; | |
var jQuery; | |
var test = 0; | |
r.placeModule("Balance", 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 { | |
drawTestBalance(); | |
} | |
}); | |
function attempt(){ | |
var unbalancedPixels = []; | |
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]]){ | |
unbalancedPixels = unbalancedPixels.concat(i); | |
console.log("Identified a wrong pixel, #" + i); | |
} | |
} | |
if (unbalancedPixels.length > 0) { | |
var pixToFix = unbalancedPixels[Math.floor(Math.random() * unbalancedPixels.length)]; | |
console.log("Found " + unbalancedPixels.length + " wrong tiles. Fixing one (# " + pixToFix + ")"); | |
var targetPoint = getPoint(pixToFix); | |
client.setColor(colors[pixToFix]); | |
client.drawTile(targetPoint.x, targetPoint.y); | |
console.log('Pixel Placed at: (' + targetPoint.x + ',' + targetPoint.y + ')'); | |
} else { | |
console.log("Found no wrong tiles. Waiting..."); | |
} | |
} | |
setTimeout(attempt, toWait + Math.round(Math.random() * 10000)); | |
} | |
function drawTestBalance(){ | |
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 % balance.width; | |
return { | |
x: balance.x + x, | |
y: balance.y + (i - x) / balance.width - balance.height | |
}; | |
} | |
function getPixel(x, y){ | |
return canvasse.writeBuffer[canvasse.getIndexFromCoords(x, y)]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment