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

.push doesn't seem to be adding to my array

I have called the .push function, but nothing is being added to my array. Here is my code: function setup() { createCanvas(400, 400); } let digits = []; function binaryConverter(num){ this.num = num; for(let i = 0; this.num === 0; i++){ …
hello
  • 39
  • 5
1
vote
0 answers

P5JS CORS error after making it a node app

So I have a P5JS app which has a very simple preload function: function preload() { json = loadJSON(getCurrentViewersUrl()); } which calls this function and returns the request url: function getCurrentViewersUrl() { return…
user3667111
  • 611
  • 6
  • 21
1
vote
1 answer

How to create a menu for a game in p5.js using buttons

I'm a creating a game of pong with three different versions of the original game of pong, and each of these versions are held in 3 different functions, such as; singleplayer, multiplayer etc. I have called a function menu(); in the first function…
user10848359
1
vote
1 answer

How do can i apply different forces using vectors?

I am trying to make a simple side-scroller game in p5.js. As far as I understood I need to have vectors to imitate real-world physics. All I really need is a force that pushed the player down and a force that makes it jump when a key is pressed. I…
1
vote
0 answers

p5.js Loading lots of images in preload() results in slow performance compared to setup()

I am making a side scroller and trying to load all of the different images for various states of my sprite (running / jumping / idle / etc.). Here is the code that I am trying to run: function create_animation_dict(){ /* Loads all sprites…
Nick Dima
  • 348
  • 1
  • 10
1
vote
1 answer

Creating a piano in p5.js

I am creating a piano using p5.js. I need help with the color change. When a user presses a key, I want the key to flash a quick color change to let them know that they pressed the key. In my code, the color does change when you click on the first…
1
vote
1 answer

Unable to get the mouse clicked function as a constant

Im trying to make a simple game for school, basically its a simple aim trainer. All it needs to do is draw dots, have them killed when you click them then add to your score, then when you click on the background instead of the dots your game is…
1
vote
1 answer

Rotating object in the direction of movement in p5 js

I have been following The Coding Train's coding challenge where he creates a flocking algorithm using cohesion, separation, and alignment. I challenged myself to see if I could rotate each triangle object so they are looking where they are going,…
Tolly Boy101
  • 55
  • 2
  • 10
1
vote
1 answer

Having trouble using instance mode

I am getting errors when I used instance mode in my code. My mini game isn't showing up I am not sure where the error is coming from. It works fine without the instance mode but I need to use the instance mode so that I can reference this code in…
1
vote
1 answer

How to use ASCII code in keyIsDown function

I want to make pong in p5.js web editor to train my programmingskill a bit but i cant seem to find a way to detect ASCII key codes for payer 2`s movement, i provide you the code further down is there any way to convert ASCII codes to movement?…
p3nd_
  • 13
  • 4
1
vote
0 answers

P5.JS - preload() issue

I try to play a song on the browser. When I run the html following occurs : "Uncaught not ready to play file, buffer has yet to load. Try preload()" HTML:
1
vote
1 answer

How to move some rectangles made with the Loop function

How can I move those 6 rectangles. I think i have to change the X and the Y for the loop, but I don't know how. I would love some help. This is the code: https://editor.p5js.org/AlexArek/sketches/r1eVquBkV let cols = 3; let rows =…
Alex Arek
  • 57
  • 7
1
vote
1 answer

Javascript Array Push Replaces Previous Element in The same Array

I am Facing this Problem, my randomPoints array element is getting replaced by push method. Here is the output of my Console I don't know why this is happening but if I don't use randomPoint.add, it dosen't replaces and work fine. randomPoint.add…
imLolman
  • 540
  • 1
  • 5
  • 15
1
vote
1 answer

p5.js rect() detailX and detailY usage?

The official documentation on the P5.js website does not include any descriptive usage of the two mentioned parameters - detailX and detailY (for the rect() function under "Shapes 2D primitives"). The only statements written for these two parameters…
bee5911
  • 516
  • 4
  • 9
1
vote
1 answer

Draw transparent colour - p5js

Is it possible to draw with transparency like you would draw with any colour? For example if i'm using a createGraphics() you can use clear() to make the canvas transparent, but what if I wanted to draw a black background with a see-through hole in…
Jared Parker
  • 390
  • 2
  • 3
  • 16