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
2 answers

Compiler cannot find types from node_modules/@types

I try to load P5 type from my node_modules, but when I compile my code the terminal returns this compilation error message Module not found: Error: Can't resolve 'p5' in '/Users/stan/En_cours/code/github/P5JS_TypeScript_WebPack/Template_V2/src' @…
Knupel
  • 323
  • 2
  • 14
1
vote
1 answer

How to "pause" during merge sort to visualize JS p5js

Im working on a sorting visualizer using p5.js, and I need to know if its possible to slow down merge sort so it can be drawn slower. Im currently trying to use the sleep function below to slow down they merge function, but I get Uncaught…
Brian Lobo
  • 13
  • 6
1
vote
1 answer

How to Centre an object in any cell of an 8x8 grid in p5.js framework

This is my code of making a chess game. let pawn1; //variable for object var offset = 10; function setup(){ createCanvas(600,600); // canvas pawn1 = new Pawn(); // pawn1 is a new Pawn object } function draw(){ background(0); //black…
1
vote
1 answer

JavaScript moving an object from starting location to ending location

I'm currently taking a course on intro to computer programming. It's an online course and doesn't have much help when you're stuck. I'm using Brackets and p5.js and I'm given a template to start off with. I seem to have done everything needed so…
Renzo
  • 13
  • 4
1
vote
1 answer

p5js for loop programming Q: how to make circles bigger and brighter near mouse pointer

I wrote this function in p5js, where the circles get smaller near the pointer. I want it to do the opposite through. I want to make the circles bigger near the pointer. I also want them to get brighter near the mouse. But I haven't been able to…
user12159663
1
vote
1 answer

Very newbie troubleshooting. Basic p5.js index.html setup on Atom, not generating anything on browser?

literally just got into the world of coding, so if my question seems absolutely insane, I do apologise. Anywho, was following some tutorials (Daniel Shiffman's https://www.youtube.com/watch?v=HZ4D3wDRaec) how to setup a basic p5.js file on Atom,…
wardrobefanatic
  • 101
  • 1
  • 3
1
vote
0 answers

Codepen prevents p5.dom webcam capture

I developed some working code on the p5.js Web editor and wanted to port it to Codepen for further work. Even the following example from the processing website fails to work: let capture; function setup() { createCanvas(390, 240); capture =…
John Coleman
  • 51,337
  • 7
  • 54
  • 119
1
vote
1 answer

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…
jabberwoo
  • 491
  • 6
  • 18
1
vote
1 answer

Is there a way to find which txt file a string comes from with javascript?

I have a randomly generated sentence from 16 txt files and I'm trying to reverse engineer the function so that I could see which sentence corresponds to which txt file. I'm using if/else right now but it's very slow and I'm wondering if there's…
ntz
  • 13
  • 2
1
vote
2 answers

How to get integers from an array of arrays?

I have an array of arrays. It's a map for a game. The ones represent walls. var walls = [] walls.push([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) walls.push([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
Jens
  • 183
  • 1
  • 10
1
vote
3 answers

Function not recognized as a function?

I'm in deep water at the moment. Not sure I know what I'm doing! Anyway, I'm trying to make a map for my snake game. At the moment I'm trying to add a wall but it wont work! This is the code: https://editor.p5js.org/JensHaglof/sketches/YwtUO8992 Or…
Jens
  • 183
  • 1
  • 10
1
vote
1 answer

All elements in array before selected being deleted

Probably just something dumb but I'm rewriting Galaga in p5.js for a university assignment and towards the beginning I'm at destroying enemies. When a bullet is fired and it hits say the third enemy on the screen, all of the enemies before it are…
J.Smart
  • 13
  • 2
1
vote
1 answer

how can i make an array interact with a object in a intersects() function?

snake = new Boks(300,300,10,10) let apple = []; for(i = 0; i<5; i++){ let x = random(20,560); let y = random(20, 560) apple[i] = new Boks(x,y,10,10) } for(i = 0; i
Mr.Ulis
  • 157
  • 6
1
vote
1 answer

How can i use DOM events inside my javascript classes?

I am trying to make a function inside my class, where by pressing the ArrowUp key, it will become true. However, it just says: "Cannot read property 'key' of undefined? class Boks{ constructor(x,y,w,h,r,k){ this.x = x; this.y = y; …
Mr.Ulis
  • 157
  • 6
1
vote
0 answers

Colors not changing when button is pressed P5.JS package

So I'm making a paint program for my computer science class in JavaScript using the p5.js package. However when changing colors between white and black, and red and black the black paint color stays red. I've tried checking if the red, white and…