Created
July 25, 2019 13:01
-
-
Save jarmitage/eac3a3ee0ce326e8f9bfda6923c7e288 to your computer and use it in GitHub Desktop.
Svelte p5 dynamic import example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
import { onMount } from 'svelte'; | |
let p5 | |
let sketch | |
onMount(async () => { | |
const module = await import('p5') | |
p5 = module.default | |
sketch = new p5 (function (sketch) { | |
sketch.setup = function() { | |
sketch.createCanvas (200,200); | |
} | |
sketch.draw = function() { | |
sketch.fill(255) | |
sketch.rect(0,0,100,10); | |
} | |
}, document.getElementById('p5sketch')); | |
}); | |
</script> | |
<style> | |
#p5sketch { | |
width:200px; | |
height:200px; | |
background-color: #000; | |
} | |
</style> | |
<div id="p5sketch"></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment