mozik_01

FEATURED

In this example below you will see how to do a mozik_01 with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by ayakooo, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright ayakooo ©
  • HTML
  • CSS
  • JavaScript
    <script src="//cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.0/p5.min.js"></script>

/*Downloaded from https://www.codeseek.co/ayakooo/mozik_01-ERmxMg */
    * {
  margin: 0;
  padding: 0;
}


/*Downloaded from https://www.codeseek.co/ayakooo/mozik_01-ERmxMg */
    var img;
function preload() {
  //change image -> img1.jpg~img5.jpg
  img = loadImage('https://lh3.googleusercontent.com/-TAYUcxAvgzs/Wx77eYqajCI/AAAAAAAAz60/ot9tQQuxVHIn8lkkg5bMdVeGRtWgwyCzwCJoC/w1060-h1060-n-rw/001'); 
}
function setup() {
  createCanvas(800,800);
  noStroke();
  //pixelDensity(1);
}

function draw() {
  background(255);

  img.loadPixels();
  var pixels = img.pixels;
    
  //mosaic step
  var stepSize = 10;
  //mosaic ellipse size
  var size = 12;

  for (var y=0; y<img.height; y+=stepSize) {
    for (var x=0; x<img.width; x+=stepSize) {
      var i = (x + y * img.width) * 4;
      var c = color(pixels[i + 0], pixels[i + 1], pixels[i + 2])
      fill(c);
      ellipse(x, y, size, size);
    }
  }
}




Comments