p5.js

Getting TypeError when trying to call multiline string in p5.js

落花浮王杯 提交于 2019-12-12 05:08:47
问题 I've been trying to work out a solution for taking single-line sentences (which I call "statements" in my code) and turning them into multiline sentences on my sketch. This question relates directly to another question I posted on SO, and I have been asked to post this new issue as a new question. The solution from @KevinWorkman got me the to this point. What's happening, though, is that I'm getting a TypeError: Cannot read property 'display' of undefined when I try to run the program. The

Connecting the HTML input page with p5.js

谁说我不能喝 提交于 2019-12-11 18:32:53
问题 I want to get the data from input tags and use them in the equation. I have tried a lot a lot of solutions, nothing worked. I want it to start setup after click one button, and start animate after pressing the other button. press button1 load the data from the html set up the canvas using those data execute draw() for ever. I did not find much documentation. Here is my html: <label class="col-lg-2" for="n4" id="m2">mass sq 2</label> <input class=" col-lg-2" name="n4" type="number" id="m2"

How to cut off function from global scope

不打扰是莪最后的温柔 提交于 2019-12-11 17:14:57
问题 I have an idea for a game where people can type in some simple instructions for their character like player.goLeft() or player.attackInFront() and for that I have people type their code into a text box and then I parse it into eval(). This works well but it also allows people to change their own character object by typing things like player.health = Infinity; or something similar. I have a list of functions I want to allow people to use, but I am unsure how to restrict it to only use them. I

Play P5.js sound on muted iPhone

柔情痞子 提交于 2019-12-11 15:31:15
问题 I can’t figure out why P5.js won’t play sound on a muted iPhone. I’m new to coding but it seems like a lot of other javascript will play sounds on muted iPhones. Has anyone else wondered about this? I don’t understand why P5 sound won’t play but maybe it was an intentional decision? Is there anyway to override it? Most of what I find is posts from people trying to prevent sounds from playing on muted iPhone. So it seems weird… Here’s a post from stackoverflow trying to figure out how to

p5.js integration with Angular / not using global functions

江枫思渺然 提交于 2019-12-11 15:12:28
问题 In tutorials & youtube channel all examples use sketch.js & global functions & canvas / video tags are automatically created by library. Is there a way to manually create "p5.js context", pass it video & canvas tag and use API on some global object? I would like to write my p5.js code inside my components 回答1: I don't really know anything about Angular, but it sounds like you're looking for instance mode in P5.js. See here for more info, but it looks like this: var s = function( sketch ) {

I have been trying to make this ball bounce for a day. Why doesnt it work?

青春壹個敷衍的年華 提交于 2019-12-11 11:00:44
问题 I am making a ball class, and in that class i want to make the ball bounce off the wall, but it remains stuck. I have tried making the ball bounce in the draw function, but then it didnt even stopped at the wall. I tried setting the this.x and this.y away from the limit so it doesnt loop, but no succes. I am left without choises. I dont know what to do. I am just starting out and im quite enjoying coding, but this is giving me a headache. let r; let g; let b; let xpos; let ypos; let size; let

How to save strings to SPECIFIC location in p5.js

送分小仙女□ 提交于 2019-12-11 10:14:47
问题 Here I have a code that I was playing around with. It loads a string within my file and saves an unimportant one. var file = "1"; var result; var meString; var splitMeString; function preload() { result = loadStrings("assets/save/"+file+".txt"); } function setup() { createCanvas(1000,650); } function draw() { meString = result+''; splitMeString = splitTokens(meString, ','); text(meString,20,20); console.log(splitMeString[2]); } function mousePressed(){ saveStrings("happy"); } but how would I

How can I make backgrounds in p5.js transparent but continue to hide elements drawn on top of them?

拜拜、爱过 提交于 2019-12-11 10:06:08
问题 I'm asking this as a follow-up to this question. I want to create a drawing app where the mouse is replaced by an ellipse that resizes to fit the brush size. The problem was that there was no way to draw the ellipse without leaving a mark on the canvas. The solution I came up with to solve this problem was to use createGraphics() as a buffer object and render the cursor on top of it as such: var brushSize = 60; function setup() { createCanvas(1080,720); pg = createGraphics(1080, 720);

jQuery: How do I clone a div containing a p5 canvas?

偶尔善良 提交于 2019-12-11 07:45:29
问题 Using jQuery to clone a div: $(document).ready(function() { // clicking the buttton $(".showcanvas").click(function() { // cloning and appending the div $(".canvas").first().clone(true).appendTo("article").fadeIn("1200"); }); }); with a p5 canvas inside that div: <script> var sketch = function(p) { p.setup = function(){ p.createCanvas(100, 100); p.background(0); } }; new p5(sketch, 'drawing'); </script> the div clones correctly but the p5 canvas is not there. how do I clone the div so that

Javascript merge sort visualisation

↘锁芯ラ 提交于 2019-12-11 07:38:19
问题 I have managed to get a merge sort working in p5.js to sort different length lines but can not figure out how to actually show them being sorted. I.e show them unsorted and then update their position as they are being sorted. I'm not sure if there is an easy way to do this with the way my code is currently written or if I need to break the sorting function up and re draw it after each stage? var values = []; var numLines = 500; function setup() { createCanvas(900, 600); colorMode(HSB, height)