Questions tagged [p5.js]

p5.js is a JavaScript library that starts with the original goal of processing, to make coding accessible for artists, designers, educators, and beginners, and reinterprets this for today’s web.

p5.js is a JavaScript library that starts with the original goal of processing, to make coding accessible for artists, designers, educators, and beginners, and reinterprets this for today’s web. p5.js has a full set of drawing functionality too.

See also:

3071 questions
1
vote
1 answer

How to post xml data(for eg. a xml file) from the p5.js JavaScript library using the httpPost() function?

I am trying to load in an XML file saved locally on my computer using the loadXML() function in p5.js, and then using the httpPost() function to POST the same to a server which expects an XML file through the following code: var url =…
1
vote
2 answers

Javascript canvas green ellipse left and red right side

I want to make green ellipses on left side and red ellipses on right side. I use random function to fill the canvas. I use if statements for my purpose. Maybe switch case would be better for this task? This syntax only generate pink dots, whats…
andfra
  • 21
  • 1
1
vote
1 answer

p5.js checkers/chessboard draw with nested loop

I want to print a chess/checkers board and with the help of a tutorial came to this code. I understand everything that's happening apart from this line: rect(i * squareSize,j * squareSize,squareSize, squareSize); The thing I do not get is why you…
1
vote
1 answer

Trying to get a triangle to point to the mouse

I hate to admit it, but I am awfully stuck on a game I have only just bleeding started. The concept is quite simple really, I have a triangle that I want to point to the mouses position. Naturally I use the atan2 function in p5.js as this is…
user3667111
  • 611
  • 6
  • 21
1
vote
1 answer

How does the p5.js draw function work?

Can't work out what I'm doing wrong. Looking at the code below my logic is that each time the draw function is called the ellipse's coordinates are changed to be another random number. However instead of the coordinates being changed, the ellipse is…
Jake2018
  • 93
  • 1
  • 10
1
vote
1 answer

Why doesn't this code work. I'm using javascript with the library p5

So I've been watching the coding train to learn to code in javascript and I tried to copy his code but it doesn't work. I'm using brackets. Here is the…
1
vote
1 answer

How to plot a graph in the form f(y) + f(x) = c

This applies to P5JS, but I am interested in a general solution as well. I currently have a graphing program where one can enter an equation in the form y = f(x). This could be y = x^2, y = sin(x+5), y = x^3 + 5*(x^2) + 6, etc. It works by just…
Freddie R
  • 377
  • 5
  • 15
1
vote
1 answer

Variable not changing in p5.js

(I'm kind of a beginner at programming, so sorry if the answer is obvious.) I was trying to make a rudimentary Tetris clone on javascript, but a specific issue keeps giving me trouble. Heres all the code I have so far: var w = 10; var h =…
Lingyloll
  • 13
  • 3
1
vote
1 answer

Negate a pair of characters in RegEx Javascript

Currently have /([^\s\+\(]+)\^([^\s\,\+\)]+)/g to convert x^y into pow(x,y). Works for: y = x y = x^2 y = x^2 + y^2 y = 5*(x^2 + y^2) y = (x^2 + y^2) y = pow(x^2+y^2, 2) However I want to be able to do something like this: y = abs(x)^2 --> y =…
Freddie R
  • 377
  • 5
  • 15
1
vote
3 answers

p5.js. Alert is spammed

I have made a program that draws a box, and when I click on it it changes color and alerts me that it has been clicked. But the alert won't stop. It just keeps alerting me even after I stopped clicking on it. Here is the code: function setup() { …
Sanity
  • 11
  • 2
1
vote
1 answer

mousePressed inside Constructor Function in JavaScript - p5.js

I am currently working on a Constructor Function in JavaScript - p5.js. My problem is that the mousePressed() function doesn't execute the code in it when I am clicking in on the right spot on the canvas. Basically what I want is that a faction of…
Simon Fredrich
  • 95
  • 1
  • 10
1
vote
2 answers

p5.js clear() function is not working properly in mobile and some browsers

The HTML I've used is very simple which is given below:
1
vote
1 answer

Load Image Generated From A Function in p5.js canvas

I'm trying to load an image that is returned as a result of a function in a library called gaborgen.js The idea is that I should be able to generate a Gabor patch image using this library and then I need to store this in an image variable in p5, and…
1
vote
1 answer

reset the content without reloading page p5

I am making my own version of minesweeper using p5. Right now, when I click on the bomb cell, I show all the bombs in the given grid.. but the game is still playable. Is there any way to restart the game without reloading the page? I can produce an…
bjoshi
  • 105
  • 1
  • 9
1
vote
1 answer

Flood fill algorithm for bucket tool in P5.js electron paint application

I'm trying to create a bucket tool for my paint application made with electron.js and P5.js for the canvas stuff. everytime a user clicks on the canvas and his mode variable is equal to "fill", it calls the floodFill function. i tried to implement…
Idan Lottan
  • 138
  • 2
  • 10