-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trying to include vanilla .js class #30
Comments
Can you provide a bit more Information about what is not working? |
Hi @and-who I've uploaded my code to https://github.com/vennsoh/react-p5 I suspect my Particle.js class doesn't know how to read the methods/functions from p5 lib. But I'm not sure how to make it work. |
@vennsoh Provide p5 context from sketch as an argument of Particle constructor. Next use functions from this context like Particle {
constructor(p5context) {
this.p5context = p5context;
...
}
display() {
this.p5context.ellipse(this.x, this.y, this.diameter, this.diameter);
} bug1 = new Particle(p); And you no need use |
@shtrih Thanks so much! It helps and it works! |
@shtrih However when I try |
Ah sorry ignore this, obviously it doesn't work, the "width" isn't a number. |
Hi, first of all I'd like to say this is the best p5 react wrapper so far! @and-who
I'm new to all these, so do give me some guidance here.
I'm trying to create create a simple particle system here.
My particle class
`
import p5 from "p5";
export default class Particle {
constructor() {
this.x = random(width);
this.y = random(height);
this.diameter = random(10, 30);
this.speed = 1;
}
move() {
this.x += random(-this.speed, this.speed);
this.y += random(-this.speed, this.speed);
}
display() {
ellipse(this.x, this.y, this.diameter, this.diameter);
}
}
`
My p5 sketch
`
import p5 from "p5";
import Particle from "./Particle";
global.p5 = p5;
export default function sketch(p) {
let bug1;
let bug2;
p.setup = () => {
p.createCanvas(710, 400);
bug1 = new Particle();
bug2 = new Particle();
};
p.draw = () => {
p.background(50, 89, 100);
bug1.move();
bug1.display();
bug2.move();
bug2.display();
};
}
`
But I can't seem to get it working...
The text was updated successfully, but these errors were encountered: