PPT

Pixel Place Tools

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

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

  1. // ==UserScript==
  2. // @name PPT
  3. // @description Pixel Place Tools
  4. // @version 2.3
  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 queue = this.client._pixelQueue;
  125. const [cxn, cyn] = queue.reduce(([x,y], [x2,y2]) => [x+x2,y+y2], [0, 0]);
  126. const [cx, cy] = [cxn/queue.length>>0, cyn/queue.length>>0];
  127. const workQueue = (func, ...args) => {
  128. let fin = queue => 0;
  129. const then = finish => finish && (fin = finish);
  130. worker(func)
  131. .then(queue => fin(this.client._pixelQueue = queue))
  132. .post([queue, ...args]);
  133. return {then}
  134. };
  135. return {
  136. start(finish){
  137. workQueue(([queue]) => {
  138. return [...queue].sort(([x,y,p,i], [x2,y2,p2,i2]) => i-i2);
  139. }).then(finish);
  140. },
  141. end(finish){
  142. workQueue(([queue]) => {
  143. return [...queue].sort(([x,y,p,i], [x2,y2,p2,i2]) => i2-i);
  144. }).then(finish);
  145. },
  146. rand(finish){
  147. workQueue(([queue]) => {
  148. return [...queue].sort(() => Math.random()-.5);
  149. }).then(finish);
  150. },
  151. top(finish){
  152. workQueue(([queue]) => {
  153. return [...queue].sort(([x,y], [x2,y2]) => y-y2);
  154. }).then(finish);
  155. },
  156. left(finish){
  157. workQueue(([queue]) => {
  158. return [...queue].sort(([x,y], [x2,y2]) => x-x2);
  159. }).then(finish);
  160. },
  161. right(finish){
  162. workQueue(([queue]) => {
  163. return [...queue].sort(([x,y], [x2,y2]) => x2-x);
  164. }).then(finish);
  165. },
  166. bottom(finish){
  167. workQueue(([queue]) => {
  168. return [...queue].sort(([x,y], [x2,y2]) => y2-y);
  169. }).then(finish);
  170. },
  171. fromCenter(finish){
  172. workQueue(([queue, cx, cy]) => {
  173. return [...queue].sort(([x,y], [x2,y2]) =>
  174. ((x-cx)**2+(y-cy)**2) -
  175. ((x2-cx)**2+(y2-cy)**2)
  176. );
  177. }, cx, cy).then(finish);
  178. },
  179. toCenter(finish){
  180. workQueue(([queue, cx, cy]) => {
  181. return [...queue].sort(([x,y], [x2,y2]) =>
  182. ((x2-cx)**2+(y2-cy)**2) -
  183. ((x-cx)**2+(y-cy)**2)
  184. );
  185. }, cx, cy).then(finish);
  186. },
  187. fromMapCenter(finish){
  188. workQueue(([queue, cx, cy]) => {
  189. return [...queue].sort(([x,y], [x2,y2]) =>
  190. ((x-cx)**2+(y-cy)**2) -
  191. ((x2-cx)**2+(y2-cy)**2)
  192. );
  193. }, this.client.map.width/2, this.client.map.height/2).then(finish);
  194. },
  195. toMapCenter(finish){
  196. workQueue(([queue, cx, cy]) => {
  197. return [...queue].sort(([x,y], [x2,y2]) =>
  198. ((x2-cx)**2+(y2-cy)**2) -
  199. ((x-cx)**2+(y-cy)**2)
  200. );
  201. }, this.client.map.width/2, this.client.map.height/2).then(finish);
  202. },
  203. };
  204. },
  205. timer: window,
  206. pixel: 0,
  207. size: 1,
  208. innerSize: 0,
  209. speed: 100,
  210. map: {pixels:[],width:0,height:0,get(x,y){return 255}},
  211. square(x,y, callback, finish) {
  212. const {pixel, timer, speed, size, innerSize} = this;
  213. const half = size>>1;
  214. const innerHalf = innerSize>>1;
  215. let xi = -half;
  216. let yi = -half;
  217. let t = timer.setInterval(() => {
  218. let i = 0;
  219. for (; yi < half+1;) {
  220. for (; xi < half+1;) {
  221. if (pixel === 255 || xi > -innerHalf && xi < innerHalf && yi > -innerHalf && yi < innerHalf) {
  222. xi++;
  223. continue;
  224. }
  225. callback(x+xi, y+yi, pixel, t);
  226. xi++;
  227. i++;
  228. if (i > speed) return;
  229. continue;
  230. }
  231. yi++;
  232. xi = -half;
  233. }
  234. timer.clearInterval(t);
  235. finish&&finish();
  236. });
  237. return t;
  238. },
  239. ring(x,y, callback, finish) {
  240. const {pixel, timer, speed, size, innerSize} = this;
  241. const half = size>>1;
  242. const innerHalf = innerSize>>1;
  243. let xi = -half;
  244. let yi = -half;
  245. let t = timer.setInterval(() => {
  246. let i = 0;
  247. for (; yi < half+1;) {
  248. for (; xi < half+1;) {
  249. if (pixel === 255 || xi**2 + yi**2 > half**2 || xi**2 + yi**2 < innerHalf**2) {
  250. xi++;
  251. continue;
  252. }
  253. callback(x+xi, y+yi, pixel, t);
  254. xi++;
  255. i++;
  256. if (i > speed) return;
  257. continue;
  258. }
  259. yi++;
  260. xi = -half;
  261. }
  262. timer.clearInterval(t);
  263. finish&&finish();
  264. });
  265. return t;
  266. },
  267. shader(callback, finish) {
  268. const {timer, speed, map} = this;
  269. let pos = 0;
  270. let t = timer.setInterval(() => {
  271. let i = 0;
  272. for (; pos < map.pixels.length; ) {
  273. if (map.pixels[pos] === 255) {
  274. pos++;
  275. continue;
  276. }
  277. callback(pos%map.width, pos/map.width>>0, map.pixels[pos], t);
  278. pos++;
  279. i++;
  280. if (i > speed) return;
  281. continue;
  282. }
  283. timer.clearInterval(t);
  284. finish&&finish();
  285. });
  286. return t;
  287. },
  288. image(pixels, x,y,w,h, callback, finish) {
  289. const {timer, speed} = this;
  290. let xi = 0;
  291. let yi = 0;
  292. let t = timer.setInterval(() => {
  293. let i = 0;
  294. for (; yi < h;) {
  295. for (; xi < w;) {
  296. const pixel = pixels[xi+yi*w];
  297. if (pixel === 255) {
  298. xi++;
  299. continue;
  300. }
  301. callback(x+xi, y+yi, pixel, t);
  302. xi++;
  303. i++;
  304. if (i > speed) return;
  305. continue;
  306. }
  307. yi++;
  308. xi = 0;
  309. }
  310. timer.clearInterval(t);
  311. finish&&finish();
  312. });
  313. return t;
  314. }
  315. };
  316.  
  317.  
  318.  
  319. window.PPT = PPT;
  320. return PPT;
  321. })();
  322. // 0vC4#7152

QingJ © 2025

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