Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var canvas = document.querySelector('.cnv');
  2. var startingPixel = Math.floor((Math.random() * 255));
  3. var ctx = canvas.getContext('2d');
  4. var color;
  5. //var pixels = [];
  6. var a = [];
  7. var inc = 0.001;
  8. getPixels();
  9.  
  10. function getPixels() {
  11.     for (var i = 0; i < canvas.height; i++) {
  12.         a[i] = [];
  13.         for (var j = 0; j < canvas.width; j++) {
  14.             a[i][j] = j;
  15.             drawPixels(i, j);
  16.  
  17.         }
  18.     }
  19.  
  20.  
  21.     //console.log(a);
  22. }
  23.  
  24.  
  25. function drawPixels(x, y) {
  26.     ctx.beginPath();
  27.     ctx.rect(x, y, 1, 1);
  28.     ctx.fillStyle = smooth(x, y);
  29.     ctx.fill();
  30.     ctx.closePath();
  31. }
  32.  
  33.  
  34.  
  35. function getHeight(x, y) {
  36.     startingPixel += Math.floor((Math.random() * 50) - 25);
  37.  
  38.     //console.log(startingPixel);
  39.     if (startingPixel >= 255) {
  40.         startingPixel = 255;
  41.     }
  42.     if (startingPixel <= 0) {
  43.         startingPixel = 0;
  44.     }
  45.     //return 'rgb(' + startingPixel + ',' + startingPixel + ',' + startingPixel + ')';
  46.     return startingPixel;
  47. }
  48.  
  49. function smooth(x, y) {
  50.     var corners = parseInt((getHeight(x - 1, y - 1) + getHeight(x + 1, x + 2) + getHeight(x + 1, y - 1) + getHeight(x + 1, y + 1)) / 20);
  51.  
  52.     var sides = parseInt((getHeight(x, y - 1) + getHeight(x, y + 1) + getHeight(x - 1, y) + getHeight(x + 1, y)) / 10);
  53.  
  54.     var center = parseInt((getHeight(x, y)) / 4);
  55.  
  56.     var total = parseInt(center + sides + corners);
  57.     //console.log(total);
  58.     //console.log(total);
  59.     if (total < 30) {
  60.         return '#3388ff';
  61.     }
  62.     if (total < 50) {
  63.         return '#55aaff';
  64.     }
  65.     if (total < 70) {
  66.         return '#77ccff';
  67.     }
  68.     if (total < 100) {
  69.         return '#ffdd99'
  70.     }
  71.     if (total < 140) {
  72.         return '#ccff77';
  73.     }
  74.     if (total < 180) {
  75.         return '#44cc33';
  76.     }
  77.     if (total < 220) {
  78.         return '#aaa';
  79.     }
  80.     if (total < 255) {
  81.         return '#666';
  82.     }
  83.  
  84.     //return 'rgb(' + total + ',' + total + ',' + total + ')';
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement