Promises
This commit is contained in:
BIN
w11_promises/promisify/assets/light.jpg
Normal file
BIN
w11_promises/promisify/assets/light.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 168 KiB |
18
w11_promises/promisify/index.html
Normal file
18
w11_promises/promisify/index.html
Normal file
@@ -0,0 +1,18 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<script src='https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.11.3/p5.js'
|
||||
integrity='sha512-BLd2MDTrBCo01Vkhjbjn3ITBDbx3o/Lt7D5hj5oLwW8vlDHYXMenxglTcUURCgBhdLNAjZ7KD8x4ZA7bQY3OhA=='
|
||||
crossorigin='anonymous'></script>
|
||||
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="./css/style.css" />
|
||||
<meta charset="utf-8" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<script src="sketch.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
21
w11_promises/promisify/sketch.js
Normal file
21
w11_promises/promisify/sketch.js
Normal file
@@ -0,0 +1,21 @@
|
||||
let img;
|
||||
let imgWidth = 100;
|
||||
|
||||
function setup() {
|
||||
createCanvas(800, 600);
|
||||
imageMode(CENTER);
|
||||
|
||||
img = loadImage('assets/light.jpg');
|
||||
|
||||
// Promisify this function
|
||||
// img = loadImage('assets/light.jpg', (loadedImage) => {
|
||||
// const ratio = loadedImage.height / loadedImage.width;
|
||||
// loadedImage.height = imgWidth * ratio;
|
||||
// loadedImage.width = imgWidth;
|
||||
// });
|
||||
}
|
||||
|
||||
function draw() {
|
||||
background(255);
|
||||
if (img) image(img, width / 2, height / 2);
|
||||
}
|
||||
Reference in New Issue
Block a user