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,8,8,8,3,8,8,8,3,8,3,8,3,3,3,8,3,3,3,8,8,3,8,8,8,8,3,8,8,8,3,3,3,8,3,3,3,8,3,8,3,8,3,3,3,8,3,8,8,3,8,3,3,3,8,3,8,8,3,8,3,3,3,8,3,8,3,8,3,3,8,8,8,3,
- 3,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,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,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,3,3,3,3,3,3,3,3,
- ];
- var colorsABGR = [];
- var image = {
- x: 281,
- y: 648,
- width: 79,
- height: 9
- };
- var perfect_timeout = 60;
- //update timeout for poor reddit servers (ms)
- var get_delay = 500;
- var use_skipping = false;
- var skipping_max = 20;
- var client;
- var canvasse;
- var jQuery;
- var currentDrawPosition = 2;
- var currentLoop = 0;
- r.placeModule("image", 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);
- }
- startup();
- });
- function startup()
- {
- console.log("skipping to first wrong pixel");
- var toWait = client.getCooldownTimeRemaining();
- for(var i = currentDrawPosition; i < image.width*image.height; i++){
- if(colors[i] === -1){
- continue;
- }
- var targetPoint = getPoint(i);
- var pixelColor = getPixel(targetPoint.x, targetPoint.y);
- if(pixelColor !== colorsABGR[colors[i]]){
- currentDrawPosition = i;
- console.log("starting at " + currentDrawPosition);
- break;
- }
- }
- setTimeout(attempt, toWait + Math.round(Math.random() * 1500));
- }
- function attempt(){
- console.log("tried to draw");
- var toWait = client.getCooldownTimeRemaining();
- if(toWait === 0)
- {
- tryDrawPixel();
- }
- else
- {
- setTimeout(attempt, toWait + Math.round(Math.random() * 1500));
- console.log("set a timeout");
- }
- }
- function tryDrawPixel()
- {
- var toWait = client.getCooldownTimeRemaining();
- if(toWait === 0 && currentLoop < image.width*image.height)
- {
- currentLoop++;
- console.log("checking pixel " + currentDrawPosition);
- var targetPoint = getPoint(currentDrawPosition);
- $.get( "/api/place/pixel.json", { x:targetPoint.x, y:targetPoint.y }, function( data )
- {
- setTimeout(function() {
- //wait an extra half second for reddits servers
- console.log("x" + targetPoint.x + " y"+ targetPoint.y);
- if (data.color == undefined)
- data.color = 0;
- canvasse.drawTileAt(data.x, data.y, colorsABGR[data.color]);
- if (colors[currentDrawPosition] != data.color && colors[currentDrawPosition] !== -1)
- {
- client.setColor(colors[currentDrawPosition]);
- client.drawTile(targetPoint.x, targetPoint.y);
- console.log("drew pixel at " + targetPoint.x + "/" + targetPoint.y);
- var toWait = client.getCooldownTimeRemaining();
- setTimeout(attempt, toWait + Math.round(Math.random() * 1500));
- currentLoop = 0;
- console.log("set a timeout");
- }
- else
- {
- var positionIncrease = 1;
- if (use_skipping == true)
- {
- positionIncrease = Math.floor(Math.random() * (Math.min(0.2*currentLoop, skipping_max))) + 1;
- }
- currentDrawPosition += positionIncrease;
- if (currentDrawPosition >= image.width*image.height)
- currentDrawPosition = 0;
- tryDrawPixel(currentDrawPosition);
- }
- }, get_delay);
- });
- }
- else
- {
- var added_timeout = 0;
- if (currentLoop == image.width*image.height)
- added_timeout = perfect_timeout*1000;
- setTimeout(attempt, toWait + Math.round(Math.random() * 1500) + added_timeout);
- currentLoop = 0;
- console.log("set a timeout");
- }
- }
- function drawTestImage(){
- for(var i=0; i < image.width*image.height; 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 % image.width;
- return {
- x: image.x + x,
- y: image.y + (i - x) / image.width - image.height
- };
- }
- function getPixel(x, y){
- return canvasse.writeBuffer[canvasse.getIndexFromCoords(x, y)];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement