-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcanvas.js
25 lines (22 loc) · 908 Bytes
/
canvas.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import * as THREE from 'three';export default function createCardTexture(){
const canvas = document.createElement('canvas');
const context = canvas.getContext('2d');
// Set canvas size
canvas.width = 512; // Set the width
canvas.height = 512*1.4; // Set the height
// Load a frog image
const frogImage = new Image();
const texture = new THREE.CanvasTexture(canvas);
frogImage.onload = function() {
context.fillStyle = 'green';
context.fillRect(0, 0, canvas.width, canvas.height)
const width = frogImage.naturalWidth
const height = frogImage.naturalHeight
// Draw the image onto the canvas when it's loaded
context.drawImage(frogImage, 0, 0, canvas.width, canvas.height);
// After drawing, update the texture
texture.needsUpdate = true;
};
frogImage.src = '/frog-on-lilypad.webp'; // Replace with the path to your frog image
return texture
}