Skip to content

Instantly share code, notes, and snippets.

@jarmitage
Created July 25, 2019 13:01
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 jarmitage/eac3a3ee0ce326e8f9bfda6923c7e288 to your computer and use it in GitHub Desktop.
Save jarmitage/eac3a3ee0ce326e8f9bfda6923c7e288 to your computer and use it in GitHub Desktop.
Svelte p5 dynamic import example
<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