p5.js

Shuffling multidimensional array in js

我们两清 提交于 2020-07-05 12:34:43
问题 This function shuffles only matrix[y], but I want it to shuffle matrix[y][x] But it doesn't want to shuffle correctly. The code what I used: function Shuffle(arguments) { for (var k = 0; k < arguments.length; k++) { var i = arguments[k].length; if (i == 0) return false; else { while (--i) { var j = Math.floor(Math.random() * (i + 1)); var tempi = arguments[k][i]; var tempj = arguments[k][j]; arguments[k][i] = tempj; arguments[k][j] = tempi; } return arguments; } } return arguments } var

Using p5.sound.js in instance mode: 'p5.Amplitude() not a constructor'

冷暖自知 提交于 2020-05-27 02:36:11
问题 I am using an npm, webpack, babel environment to write an application with p5.js. To be able to have the sketch as a module, I have the sketch in instance mode and import the library and add-ons as modules: import p5 from 'p5'; import 'p5/lib/addons/p5.sound'; import 'p5/lib/addons/p5.dom'; Then I load them to the window inside my sketch: const sketch = (p5) => { window.p5 = p5; ... } new p5(sketch); When I try to use: amp = new p5.Amplitude() I get a 'p5.Amplitude is not a constructor' error

Using p5.sound.js in instance mode: 'p5.Amplitude() not a constructor'

冷暖自知 提交于 2020-05-27 02:34:07
问题 I am using an npm, webpack, babel environment to write an application with p5.js. To be able to have the sketch as a module, I have the sketch in instance mode and import the library and add-ons as modules: import p5 from 'p5'; import 'p5/lib/addons/p5.sound'; import 'p5/lib/addons/p5.dom'; Then I load them to the window inside my sketch: const sketch = (p5) => { window.p5 = p5; ... } new p5(sketch); When I try to use: amp = new p5.Amplitude() I get a 'p5.Amplitude is not a constructor' error

Independent random generations in Javascript / p5.js

冷暖自知 提交于 2020-05-24 07:29:31
问题 In P5.js, I often have to write more than one line of random in order to get independent random generation such as : random(); random(); random(); // or a = random(); b = random(); c = random(); //etc is there any alternative code(s) in p5.js or javascript that can perform the same/similar generations and so the code efficiency can be improve? Thanks 回答1: If you're putting random numbers into an array, you can do it concisely with Array.from : const random = () => Math.random(); const arr =

p5.js createCanvas not defined error. Uncaught ReferenceError

微笑、不失礼 提交于 2020-05-15 00:58:22
问题 Problem: I am trying to use p5.js in my simple app, and including it thus: <script src="static/js/p5.js"> </script> What I've tried: If I put a debugger and look in the console, I do get the functions for p5Color (for ex) and others. And the script gets loaded on to the page fine. Except createCanvas doesn't auto-complete and when used in the page, throws above error. Why? How can I work around this? 回答1: p5.js won't load into "global mode" unless it sees setup() or draw() defined on the page

p5.js manually call setup and draw

删除回忆录丶 提交于 2020-01-13 04:12:12
问题 I am making an online game with p5.js and I would like to manually call setup, and once setup is called I want draw() to run. For example, if I click a button: <button id="somebutton" onclick="setup()">CLICK ME!!!</button> Then the canvas will be created and all of the stuff in setup will be run and draw() will run. 回答1: Why do you want to do this? Processing needs to do a bunch of things related to calling the setup() function, so there's almost never a good reason for you to call it

Colision detection p5.js

若如初见. 提交于 2020-01-11 11:55:10
问题 just trying to make a simple pong game in p5.js. I have very recently gotten into JavaScript and can't manage to figure out collision detection between the ball and the bat. I have tried a few ways of doing it but it mostly just stopped my code from running.. etc.. would love any help! Here is my source code: function setup() { createCanvas(750, 750); } var x = 50; var y = 50; var direction = 5; var arrow = 0; var ball; var bat; function draw() { background(220); fill ('white'); ball =

Save tracking data from Leap Motion with p5.js to .csv

匆匆过客 提交于 2020-01-05 04:20:11
问题 I need to write a script in p5.js to track the position of the five fingertips (on one or both hands) at a set interval (e.g. 20 ms), and then save the time-finger data to a .csv I have previously done this in Processing with Table and getting the PVector for the fingers, but I have no idea on how to do this with javascript. Any and all input would be greatly appreciated! 回答1: Stack Overflow isn't really designed for general "how do I do this" type questions. It's for specific "I tried X,

p5 set fill color using hex string and alpha

这一生的挚爱 提交于 2020-01-03 04:46:03
问题 I'm trying to use hexadecimal values for colors in p5.js and I'm having trouble using it and using an alpha at the same time. I'd like to set the color with one variable and the alpha with another. let myColor = '#FF0000'; let myAlpha = 128; function setup() { createCanvas(200,200); } function draw() { fill(color(myColor), myAlpha); noStroke(); ellipse(100, 100, 50, 50); } <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.16/p5.js"></script> <html> <head></head> <body></body> <