Skip to content

Instantly share code, notes, and snippets.

@lostintangent
Created February 4, 2021 05:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lostintangent/04052d31fcf92f7ce70b47ee5b9d8f92 to your computer and use it in GitHub Desktop.
Save lostintangent/04052d31fcf92f7ce70b47ee5b9d8f92 to your computer and use it in GitHub Desktop.
Genuary #12 - using an API
let img
let scale = 20
function preload() {
img = loadImage('https://source.unsplash.com/random/1200x800');
}
function setup() {
createCanvas(1200, 800)
img.loadPixels()
noStroke()
}
function draw() {
let x = int(random(img.width / scale + 1))
let y = int(random(img.height / scale + 1))
let col = img.get(x * scale, y * scale)
fill(col)
circle(x * scale, y * scale, scale - 1)
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.2.0/p5.min.js"></script>
html, body {
margin: 0;
padding: 10px;
background: #000000;
}
canvas {
margin: 0 auto;
display: block;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment