Skip to content

Instantly share code, notes, and snippets.

@oxo-yuta
Last active April 14, 2021 14:44
Show Gist options
  • Save oxo-yuta/8a15ae6fdde9a6b696aa26fcc7b0aeba to your computer and use it in GitHub Desktop.
Save oxo-yuta/8a15ae6fdde9a6b696aa26fcc7b0aeba to your computer and use it in GitHub Desktop.
use p5 on Nuxt template. You need to add p5 and @type/p5
<template>
<v-row>
<v-col>
<v-card width="500" height="500">
<div id="p5Canvas"></div>
</v-card>
</v-col>
</v-row>
</template>
<script lang="ts">
import p5 from 'p5'
export default {
mounted(){
const P5 = require('p5')
new P5(script)
}
}
const script = function (p5: p5) {
const color1 = p5.color("#fffbe3");
const color2 = p5.color("#24495c");
let color1amount = 1;
p5.setup = () => {
// setup canvas
const canvas = p5.createCanvas(500, 500)
canvas.parent("p5Canvas");
// codes
p5.background(0);
p5.angleMode(p5.DEGREES);
p5.noStroke();
p5.background("#131821");
p5.blendMode(p5.LIGHTEST);
}
p5.draw = () => {
p5.fill(p5.lerpColor(color2, color1, color1amount));
p5.translate(p5.width / 2, p5.height / 2);
p5.rotate(p5.frameCount * 13);
p5.ellipse(p5.frameCount / 2, 0, p5.frameCount, p5.frameCount / 3);
color1amount *= 0.995;
}
}
</script>
@oxo-yuta
Copy link
Author

original code for p5 is from https://ics.media/entry/210129/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment