# Coding Questions

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

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

**Page:** 30

---

## [Cull or Remove polygon backfaces with OpenGL](https://discourse.processing.org/t/cull-or-remove-polygon-backfaces-with-opengl/22673)

<div class="topic-metadata">

**Author:** [@CND](https://discourse.processing.org/u/CND)\
**Replies:** 0\
**Last updated:** [July 16, 2020, 10:00pm UTC](https://discourse.processing.org/t/cull-or-remove-polygon-backfaces-with-opengl/22673 "2020-07-16T22:00:29Z")

</div>

OpenGL has a command to cull backfaces “glCullFace”. I would like to know how to execute this. I want to view semi-wireframe images only showing framed front faces. This is a larger question on how to execute other Ope…

---

## [Lerp() not working as expected in animation between array position values](https://discourse.processing.org/t/lerp-not-working-as-expected-in-animation-between-array-position-values/22670)

<div class="topic-metadata">

**Author:** [@fpalla](https://discourse.processing.org/u/fpalla)\
**Replies:** 5\
**Last updated:** [July 16, 2020, 9:43pm UTC](https://discourse.processing.org/t/lerp-not-working-as-expected-in-animation-between-array-position-values/22670 "2020-07-16T21:43:47Z")

</div>

Hello forum/guys/people who understand js better than me, feels like kind of a noob question but I don’t think my knowledge at this point is sufficeint to figure out on my own. Either this or I’m blind to something. Rea…

---

## [A function that takes in a function Y and a number, and returns a function which when called, invokes Y some number of times](https://discourse.processing.org/t/a-function-that-takes-in-a-function-y-and-a-number-and-returns-a-function-which-when-called-invokes-y-some-number-of-times/22512)

<div class="topic-metadata">

**Author:** [@Biggy](https://discourse.processing.org/u/Biggy)\
**Replies:** 5\
**Last updated:** [July 15, 2020, 1:02am UTC](https://discourse.processing.org/t/a-function-that-takes-in-a-function-y-and-a-number-and-returns-a-function-which-when-called-invokes-y-some-number-of-times/22512 "2020-07-15T01:02:14Z")

</div>

please format code with \</\> button \* homework policy \* asking questions function loopable(n, func) { return function (...args) { function looper() { if (n === 0) { return undefined; } n -=…

---

## [Issues with different webcam resolutions & video capture](https://discourse.processing.org/t/issues-with-different-webcam-resolutions-video-capture/22568)

<div class="topic-metadata">

**Author:** [@Paraclete\_Pizza](https://discourse.processing.org/u/Paraclete_Pizza)\
**Replies:** 0\
**Last updated:** [July 12, 2020, 1:06pm UTC](https://discourse.processing.org/t/issues-with-different-webcam-resolutions-video-capture/22568 "2020-07-12T13:06:44Z")

</div>

Hi! I recently adapted my Processing curriculum to P5 for some remote teaching I’m doing, and an issue came up during our webcam project, owing to the students working on different computers with different webcam resolut…

---

## [Resizing problem: blurring images](https://discourse.processing.org/t/resizing-problem-blurring-images/22552)

<div class="topic-metadata">

**Author:** [@agrgal](https://discourse.processing.org/u/agrgal)\
**Replies:** 2\
**Last updated:** [July 12, 2020, 9:37am UTC](https://discourse.processing.org/t/resizing-problem-blurring-images/22552 "2020-07-12T09:37:00Z")

</div>

Hi to everybody, First of all, excuse my English. Besides of that, I’m a newbie on p5.js :slight\_smile: I developed a series of programs coded in p5.js and processing that you can find in: https://github.com/agrgal/sis…

---

## [How to move pad with touch](https://discourse.processing.org/t/how-to-move-pad-with-touch/22506)

<div class="topic-metadata">

**Author:** [@bismarck](https://discourse.processing.org/u/bismarck)\
**Replies:** 2\
**Last updated:** [July 10, 2020, 10:00pm UTC](https://discourse.processing.org/t/how-to-move-pad-with-touch/22506 "2020-07-10T22:00:43Z")

</div>

let position1 = 100; let position2 = 100; function setup() { createCanvas(400, 400); } function draw() { background(220); rect(0,position2,10,100); rect(width-10,position1,10,100); if(mouseX \> width/2){…

---

## [Making a photo scanner with transforming picture](https://discourse.processing.org/t/making-a-photo-scanner-with-transforming-picture/22539)

<div class="topic-metadata">

**Author:** [@lin.liangchen](https://discourse.processing.org/u/lin.liangchen)\
**Replies:** 0\
**Last updated:** [July 10, 2020, 5:04pm UTC](https://discourse.processing.org/t/making-a-photo-scanner-with-transforming-picture/22539 "2020-07-10T17:04:30Z")

</div>

Hi everyone, I am new here. I am trying to program a code which is making a photo scanner, to scan the photo pixels with mouse moving. However, I change the photo size by ratio to make smaller, but the scanner only up…

---

## [Webgl 3d point mouse interaction](https://discourse.processing.org/t/webgl-3d-point-mouse-interaction/22526)

<div class="topic-metadata">

**Author:** [@nomad](https://discourse.processing.org/u/nomad)\
**Replies:** 2\
**Last updated:** [July 10, 2020, 4:26pm UTC](https://discourse.processing.org/t/webgl-3d-point-mouse-interaction/22526 "2020-07-10T16:26:34Z")

</div>

Hello there, I have a collection of points in 3d space. they are rotating around a center. Would like to create a simple mouse interaction where they change color when I hover the mouse on them. my code is as follows …

---

## [Question About Multiple Collisions At Once (Kinda)](https://discourse.processing.org/t/question-about-multiple-collisions-at-once-kinda/22461)

<div class="topic-metadata">

**Author:** [@The99thTroll](https://discourse.processing.org/u/The99thTroll)\
**Replies:** 7\
**Last updated:** [July 8, 2020, 9:20pm UTC](https://discourse.processing.org/t/question-about-multiple-collisions-at-once-kinda/22461 "2020-07-08T21:20:15Z")

</div>

So, I’m in the process of making a tower defense game. Currently the way it works is that when an enemy touches the collider of the tower, the tower locks on to that enemy and no others until that enemy is out of range o…

---

## [Does video.size() function doesn’t work properly for pixel manipulation](https://discourse.processing.org/t/does-video-size-function-doesn-t-work-properly-for-pixel-manipulation/22489)

<div class="topic-metadata">

**Author:** [@maddyna](https://discourse.processing.org/u/maddyna)\
**Replies:** 0\
**Last updated:** [July 8, 2020, 8:09pm UTC](https://discourse.processing.org/t/does-video-size-function-doesn-t-work-properly-for-pixel-manipulation/22489 "2020-07-08T20:09:30Z")

</div>

\<does video.size() function doesn’t work properly for pixel manipulation. the moment i am using it I am getting a black screen in the canvas though the video is running in the browser I am sending the code: let video; …

---

## [How to make a better zoom with orbitControl()?](https://discourse.processing.org/t/how-to-make-a-better-zoom-with-orbitcontrol/12978)

<div class="topic-metadata">

**Author:** [@NeilTheSeal](https://discourse.processing.org/u/NeilTheSeal)\
**Replies:** 4\
**Last updated:** [July 6, 2020, 5:48pm UTC](https://discourse.processing.org/t/how-to-make-a-better-zoom-with-orbitcontrol/12978 "2020-07-06T17:48:24Z")

</div>

I have been trying to figure out a way to adjust the sensitivity of the scroll wheel in WebGL mode, because zooming in and out on my sketch is extremely difficult and you have to be almost violent with your scroll wheel …

---

## [Maximum image size saveable from offscreen buffer?](https://discourse.processing.org/t/maximum-image-size-saveable-from-offscreen-buffer/22429)

<div class="topic-metadata">

**Author:** [@grege2](https://discourse.processing.org/u/grege2)\
**Replies:** 5\
**Last updated:** [July 7, 2020, 7:05am UTC](https://discourse.processing.org/t/maximum-image-size-saveable-from-offscreen-buffer/22429 "2020-07-07T07:05:02Z")

</div>

Hi folks, I’m trying to verify and understand the maximum image size that can be saved from an offscreen createGraphics() buffer. Here’s a sketch I used to test it. https://editor.p5js.org/grege2/sketches/OchyJsPRY I …

---

## [Is it possible to check if a sprite was destroyed?](https://discourse.processing.org/t/is-it-possible-to-check-if-a-sprite-was-destroyed/22369)

<div class="topic-metadata">

**Author:** [@The99thTroll](https://discourse.processing.org/u/The99thTroll)\
**Replies:** 1\
**Last updated:** [July 5, 2020, 8:44am UTC](https://discourse.processing.org/t/is-it-possible-to-check-if-a-sprite-was-destroyed/22369 "2020-07-05T08:44:03Z")

</div>

The title basically says it all. Is there a way to detect if a sprite is destroyed so I can manipulate a different sprite later on?

---

## [How to change a line stroke after its been set?](https://discourse.processing.org/t/how-to-change-a-line-stroke-after-its-been-set/22386)

<div class="topic-metadata">

**Author:** [@FireMe](https://discourse.processing.org/u/FireMe)\
**Replies:** 5\
**Last updated:** [July 4, 2020, 6:40pm UTC](https://discourse.processing.org/t/how-to-change-a-line-stroke-after-its-been-set/22386 "2020-07-04T18:40:46Z")

</div>

Hi All, Im completely new here and to code tbh, I followed this tutorial on a gift wrapping algorithm, which of course was fairly easy to follow, problems arise when i want to do something different to the tutorial. The…

---

## [Mouse dragged in P5js](https://discourse.processing.org/t/mouse-dragged-in-p5js/22066)

<div class="topic-metadata">

**Author:** [@AKAC](https://discourse.processing.org/u/AKAC)\
**Replies:** 6\
**Last updated:** [July 4, 2020, 3:08pm UTC](https://discourse.processing.org/t/mouse-dragged-in-p5js/22066 "2020-07-04T15:08:33Z")

</div>

Hi I’m new in P5 and need a help with “mouse dragged” my code is: let imgB; let imgC; let imgD; let sz = 70 let y = 0; let x = 0; let y1 = 0; let x1 = 0; let y2 = 0; let x2 = 0; let startX = 0; let startY =…

---

## [Can someone tell me what is wrong with my conversion of this code?](https://discourse.processing.org/t/can-someone-tell-me-what-is-wrong-with-my-conversion-of-this-code/22370)

<div class="topic-metadata">

**Author:** [@tinkrit](https://discourse.processing.org/u/tinkrit)\
**Replies:** 1\
**Last updated:** [July 4, 2020, 1:17am UTC](https://discourse.processing.org/t/can-someone-tell-me-what-is-wrong-with-my-conversion-of-this-code/22370 "2020-07-04T01:17:36Z")

</div>

// // Conversione in P5.js di "Quasicrystals as sums of waves in the plane" // http://mainisusuallyafunction.blogspot.it/2011/10/quasicrystals-as-sums-of-waves-in-plane.html // var dimPix = 0.4; var numeroLivelli = 7; …

---

## [How to access p5js functions when using ES6 modules](https://discourse.processing.org/t/how-to-access-p5js-functions-when-using-es6-modules/21359)

<div class="topic-metadata">

**Author:** [@dansumption](https://discourse.processing.org/u/dansumption)\
**Replies:** 6\
**Last updated:** [July 3, 2020, 3:36pm UTC](https://discourse.processing.org/t/how-to-access-p5js-functions-when-using-es6-modules/21359 "2020-07-03T15:36:39Z")

</div>

I am trying to write an app using ES6 modules and the voronoi library, and in this environment all of the processing instance functions (background, stroke, random, etc) are not in the module’s namespace. I have got aro…

---

## [Error with video= IndexSizeError: Index or size is negative or greater than the allowed amount](https://discourse.processing.org/t/error-with-video-indexsizeerror-index-or-size-is-negative-or-greater-than-the-allowed-amount/22306)

<div class="topic-metadata">

**Author:** [@akenaton](https://discourse.processing.org/u/akenaton)\
**Replies:** 1\
**Last updated:** [July 2, 2020, 5:18pm UTC](https://discourse.processing.org/t/error-with-video-indexsizeerror-index-or-size-is-negative-or-greater-than-the-allowed-amount/22306 "2020-07-02T17:18:01Z")

</div>

i have a sketch in which there is a video; not any problem with the code (it seems!) - When i run the sketch i get often and not always this error: “IndexSizeError: Index or size is negative or greater than the allowed …

---

## [Setup method runs twice](https://discourse.processing.org/t/setup-method-runs-twice/21275)

<div class="topic-metadata">

**Author:** [@dansumption](https://discourse.processing.org/u/dansumption)\
**Replies:** 3\
**Last updated:** [July 2, 2020, 6:36pm UTC](https://discourse.processing.org/t/setup-method-runs-twice/21275 "2020-07-02T18:36:17Z")

</div>

My p5js app runs the setup function twice. I have stripped the whole thing down as much as possible, and it’s still happening. This is messing with my app because (a) I wish to run some fairly heavy operations in setup a…

---

## [Converting inputs into int types](https://discourse.processing.org/t/converting-inputs-into-int-types/22276)

<div class="topic-metadata">

**Author:** [@olorin](https://discourse.processing.org/u/olorin)\
**Replies:** 4\
**Last updated:** [July 1, 2020, 11:13am UTC](https://discourse.processing.org/t/converting-inputs-into-int-types/22276 "2020-07-01T11:13:14Z")

</div>

I’m trying to take in user number inputs, convert them into int types, multiply, convert the outcome back into a string, and print this out. I keep getting the Not a Number result when ever i try int(input.value()). does…

---

## [Make line shape fade away after x seconds](https://discourse.processing.org/t/make-line-shape-fade-away-after-x-seconds/22233)

<div class="topic-metadata">

**Author:** [@arala22](https://discourse.processing.org/u/arala22)\
**Replies:** 4\
**Last updated:** [June 30, 2020, 5:47pm UTC](https://discourse.processing.org/t/make-line-shape-fade-away-after-x-seconds/22233 "2020-06-30T17:47:43Z")

</div>

whats the best way to fade a line out? I have this here: https://codepen.io/itsMeAra/pen/e6ebe0dec2d370f50217809c547052e7 Trying to figure out how to make the line fade away after .5 seconds to make sort of a trailing …

---

## [Pixel correspondence with live capture](https://discourse.processing.org/t/pixel-correspondence-with-live-capture/22248)

<div class="topic-metadata">

**Author:** [@maddyna](https://discourse.processing.org/u/maddyna)\
**Replies:** 4\
**Last updated:** [June 30, 2020, 11:24am UTC](https://discourse.processing.org/t/pixel-correspondence-with-live-capture/22248 "2020-06-30T11:24:03Z")

</div>

\<I have asked this question but not getting a successful answer.Tring to scale the video feed from the capture object into a small size and then mapping it into a larger canvas but some how even 1:1 pixel manipulation d…

---

## [Using sound classification to trigger a camera?](https://discourse.processing.org/t/using-sound-classification-to-trigger-a-camera/22259)

<div class="topic-metadata">

**Author:** [@FloydW2](https://discourse.processing.org/u/FloydW2)\
**Replies:** 2\
**Last updated:** [June 30, 2020, 7:18am UTC](https://discourse.processing.org/t/using-sound-classification-to-trigger-a-camera/22259 "2020-06-30T07:18:12Z")

</div>

Hi All, I’m a bit new to all of this, and working with my kid to try and figure something out. We’ve followed the Coding Train Teachable Machine Sound Classification tutorial, and got it done while having a ton of fun.…

---

## [How do I make a sprite rotate to face another sprite?](https://discourse.processing.org/t/how-do-i-make-a-sprite-rotate-to-face-another-sprite/22266)

<div class="topic-metadata">

**Author:** [@The99thTroll](https://discourse.processing.org/u/The99thTroll)\
**Replies:** 3\
**Last updated:** [June 30, 2020, 1:20am UTC](https://discourse.processing.org/t/how-do-i-make-a-sprite-rotate-to-face-another-sprite/22266 "2020-06-30T01:20:16Z")

</div>

I’m working on a tower defense game but I am unable to find a way for my towers to rotate to look at the current enemy they’re targeting. Any solutions?

---

## [Conceptual Clarity on frameCount and rotate function](https://discourse.processing.org/t/conceptual-clarity-on-framecount-and-rotate-function/22246)

<div class="topic-metadata">

**Author:** [@diomedeidae](https://discourse.processing.org/u/diomedeidae)\
**Replies:** 3\
**Last updated:** [June 29, 2020, 2:00pm UTC](https://discourse.processing.org/t/conceptual-clarity-on-framecount-and-rotate-function/22246 "2020-06-29T14:00:44Z")

</div>

I was doing one of the examples on the p5.js website - https://p5js.org/examples/form-regular-polygon.html. I got really confused by the way rotate function worked in that code . IN the below function if I just pass rota…

---

## [Making object appear in random locations](https://discourse.processing.org/t/making-object-appear-in-random-locations/22216)

<div class="topic-metadata">

**Author:** [@liekevoortman](https://discourse.processing.org/u/liekevoortman)\
**Replies:** 5\
**Last updated:** [June 28, 2020, 1:24pm UTC](https://discourse.processing.org/t/making-object-appear-in-random-locations/22216 "2020-06-28T13:24:34Z")

</div>

Hi! I need to make an object (circle) appear in random locations on my screen. So it appears, dissapears, and appears again in another random location, and so forth. Maybe this is really simple, but I’m not very familiar…

---

## [How can i optimize this chain of if/else statement?](https://discourse.processing.org/t/how-can-i-optimize-this-chain-of-if-else-statement/22182)

<div class="topic-metadata">

**Author:** [@bismarck](https://discourse.processing.org/u/bismarck)\
**Replies:** 3\
**Last updated:** [June 27, 2020, 9:07pm UTC](https://discourse.processing.org/t/how-can-i-optimize-this-chain-of-if-else-statement/22182 "2020-06-27T21:07:02Z")

</div>

hello i want to optimize this code. I thought that i can use the switch statement, but i don’t know how to implement it: //function setup() { createCanvas(400, 400); } function draw() { background(220); let s…

---

## [How to add a canvas to a \<div\> and center it?](https://discourse.processing.org/t/how-to-add-a-canvas-to-a-div-and-center-it/22107)

<div class="topic-metadata">

**Author:** [@Bassam](https://discourse.processing.org/u/Bassam)\
**Replies:** 4\
**Last updated:** [June 26, 2020, 6:48am UTC](https://discourse.processing.org/t/how-to-add-a-canvas-to-a-div-and-center-it/22107 "2020-06-26T06:48:31Z")

</div>

I’m not sure if div is the best thing to use but here goes. I have 2 different types of canvases. Type 1 will be centered horizontally. Type 2 will be centered horizontally and vertically. I have 2 different snippets of…

---

## [Texture with P2D renderer?](https://discourse.processing.org/t/texture-with-p2d-renderer/22148)

<div class="topic-metadata">

**Author:** [@grege2](https://discourse.processing.org/u/grege2)\
**Replies:** 2\
**Last updated:** [June 25, 2020, 8:04pm UTC](https://discourse.processing.org/t/texture-with-p2d-renderer/22148 "2020-06-25T20:04:35Z")

</div>

Hi, Is it possible at all, maybe with a hack to directly talk to the browser GL rendering layer, to use simple texturing in the p5.js P2D renderer ? In Java Processing it seems it might be possible in the P2D renderer, …

---

## [Tilemap with Buildings and Mousemovement, does not work like it should](https://discourse.processing.org/t/tilemap-with-buildings-and-mousemovement-does-not-work-like-it-should/22159)

<div class="topic-metadata">

**Author:** [@rotzend](https://discourse.processing.org/u/rotzend)\
**Replies:** 1\
**Last updated:** [June 25, 2020, 6:00pm UTC](https://discourse.processing.org/t/tilemap-with-buildings-and-mousemovement-does-not-work-like-it-should/22159 "2020-06-25T18:00:30Z")

</div>

Hello everybody, I have only been dealing with canvas for a very short time, thanks to the YouTube “The Coding Train” I became aware of p5js years ago and I am really enthusiastic, it is significantly faster, smaller an…

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

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