Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- """
- PixelPlaceBot is a bot that ruins your fun time on Pixel Place. Who would have
- thought.
- put_pixel(x,y,colour) places a pixel,
- calculate_grid(grid) calculates the importance of many bad pixels in an image.
- get_map() gets the map from Pixel Place.
- show_map() shows the map (using false colour) with matplotlib.
- largest_elements() picks the points in an array with the largest value.
- demonstrate_kill() demonstrates the defacing powers of calculate_grid.
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- """
- import subprocess
- import shlex
- import numpy as np
- import math
- import json
- import random
- def put_pixel(x, y, colour):
- s = subprocess.Popen(shlex.split("curl 'https://pixelplace.io/back/placepixelnew.php?history=1' -H 'Host: pixelplace.io' -H 'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:52.0) Gecko/20100101 Firefox/52.0' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Referer: https://pixelplace.io/?activateKey=zjlahb051orvx3091yyd84x2pzwb8wn7f8hxji2l6uh3yhc0gbdogbr5anhij4qyd7wwpzivtzzshcsxo5l4gdar0r9jwzi97e6xeot7osz54r2sxoxe1751zflvf45micjw1d4p54uawx3um08n7ep6tb28f7vyjfvls0ay45812bvob4cjj2pcdrlszhrjwm4pmenrkvtm7pbjto2cqsp3kbwksn3pa8exm1o7xhu465o0trdkj3o4eko78rw&activateToken=jzbgmd4tamoftt3tnv78eawjph7xpzu8z5pmiugtg489xc3l7btmlq5b7d8wc25b8uyroek5isfg5j1cuvzgl4rsi0pu3v6bq42finl0g0hljjyeeyu03mtlmjfpfl15q4l8r6987rtras5pq0ptmje93uzig1o659fxgp5ngzeqskfil5c7orgrlga1hy7m7nkncqbtpqjhbz0w4c3t3klp1vqity50mpoyf0r5qbn2anyf0284mttnpk6ijbj' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'X-Requested-With: XMLHttpRequest' -H 'Cookie: 60gpBAK=R1224193598; PHPSESSID=54e3ba68e785f6fee73c28d98cc2ba16; authKey=zjlahb051orvx3091yyd84x2pzwb8wn7f8hxji2l6uh3yhc0gbdogbr5anhij4qyd7wwpzivtzzshcsxo5l4gdar0r9jwzi97e6xeot7osz54r2sxoxe1751zflvf45micjw1d4p54uawx3um08n7ep6tb28f7vyjfvls0ay45812bvob4cjj2pcdrlszhrjwm4pmenrkvtm7pbjto2cqsp3kbwksn3pa8exm1o7xhu465o0trdkj3o4eko78rw; authToken=664l8cip30yr5zjtsy5so16xps99ncxuj1gsezhizfa5fuy8s40h67fvzo5n12ik4ydjxu2xad3p72y06yhc6w75kctmfb7jak37f55pi9fpbdphc7uj32pofiauuie42hchmh74qnu11kjerexvgnjv5uq0c44flgx8y4cos7qtra8jp6e5ty1yssz5w3likiqim37fay928hlxn03gy5frxexuiic203kn6s2hqcjzt5xg51x36cv4rsy9abc; 60gpD=R2432247896' -H 'Connection: keep-alive' --data 'attemptPlace=true&x={}&y={}&c={}&b=1'".format(x, y, colour)), stdout=subprocess.PIPE)
- return json.loads(s.stdout.read())
- def get_map():
- s = subprocess.Popen(shlex.split("curl 'https://pixelplace.io/back/getcanvasnew.php?getCanvasData=1&history=1&umt=0&_=1513294113600' -H 'Host: pixelplace.io' -H 'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:52.0) Gecko/20100101 Firefox/52.0' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Referer: https://pixelplace.io/?activateKey=zjlahb051orvx3091yyd84x2pzwb8wn7f8hxji2l6uh3yhc0gbdogbr5anhij4qyd7wwpzivtzzshcsxo5l4gdar0r9jwzi97e6xeot7osz54r2sxoxe1751zflvf45micjw1d4p54uawx3um08n7ep6tb28f7vyjfvls0ay45812bvob4cjj2pcdrlszhrjwm4pmenrkvtm7pbjto2cqsp3kbwksn3pa8exm1o7xhu465o0trdkj3o4eko78rw&activateToken=jzbgmd4tamoftt3tnv78eawjph7xpzu8z5pmiugtg489xc3l7btmlq5b7d8wc25b8uyroek5isfg5j1cuvzgl4rsi0pu3v6bq42finl0g0hljjyeeyu03mtlmjfpfl15q4l8r6987rtras5pq0ptmje93uzig1o659fxgp5ngzeqskfil5c7orgrlga1hy7m7nkncqbtpqjhbz0w4c3t3klp1vqity50mpoyf0r5qbn2anyf0284mttnpk6ijbj' -H 'X-Requested-With: XMLHttpRequest' -H 'Cookie: 60gpBAK=R1224193598; PHPSESSID=54e3ba68e785f6fee73c28d98cc2ba16; authKey=zjlahb051orvx3091yyd84x2pzwb8wn7f8hxji2l6uh3yhc0gbdogbr5anhij4qyd7wwpzivtzzshcsxo5l4gdar0r9jwzi97e6xeot7osz54r2sxoxe1751zflvf45micjw1d4p54uawx3um08n7ep6tb28f7vyjfvls0ay45812bvob4cjj2pcdrlszhrjwm4pmenrkvtm7pbjto2cqsp3kbwksn3pa8exm1o7xhu465o0trdkj3o4eko78rw; authToken=664l8cip30yr5zjtsy5so16xps99ncxuj1gsezhizfa5fuy8s40h67fvzo5n12ik4ydjxu2xad3p72y06yhc6w75kctmfb7jak37f55pi9fpbdphc7uj32pofiauuie42hchmh74qnu11kjerexvgnjv5uq0c44flgx8y4cos7qtra8jp6e5ty1yssz5w3likiqim37fay928hlxn03gy5frxexuiic203kn6s2hqcjzt5xg51x36cv4rsy9abc' -H 'Connection: keep-alive'"), stdout=subprocess.PIPE)
- m = json.loads(s.stdout.read())
- grid = [[0 for x in range(1010)] for y in range(1010)]
- try:
- for x, y, c in [z.split(".") for z in m["data"]["pixels"]]:
- x, y, c = int(x), int(y), int(c)
- grid[y][x] = c
- except:
- return grid
- return grid
- def show_map(grid):
- import matplotlib.pyplot as plt
- plt.imshow(np.array(grid, dtype=float))
- plt.show()
- def calculate_grid(grid):
- weights = grid * 0 # make an array of the same size as grid but blank
- # PASS 1: Populate a set of bad pixels.
- badpixels = set()
- for cy, crow in enumerate(grid):
- for cx, cpos in enumerate(crow):
- if cpos:
- badpixels.add((cx, cy))
- # PASS 2: Calculate the resulting order.
- for oy, orow in enumerate(grid):
- for ox, opos in enumerate(orow):
- if opos:
- weights[oy][ox] = 1
- for cx, cy in badpixels:
- try:
- weights[oy][ox] += 1. / math.sqrt((cy - oy)
- ** 2 + (cx - ox)**2)
- except Exception as e:
- # print e, e.args, e.message
- pass
- return weights
- def largest_elements(grid):
- biggestnum = 0
- biggestpos = []
- for y, row in enumerate(grid):
- for x, cell in enumerate(row):
- if cell > biggestnum:
- biggestpos = []
- if cell >= biggestnum:
- biggestnum = cell
- biggestpos.append((x, y))
- return biggestpos
- def updatefig(*args):
- global badart
- global step
- if badart.mean() > 0:
- pos = largest_elements(calculate_grid(badart))
- nextdeface = random.choice(pos)
- print "Removing ({},{}).".format(*nextdeface)
- x, y = nextdeface
- badart[y][x] = 0
- step += 1
- im.set_array(badart)
- return im,
- def demonstrate_kill():
- import matplotlib.pyplot as plt
- import matplotlib.animation as animation
- import sys
- # deface a swastika as demonstration
- # arguably the one at 45 degrees is problematic,
- # but who draws that on a square grid?
- # answer (rot13): "ab bar!"
- badart = np.array([
- [1, 0, 1, 1, 1],
- [1, 0, 1, 0, 0],
- [1, 1, 1, 1, 1],
- [0, 0, 1, 0, 1],
- [1, 1, 1, 0, 1]]).astype(np.float32, copy=False)
- fig = plt.figure()
- im = plt.imshow(badart, cmap=plt.get_cmap("binary"))
- step = 0
- ani = animation.FuncAnimation(fig, updatefig, interval=500, blit=True)
- plt.show()
- print "Done in {} steps.".format(step)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement