PPT

Pixel Place Tools

当前为 2022-05-08 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.gf.qytechs.cn/scripts/443807/1048501/PPT.js

  1. // ==UserScript==
  2. // @name PPT
  3. // @description Pixel Place Tools
  4. // @version 2.6
  5. // @author 0vC4
  6. // @namespace https://gf.qytechs.cn/users/670183
  7. // @match https://pixelplace.io/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=pixelplace.io
  9. // @license MIT
  10. // @grant none
  11. // @run-at document-start
  12. // ==/UserScript==
  13.  
  14.  
  15.  
  16.  
  17.  
  18. const PPT = (() => {
  19. if (window.PPT) return window.PPT;
  20.  
  21.  
  22.  
  23. const worker = function(func) {
  24. const worker = new Worker(URL.createObjectURL(new Blob(["onmessage=async({data})=>self.postMessage(await(" + func.toString() + ")(data))"], { type: "text/javascript" })));
  25. const root = {};
  26. const post = data => (worker.postMessage(data), root);
  27. const then = callback => (worker.onmessage=({data})=>callback(data), root);
  28. return Object.assign(root, {post, then});
  29. };
  30.  
  31.  
  32.  
  33. const PPT = {
  34. zero: 0xCCCCCC,
  35. default: new Uint32Array([
  36. 0xFFFFFF,
  37. 0xC4C4C4,
  38. 0x888888,
  39. 0x555555,
  40. 0x222222,
  41. 0x000000,
  42. 0x006600,
  43. 0x22B14C,
  44. 0x02BE01,
  45. 0x51E119,
  46. 0x94E044,
  47. 0xFBFF5B,
  48. 0xE5D900,
  49. 0xE6BE0C,
  50. 0xE59500,
  51. 0xA06A42,
  52. 0x99530D,
  53. 0x633C1F,
  54. 0x6B0000,
  55. 0x9F0000,
  56. 0xE50000,
  57. 0xFF3904,
  58. 0xBB4F00,
  59. 0xFF755F,
  60. 0xFFC49F,
  61. 0xFFDFCC,
  62. 0xFFA7D1,
  63. 0xCF6EE4,
  64. 0xEC08EC,
  65. 0x820080,
  66. 0x5100FF,
  67. 0x020763,
  68. 0x0000EA,
  69. 0x044BFF,
  70. 0x6583CF,
  71. 0x36BAFF,
  72. 0x0083C7,
  73. 0x00D3DD,
  74. 0x45FFC8
  75. ]),
  76. exclude: new Uint32Array([
  77. 0x51E119,
  78. 0xFF3904,
  79. 0x5100FF,
  80. 0x45FFC8
  81. ]),
  82. get palette() {
  83. return this.default.map(color => this.exclude.includes(color) ? this.zero : color);
  84. },
  85.  
  86.  
  87.  
  88. _wheelID: 0,
  89. get wheel() {
  90. let pixel = this._wheelID+1;
  91.  
  92. while (this.palette[pixel] == this.zero)
  93. if (this.palette[++pixel] == null)
  94. pixel = 0;
  95.  
  96. this._wheelID = pixel;
  97. return this._wheelID;
  98. },
  99.  
  100.  
  101.  
  102. RGB2P(r, g, b) {
  103. const closest = [...this.palette]
  104. .filter(n => n != this.zero)
  105. .map(clr =>
  106. [
  107. ((r - ((clr>>16)&0xFF))*.299)**2 +
  108. ((g - ((clr>>8)&0xFF))*.587)**2 +
  109. ((b - (clr&0xFF))*.114)**2,
  110. clr
  111. ]
  112. )
  113. .sort((a,b) => a[0]-b[0])
  114. [0][1];
  115.  
  116. return this.palette.indexOf(closest);
  117. },
  118. CLR2P(color) {
  119. return this.RGB2P((color>>16)&0xFF, (color>>8)&0xFF, color&0xFF);
  120. },
  121. client: null,
  122. get order() {
  123. if (!this.client) throw new Error('assign client variable first');
  124. const client = this.client;
  125. const queue = client._pixelQueue;
  126. const [cxn, cyn] = queue.reduce(([x,y], [x2,y2]) => [x+x2,y+y2], [0, 0]);
  127. const [cx, cy] = [cxn/queue.length>>0, cyn/queue.length>>0];
  128. const workQueue = (func, ...args) => {
  129. let fin = queue => 0;
  130. const then = finish => finish && (fin = finish);
  131. worker(func)
  132. .then(queue => fin(client._pixelQueue = queue))
  133. .post([queue, ...args]);
  134. return {then}
  135. };
  136. return {
  137. start(finish){
  138. workQueue(([queue]) => {
  139. return [...queue].sort(([x,y,p,i], [x2,y2,p2,i2]) => i-i2);
  140. }).then(finish);
  141. },
  142. end(finish){
  143. workQueue(([queue]) => {
  144. return [...queue].sort(([x,y,p,i], [x2,y2,p2,i2]) => i2-i);
  145. }).then(finish);
  146. },
  147. rand(finish){
  148. workQueue(([queue]) => {
  149. return [...queue].sort(() => Math.random()-.5);
  150. }).then(finish);
  151. },
  152. top(finish){
  153. workQueue(([queue]) => {
  154. return [...queue].sort(([x,y], [x2,y2]) => y-y2);
  155. }).then(finish);
  156. },
  157. left(finish){
  158. workQueue(([queue]) => {
  159. return [...queue].sort(([x,y], [x2,y2]) => x-x2);
  160. }).then(finish);
  161. },
  162. right(finish){
  163. workQueue(([queue]) => {
  164. return [...queue].sort(([x,y], [x2,y2]) => x2-x);
  165. }).then(finish);
  166. },
  167. bottom(finish){
  168. workQueue(([queue]) => {
  169. return [...queue].sort(([x,y], [x2,y2]) => y2-y);
  170. }).then(finish);
  171. },
  172. fromCenter(finish){
  173. workQueue(([queue, cx, cy]) => {
  174. return [...queue].sort(([x,y], [x2,y2]) =>
  175. ((x-cx)**2+(y-cy)**2) -
  176. ((x2-cx)**2+(y2-cy)**2)
  177. );
  178. }, cx, cy).then(finish);
  179. },
  180. toCenter(finish){
  181. workQueue(([queue, cx, cy]) => {
  182. return [...queue].sort(([x,y], [x2,y2]) =>
  183. ((x2-cx)**2+(y2-cy)**2) -
  184. ((x-cx)**2+(y-cy)**2)
  185. );
  186. }, cx, cy).then(finish);
  187. },
  188. fromVertical(finish){
  189. workQueue(([queue, cx, cy]) => {
  190. return [...queue].sort(([x,y], [x2,y2]) => Math.abs(x-cx) - Math.abs(x2-cx));
  191. }, cx, cy).then(finish);
  192. },
  193. fromHorizontal(finish){
  194. workQueue(([queue, cx, cy]) => {
  195. return [...queue].sort(([x,y], [x2,y2]) => Math.abs(y-cy) - Math.abs(y2-cy));
  196. }, cx, cy).then(finish);
  197. },
  198. toVertical(finish){
  199. workQueue(([queue, cx, cy]) => {
  200. return [...queue].sort(([x,y], [x2,y2]) => Math.abs(x2-cx) - Math.abs(x-cx));
  201. }, cx, cy).then(finish);
  202. },
  203. toHorizontal(finish){
  204. workQueue(([queue, cx, cy]) => {
  205. return [...queue].sort(([x,y], [x2,y2]) => Math.abs(y2-cy) - Math.abs(y-cy));
  206. }, cx, cy).then(finish);
  207. },
  208. fromMapCenter(finish){
  209. workQueue(([queue, cx, cy]) => {
  210. return [...queue].sort(([x,y], [x2,y2]) =>
  211. ((x-cx)**2+(y-cy)**2) -
  212. ((x2-cx)**2+(y2-cy)**2)
  213. );
  214. }, client.map.width/2, client.map.height/2).then(finish);
  215. },
  216. toMapCenter(finish){
  217. workQueue(([queue, cx, cy]) => {
  218. return [...queue].sort(([x,y], [x2,y2]) =>
  219. ((x2-cx)**2+(y2-cy)**2) -
  220. ((x-cx)**2+(y-cy)**2)
  221. );
  222. }, client.map.width/2, client.map.height/2).then(finish);
  223. },
  224. fromMapVertical(finish){
  225. workQueue(([queue, cx, cy]) => {
  226. return [...queue].sort(([x,y], [x2,y2]) => Math.abs(x-cx) - Math.abs(x2-cx));
  227. }, client.map.width/2, client.map.height/2).then(finish);
  228. },
  229. fromMapHorizontal(finish){
  230. workQueue(([queue, cx, cy]) => {
  231. return [...queue].sort(([x,y], [x2,y2]) => Math.abs(y-cx) - Math.abs(y2-cx));
  232. }, client.map.width/2, client.map.height/2).then(finish);
  233. },
  234. toMapVertical(finish){
  235. workQueue(([queue, cx, cy]) => {
  236. return [...queue].sort(([x,y], [x2,y2]) => Math.abs(x2-cx) - Math.abs(x-cx));
  237. }, client.map.width/2, client.map.height/2).then(finish);
  238. },
  239. toMapHorizontal(finish){
  240. workQueue(([queue, cx, cy]) => {
  241. return [...queue].sort(([x,y], [x2,y2]) => Math.abs(y2-cx) - Math.abs(y-cx));
  242. }, client.map.width/2, client.map.height/2).then(finish);
  243. },
  244. };
  245. },
  246. timer: window,
  247. pixel: 0,
  248. size: 1,
  249. innerSize: 0,
  250. speed: 100,
  251. map: {pixels:[],width:0,height:0,get(x,y){return 255}},
  252. square(x,y, callback, finish) {
  253. const {pixel, timer, speed, size, innerSize} = this;
  254. const half = size>>1;
  255. const innerHalf = innerSize>>1;
  256. let xi = -half;
  257. let yi = -half;
  258. let t = timer.setInterval(() => {
  259. let i = 0;
  260. for (; yi < half+1;) {
  261. for (; xi < half+1;) {
  262. if (pixel === 255 || xi > -innerHalf && xi < innerHalf && yi > -innerHalf && yi < innerHalf) {
  263. xi++;
  264. continue;
  265. }
  266. callback(x+xi, y+yi, pixel, t);
  267. xi++;
  268. i++;
  269. if (i > speed) return;
  270. continue;
  271. }
  272. yi++;
  273. xi = -half;
  274. }
  275. timer.clearInterval(t);
  276. finish&&finish();
  277. });
  278. return t;
  279. },
  280. ring(x,y, callback, finish) {
  281. const {pixel, timer, speed, size, innerSize} = this;
  282. const half = size>>1;
  283. const innerHalf = innerSize>>1;
  284. let xi = -half;
  285. let yi = -half;
  286. let t = timer.setInterval(() => {
  287. let i = 0;
  288. for (; yi < half+1;) {
  289. for (; xi < half+1;) {
  290. if (pixel === 255 || xi**2 + yi**2 > half**2 || xi**2 + yi**2 < innerHalf**2) {
  291. xi++;
  292. continue;
  293. }
  294. callback(x+xi, y+yi, pixel, t);
  295. xi++;
  296. i++;
  297. if (i > speed) return;
  298. continue;
  299. }
  300. yi++;
  301. xi = -half;
  302. }
  303. timer.clearInterval(t);
  304. finish&&finish();
  305. });
  306. return t;
  307. },
  308. shader(callback, finish) {
  309. const {timer, speed, map} = this;
  310. let pos = 0;
  311. let t = timer.setInterval(() => {
  312. let i = 0;
  313. for (; pos < map.pixels.length; ) {
  314. if (map.pixels[pos] === 255) {
  315. pos++;
  316. continue;
  317. }
  318. callback(pos%map.width, pos/map.width>>0, map.pixels[pos], t);
  319. pos++;
  320. i++;
  321. if (i > speed) return;
  322. continue;
  323. }
  324. timer.clearInterval(t);
  325. finish&&finish();
  326. });
  327. return t;
  328. },
  329. image(pixels, x,y,w,h, callback, finish) {
  330. const {timer, speed} = this;
  331. let xi = 0;
  332. let yi = 0;
  333. let t = timer.setInterval(() => {
  334. let i = 0;
  335. for (; yi < h;) {
  336. for (; xi < w;) {
  337. const pixel = pixels[xi+yi*w];
  338. if (pixel === 255) {
  339. xi++;
  340. continue;
  341. }
  342. callback(x+xi, y+yi, pixel, t);
  343. xi++;
  344. i++;
  345. if (i > speed) return;
  346. continue;
  347. }
  348. yi++;
  349. xi = 0;
  350. }
  351. timer.clearInterval(t);
  352. finish&&finish();
  353. });
  354. return t;
  355. }
  356. };
  357.  
  358.  
  359.  
  360. window.PPT = PPT;
  361. return PPT;
  362. })();
  363. // 0vC4#7152

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址