Advertisement
Guest User

GrayCorner Script.

a guest
Apr 7th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1.  
  2. /*
  3. colors
  4. white: 0
  5. lightgray: 1
  6. gray: 2
  7. black: 3
  8. pink: 4
  9. red: 5
  10. orange: 6
  11. brown: 7
  12. yellow: 8
  13. lime: 9
  14. green: 10
  15. light blue: 11
  16. navy blue: 12
  17. blue: 13
  18. lightpurple: 14
  19. purple: 15
  20. */
  21.  
  22.  
  23. var imageData = [
  24. [2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2],
  25. [2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2],
  26. [2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2],
  27. [2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2],
  28. [2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2],
  29. [2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2],
  30. [2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2],
  31. [2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2],
  32. [2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2],
  33. [2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2],
  34.  
  35. [2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2],
  36. [2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2]
  37. ];
  38. var taskQueue = [];
  39. var taskIndex = 0;
  40.  
  41. var x = 0; //STARTING POSITION X
  42. var y = 0; //STARTING POSITION Y
  43.  
  44. function generateTasks(){
  45. taskQueue = [];
  46. for(var rowIndex = 0; rowIndex < imageData.length; rowIndex++){
  47. var row = imageData[rowIndex];
  48. for(var columnIndex = 0; columnIndex < row.length; columnIndex++){
  49. var dx = x + (columnIndex || 0);
  50. var dy = y + (rowIndex || 0);
  51. var pixel = ctx.getImageData(dx, dy, 1, 1).data;
  52. if(colors.indexOf("rgb(" + pixel[0] + ", " + pixel[1] + ", " + pixel[2] + ")") != row[columnIndex]) {
  53. console.log(dx, dy, pixel);
  54. taskQueue.push([
  55. dx,
  56. dy,
  57. (function(dx, dy, c) {
  58. return function() {
  59. tryColorPixel(dx, dy, c);
  60. }
  61. })(dx, dy, row[columnIndex])
  62. ]);
  63. }
  64. }
  65. }
  66. shuffle(taskQueue);
  67. }
  68. setInterval(function(){
  69. if(taskQueue.length > 0){
  70. if(taskIndex < taskQueue.length ){
  71. var task = taskQueue[taskIndex];
  72. if(typeof task[2] == "function"){
  73. task[2]();
  74.  
  75. }
  76. taskIndex++;
  77. } else {
  78. taskIndex = 0;
  79. console.log("a");
  80. y = y + imageData.length;
  81. if(y < 999){
  82. y = 0;
  83. x += imageData[0].length;
  84. if(x < 999)
  85. x = 0;
  86. }
  87. generateTasks();
  88. }
  89. }
  90. else {
  91. generateTasks();
  92. }
  93. }, 5000);
  94. function shuffle(a) {
  95. for (let i = a.length; i; i--) {
  96. let j = Math.floor(Math.random() * i);
  97. [a[i - 1], a[j]] = [a[j], a[i - 1]];
  98. }
  99. }
  100. generateTasks();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement