I’m trying to have a few circles drawn on the screen that do not move after initialization. Right now it is constantly drawing them to the screen instead of keeping them there. Here’s the code: (This is with the p5.js library) Answer It sounds like your code is in the draw() function, which is called multiple times a second. Since
Tag: p5.js
P5 try to factorize Graphics and Canvas code
I want to factorize code for drawing same thing in a graphics or in the standard canvas. ( In my real program, i want to have autonomous class that draw themselves in some context given at construction time ) I cannot find some equivalent from canvas that can match graphics instructions except line. In the following, i try to give
song.play() returns “Uncaught TypeError: Cannot read property ‘play’ of undefined” for background music
I am trying to get background music playing behind my game using p5.js. However, I have tried every variation I can possibly think of, trying new Audio, not having preLoad, etc. And whatever I do I still get the Uncaught TypeError: Cannot read property ‘play’ of undefined” on my backgroundMusic.play(); I have tried to follow what the p5.js reference says
How to use windowWidth and windowHeight outside of setup()?
I need the screen dimensions for a project, but trying windowWidth and windowHeight yields an error saying I can’t use them outside of setup(). I also tried defining the windowWidth and Height to a new constant, but it simply says the constant has not been defined. Here’s the current state of my code (doesn’t work, but gives a pretty good
How can I access the real-time sketch images on a p5.js canvas?
Recently I am attempting to modify the source codes of this page. The underlying technique of this interactive programe is called sketch-rnn, a deep learning algorithm that can generate sketches. I need to access the real time images on the canvas so that I can use convolutional neural network (CNN), and feed the image as a 2d array to the
How to draw a star in P5.js?
I’m trying to make a class “star” with a method inside of it that, at given coordinates and size, draws a star. Something like rect() or ellipse() functions. How can make it? Answer
Passing value from p5 sketch to React (with react-p5-wrapper)
I have a p5 webcam video prediction system working right now. Currently, I’m trying to plug this into a React app to create a fuller web app. My problem is, the prediction is now only made in my p5 sketch, I want the prediction value to be passed into React’s App.js for further constructions. Is there any method of doing
p5.js how to freeze canvas?
I try to do something like that : But i want to “freeze” this canvas, so if i load the page i will have 30 rect() at a random height between 30 and 120. Answer One option would be to use noLoop() method inside setup function that will stop draw method loop. Note that with using noLoop and loop methods,