# Coding Questions

**URL:** https://discourse.processing.org/c/p5js/p5js-questions/18.md?page=36

[Latest](https://discourse.processing.org/latest.md) · [Categories](https://discourse.processing.org/categories.md) · [Tags](https://discourse.processing.org/tags.md)

**Page:** 37

---

## [Question about using a for loop to execute a function multiple times](https://discourse.processing.org/t/question-about-using-a-for-loop-to-execute-a-function-multiple-times/17369)

<div class="topic-metadata">

**Author:** [@ZachMcMkay](https://discourse.processing.org/u/ZachMcMkay)\
**Replies:** 1\
**Last updated:** [January 27, 2020, 9:22am UTC](https://discourse.processing.org/t/question-about-using-a-for-loop-to-execute-a-function-multiple-times/17369 "2020-01-27T09:22:48Z")

</div>

I have a function that I know is running without errors if called once through the draw loop. In order to increase the “speed” of the function i ran the function in a for loop. Meaning, instead of just calling the func…

---

## [Surely there has to be a better way to do this](https://discourse.processing.org/t/surely-there-has-to-be-a-better-way-to-do-this/17246)

<div class="topic-metadata">

**Author:** [@ZachMcMkay](https://discourse.processing.org/u/ZachMcMkay)\
**Replies:** 2\
**Last updated:** [January 22, 2020, 5:59pm UTC](https://discourse.processing.org/t/surely-there-has-to-be-a-better-way-to-do-this/17246 "2020-01-22T17:59:17Z")

</div>

What i wanted to do was take an array of integers and get all permutations of that array keeping the same length. I was using the array \[1,2,3,4,5\] after trying for a bit i just decided to do it the hard way. However i…

---

## [Set Focus to an DOM Input Field](https://discourse.processing.org/t/set-focus-to-an-dom-input-field/17140)

<div class="topic-metadata">

**Author:** [@olafval](https://discourse.processing.org/u/olafval)\
**Replies:** 2\
**Last updated:** [January 21, 2020, 10:01am UTC](https://discourse.processing.org/t/set-focus-to-an-dom-input-field/17140 "2020-01-21T10:01:23Z")

</div>

How is it possible to select an input field directly by code, so that you can start typing right away? I have tried the following commands without success: input.focus(); input.style(‘focus’, true); input.style(‘focu…

---

## [Video auto play](https://discourse.processing.org/t/video-auto-play/17195)

<div class="topic-metadata">

**Author:** [@airinterface](https://discourse.processing.org/u/airinterface)\
**Replies:** 1\
**Last updated:** [January 21, 2020, 4:24am UTC](https://discourse.processing.org/t/video-auto-play/17195 "2020-01-21T04:24:47Z")

</div>

I’m having trouble stopping autoplay. video = createCapture(VIDEO, function( stream ) { console.info("video stream initialized"); video.stop(); }); video.autoplay( false ) ; video…

---

## [Optimising loadImage, fitting image ratio](https://discourse.processing.org/t/optimising-loadimage-fitting-image-ratio/17200)

<div class="topic-metadata">

**Author:** [@nikodemd](https://discourse.processing.org/u/nikodemd)\
**Replies:** 2\
**Last updated:** [January 20, 2020, 2:00pm UTC](https://discourse.processing.org/t/optimising-loadimage-fitting-image-ratio/17200 "2020-01-20T14:00:29Z")

</div>

Hi guys, new here! I am making this app where I load 2 images and 2 sliders, and each slider controls the level that the image blend with each other. Basically: image DAYLIGHT is a picture of a room only with light from…

---

## [Trails with background Transparency](https://discourse.processing.org/t/trails-with-background-transparency/17139)

<div class="topic-metadata">

**Author:** [@Skranker](https://discourse.processing.org/u/Skranker)\
**Replies:** 2\
**Last updated:** [January 18, 2020, 12:22pm UTC](https://discourse.processing.org/t/trails-with-background-transparency/17139 "2020-01-18T12:22:17Z")

</div>

Hey everyone, i’m using background(0, 10); to get a trail effect, but i get these weird permanent trails that dont go away. Usually the screen should be black again if the background has been drawn enough times. Not s…

---

## [Only take the Top One](https://discourse.processing.org/t/only-take-the-top-one/17115)

<div class="topic-metadata">

**Author:** [@phoebus](https://discourse.processing.org/u/phoebus)\
**Replies:** 3\
**Last updated:** [January 16, 2020, 12:18pm UTC](https://discourse.processing.org/t/only-take-the-top-one/17115 "2020-01-16T12:18:51Z")

</div>

Hi there, long time no see :slight\_smile: I want to make some sort of 2d picking on a 2D sketch: I made a test “isOver” on my objects, so my objects change color when mouse is over ( dist(mouseX…) So in my main I get …

---

## [Assigning mouseOver to object in instance mode](https://discourse.processing.org/t/assigning-mouseover-to-object-in-instance-mode/17104)

<div class="topic-metadata">

**Author:** [@lnp](https://discourse.processing.org/u/lnp)\
**Replies:** 4\
**Last updated:** [January 15, 2020, 9:40pm UTC](https://discourse.processing.org/t/assigning-mouseover-to-object-in-instance-mode/17104 "2020-01-15T21:40:40Z")

</div>

Hello peeps! I don’t really see how I can assign a mouseOver listener to generated objects in instance mode. This doesn’t work for obvious reasons (looking for the function in the object). I tried p.glyphs\_to\_show\[n\].m…

---

## [How to use asset fonts in p5](https://discourse.processing.org/t/how-to-use-asset-fonts-in-p5/17037)

<div class="topic-metadata">

**Author:** [@gregts13](https://discourse.processing.org/u/gregts13)\
**Replies:** 8\
**Last updated:** [January 13, 2020, 2:03am UTC](https://discourse.processing.org/t/how-to-use-asset-fonts-in-p5/17037 "2020-01-13T02:03:47Z")

</div>

Honored motorcycle by gregeb13 -p5.js Web Editor Error: Unsupported OpenType signature p5.js says: It looks like there was a problem loading your font. Try checking if the file path \[assets/Bold.ttf\] is correct, hostin…

---

## [Mitosis chain reaction, cant get it under control](https://discourse.processing.org/t/mitosis-chain-reaction-cant-get-it-under-control/16937)

<div class="topic-metadata">

**Author:** [@ZenVega](https://discourse.processing.org/u/ZenVega)\
**Replies:** 2\
**Last updated:** [January 8, 2020, 6:38am UTC](https://discourse.processing.org/t/mitosis-chain-reaction-cant-get-it-under-control/16937 "2020-01-08T06:38:07Z")

</div>

Hey all, so i created this advanced version of the mitosis simulation challange (‘https://thecodingtrain.com/CodingChallenges/006-mitosis-p5.html’) and among others included a function to remerge the cells. It kinda wor…

---

## [Way to check if draw() is currently looping?](https://discourse.processing.org/t/way-to-check-if-draw-is-currently-looping/16946)

<div class="topic-metadata">

**Author:** [@maayan](https://discourse.processing.org/u/maayan)\
**Replies:** 2\
**Last updated:** [January 8, 2020, 4:12am UTC](https://discourse.processing.org/t/way-to-check-if-draw-is-currently-looping/16946 "2020-01-08T04:12:08Z")

</div>

Is there any way to check if draw() is currently looping (ie if loop/noLoop was called)? There doesn’t seem to be a way to do this in the p5 library so is there some way to check under the hood?

---

## [Disappearing/ appearing items when I click a button](https://discourse.processing.org/t/disappearing-appearing-items-when-i-click-a-button/16866)

<div class="topic-metadata">

**Author:** [@Csperedakos11](https://discourse.processing.org/u/Csperedakos11)\
**Replies:** 3\
**Last updated:** [January 4, 2020, 8:55pm UTC](https://discourse.processing.org/t/disappearing-appearing-items-when-i-click-a-button/16866 "2020-01-04T20:55:00Z")

</div>

Hi all, I’m pretty new at p5 so I’m sure my problem is fairly easy to solve, but I’ve been trying to figure it out for some time and have not been able to successfully. My Project Basically, I am trying to create a bun…

---

## [Change cursor() in instance mode](https://discourse.processing.org/t/change-cursor-in-instance-mode/16894)

<div class="topic-metadata">

**Author:** [@lnp](https://discourse.processing.org/u/lnp)\
**Replies:** 2\
**Last updated:** [January 6, 2020, 3:40pm UTC](https://discourse.processing.org/t/change-cursor-in-instance-mode/16894 "2020-01-06T15:40:41Z")

</div>

Happy new year yo! Absolutely no problem with changing the cursor in global mode but unfortunately I can’t get it to in instance mode - or even any kind of error in the console. The sketch canvas is part of a site and I…

---

## [ReferenceError: loadModel is not defined](https://discourse.processing.org/t/referenceerror-loadmodel-is-not-defined/16877)

<div class="topic-metadata">

**Author:** [@micheal](https://discourse.processing.org/u/micheal)\
**Replies:** 11\
**Last updated:** [January 5, 2020, 5:51pm UTC](https://discourse.processing.org/t/referenceerror-loadmodel-is-not-defined/16877 "2020-01-05T17:51:37Z")

</div>

Hi there I’m a new user of p5js and loving learning what’s possible! Can I get some advice please about the loadModel function? I’m getting the error in console.log: “ReferenceError: loadModel is not defined” I can’…

---

## [Move the 2d camera has the player move](https://discourse.processing.org/t/move-the-2d-camera-has-the-player-move/16851)

<div class="topic-metadata">

**Author:** [@Westergard](https://discourse.processing.org/u/Westergard)\
**Replies:** 1\
**Last updated:** [January 4, 2020, 8:22am UTC](https://discourse.processing.org/t/move-the-2d-camera-has-the-player-move/16851 "2020-01-04T08:22:55Z")

</div>

Hello, I am doing a “Mario game” and I want my 2d view to automatically move around to follow the player has he move. Please help me! Thanks! :grin:

---

## [P5.js - sketch trying to load images from previous sketches](https://discourse.processing.org/t/p5-js-sketch-trying-to-load-images-from-previous-sketches/16830)

<div class="topic-metadata">

**Author:** [@rebekah\_tkd](https://discourse.processing.org/u/rebekah_tkd)\
**Replies:** 2\
**Last updated:** [January 4, 2020, 2:16am UTC](https://discourse.processing.org/t/p5-js-sketch-trying-to-load-images-from-previous-sketches/16830 "2020-01-04T02:16:05Z")

</div>

I’m trying to call an array of images. My sketch keeps trying to load images which are not added within the sketch. These files were loaded in previous sketches, therefore this somehow overrides the images I am attempted…

---

## [Flickering in Exclusion](https://discourse.processing.org/t/flickering-in-exclusion/16760)

<div class="topic-metadata">

**Author:** [@musiciantriescoding](https://discourse.processing.org/u/musiciantriescoding)\
**Replies:** 8\
**Last updated:** [December 31, 2019, 10:01pm UTC](https://discourse.processing.org/t/flickering-in-exclusion/16760 "2019-12-31T22:01:33Z")

</div>

Hi everyone! I’m trying to play with the blend modes in P5, specifically to play around with black and white. When I use the code below, I expected a black line across a white canvas. However, I got the line and the canv…

---

## [CORS issue when loading JSON in p5](https://discourse.processing.org/t/cors-issue-when-loading-json-in-p5/16727)

<div class="topic-metadata">

**Author:** [@gjs](https://discourse.processing.org/u/gjs)\
**Replies:** 2\
**Last updated:** [December 30, 2019, 8:19pm UTC](https://discourse.processing.org/t/cors-issue-when-loading-json-in-p5/16727 "2019-12-30T20:19:38Z")

</div>

I’m attempting to load a JSON and receive the following message: “Access to fetch at ‘https://api.flightstats.com/flex/schedules/rest/v1/json/flight/AA/100/departing/2020/1/31?appId=XXX&appKey=XXX’ from origin ‘https://…

---

## [Zoom and save as png](https://discourse.processing.org/t/zoom-and-save-as-png/16729)

<div class="topic-metadata">

**Author:** [@monk-e-boy](https://discourse.processing.org/u/monk-e-boy)\
**Replies:** 4\
**Last updated:** [December 30, 2019, 8:00pm UTC](https://discourse.processing.org/t/zoom-and-save-as-png/16729 "2019-12-30T20:00:03Z")

</div>

I can save my canvas as a .png :slight\_smile: how do I zoom it in first? I am creating a D&D grid, I would like to save it so each square is 1 inch across. I would like to save it with a transparent background. https:…

---

## [If condition breaks for loop in recursive function](https://discourse.processing.org/t/if-condition-breaks-for-loop-in-recursive-function/16717)

<div class="topic-metadata">

**Author:** [@musiciantriescoding](https://discourse.processing.org/u/musiciantriescoding)\
**Replies:** 3\
**Last updated:** [December 30, 2019, 11:08am UTC](https://discourse.processing.org/t/if-condition-breaks-for-loop-in-recursive-function/16717 "2019-12-30T11:08:08Z")

</div>

Hi everyone! I have come across what I think may be a bug. I am just testing a recursive function which: Draws 6 circles around a circle for each circle, draw 6 circles around it. This is the following code I wrote. (…

---

## [Can I use multiple p5.js on my website..?](https://discourse.processing.org/t/can-i-use-multiple-p5-js-on-my-website/16522)

<div class="topic-metadata">

**Author:** [@Sejin.OH](https://discourse.processing.org/u/Sejin.OH)\
**Replies:** 2\
**Last updated:** [December 29, 2019, 4:29pm UTC](https://discourse.processing.org/t/can-i-use-multiple-p5-js-on-my-website/16522 "2019-12-29T16:29:21Z")

</div>

Hello, I have a website where I want to use my portfolio… but I tried my work(p5.js) with a script on my website but couldn’t succeed more than one. Is there a way to upload multiple p5.js in html differently? Thanks fo…

---

## [Using textToPoints() with an already loaded font](https://discourse.processing.org/t/using-texttopoints-with-an-already-loaded-font/16651)

<div class="topic-metadata">

**Author:** [@Seyka](https://discourse.processing.org/u/Seyka)\
**Replies:** 3\
**Last updated:** [December 27, 2019, 2:17pm UTC](https://discourse.processing.org/t/using-texttopoints-with-an-already-loaded-font/16651 "2019-12-27T14:17:02Z")

</div>

Hi, I am using the textToPoints() function in a project, but since textToPoints() is part of the prototype of p5.Font I need to use it with a font loaded with loadFont(). But I can’t find a way to get a reference to an …

---

## [Glitches and crashes appearing on p5.js app in Google Chrome](https://discourse.processing.org/t/glitches-and-crashes-appearing-on-p5-js-app-in-google-chrome/16641)

<div class="topic-metadata">

**Author:** [@Ackados](https://discourse.processing.org/u/Ackados)\
**Replies:** 1\
**Last updated:** [December 27, 2019, 11:16am UTC](https://discourse.processing.org/t/glitches-and-crashes-appearing-on-p5-js-app-in-google-chrome/16641 "2019-12-27T11:16:12Z")

</div>

I am not sure if this a problem from my code or a problem from Google Chrome itself, but I am seeing this “glitch”. Then after a while this tab that I am working on with Processing “crashes” or restarts. I don’t see a…

---

## [Drawing triangle to face toward it's velocity](https://discourse.processing.org/t/drawing-triangle-to-face-toward-its-velocity/16642)

<div class="topic-metadata">

**Author:** [@Ackados](https://discourse.processing.org/u/Ackados)\
**Replies:** 2\
**Last updated:** [December 27, 2019, 2:01am UTC](https://discourse.processing.org/t/drawing-triangle-to-face-toward-its-velocity/16642 "2019-12-27T02:01:21Z")

</div>

I know you can use vector.heading() to get the angle of direction. I have been using this in my code but it’s not working correctly. class Boid { constructor() { this.loc = createVector(); this.vel =…

---

## [Two canvases on the same page + keyboard](https://discourse.processing.org/t/two-canvases-on-the-same-page-keyboard/16645)

<div class="topic-metadata">

**Author:** [@tanzor](https://discourse.processing.org/u/tanzor)\
**Replies:** 3\
**Last updated:** [December 26, 2019, 8:54pm UTC](https://discourse.processing.org/t/two-canvases-on-the-same-page-keyboard/16645 "2019-12-26T20:54:40Z")

</div>

Hello community, I’m trying to have two canvases within the same HTML page, such that both canvases react to key presses. For some reason only the first canvas is reactive, and the second canvas is not. Here’s a minimi…

---

## [Video Playback Problem](https://discourse.processing.org/t/video-playback-problem/16520)

<div class="topic-metadata">

**Author:** [@Comradetony](https://discourse.processing.org/u/Comradetony)\
**Replies:** 1\
**Last updated:** [December 20, 2019, 2:12am UTC](https://discourse.processing.org/t/video-playback-problem/16520 "2019-12-20T02:12:37Z")

</div>

Hi. I’m trying to make it so this sketch plays videos upon clicking the images, but so far I have not been able to make the videos play at all, let alone swap between them freely. var immol; var i = 'Immolation1.mp4'; v…

---

## [Div as Canvas -\> possible to save down?](https://discourse.processing.org/t/div-as-canvas-possible-to-save-down/16478)

<div class="topic-metadata">

**Author:** [@potipoo](https://discourse.processing.org/u/potipoo)\
**Replies:** 1\
**Last updated:** [December 18, 2019, 1:21am UTC](https://discourse.processing.org/t/div-as-canvas-possible-to-save-down/16478 "2019-12-18T01:21:03Z")

</div>

Hi, I’ve created a document where all my p5.js code changes the attributes of a I am now wondering, is there a way of saving down the div? or to make the div appear as a canvas? Thanks in advance, Cheers Andy

---

## [Getting nothing when trying to show image with the help of HTML tag](https://discourse.processing.org/t/getting-nothing-when-trying-to-show-image-with-the-help-of-html-tag/16378)

<div class="topic-metadata">

**Author:** [@RadheTians](https://discourse.processing.org/u/RadheTians)\
**Replies:** 6\
**Last updated:** [December 16, 2019, 6:47am UTC](https://discourse.processing.org/t/getting-nothing-when-trying-to-show-image-with-the-help-of-html-tag/16378 "2019-12-16T06:47:37Z")

</div>

I noticed that when I was trying to show an image on canvas with the help of HTML tags(i.e input tag and type is file) the codebase wasn’t showing an image and when I was trying to show with the help of p5.js function c…

---

## [Change x position of an array of lines](https://discourse.processing.org/t/change-x-position-of-an-array-of-lines/16427)

<div class="topic-metadata">

**Author:** [@Tilia](https://discourse.processing.org/u/Tilia)\
**Replies:** 1\
**Last updated:** [December 16, 2019, 3:18am UTC](https://discourse.processing.org/t/change-x-position-of-an-array-of-lines/16427 "2019-12-16T03:18:51Z")

</div>

hi Leute could someone explain me why i cannot change the x position of an array of lines by pressing the arrow keyes? the lines (looking like a sun) have all the same x position (0,0) translated to the middle of the c…

---

## [Problems with the video.size (number1, number2) function;](https://discourse.processing.org/t/problems-with-the-video-size-number1-number2-function/16331)

<div class="topic-metadata">

**Author:** [@willianxz](https://discourse.processing.org/u/willianxz)\
**Replies:** 7\
**Last updated:** [December 13, 2019, 12:36pm UTC](https://discourse.processing.org/t/problems-with-the-video-size-number1-number2-function/16331 "2019-12-13T12:36:21Z")

</div>

Now in 2019, for reasons of some update of P5.JS or browsers, the video.size function (number1, number2); Does not work, breaking or code. Here is the error: undefined p5.js: 61127 Uncaught IndexSizeError: Failed to …

[Previous page](https://discourse.processing.org/c/p5js/p5js-questions/18.md?page=35)

[Next page](https://discourse.processing.org/c/p5js/p5js-questions/18.md?page=37)
