# Coding Questions

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

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

**Page:** 32

---

## [For loop is not being called](https://discourse.processing.org/t/for-loop-is-not-being-called/21493)

<div class="topic-metadata">

**Author:** [@shodai](https://discourse.processing.org/u/shodai)\
**Replies:** 6\
**Last updated:** [June 2, 2020, 4:43pm UTC](https://discourse.processing.org/t/for-loop-is-not-being-called/21493 "2020-06-02T16:43:25Z")

</div>

I am working through a snake game program and have run into a really odd problem. Everything works except that the snake does not crash into itself. When the snake runs into itself the screen should turn red temporarily.…

---

## [Slowdown in Game of Life with Objects - Why?](https://discourse.processing.org/t/slowdown-in-game-of-life-with-objects-why/21481)

<div class="topic-metadata">

**Author:** [@umutreldem](https://discourse.processing.org/u/umutreldem)\
**Replies:** 2\
**Last updated:** [June 1, 2020, 9:19pm UTC](https://discourse.processing.org/t/slowdown-in-game-of-life-with-objects-why/21481 "2020-06-01T21:19:12Z")

</div>

I am working on recreating Game of Life in different ways, taking Coding Train’s video as the starting point. What I am trying to add is ‘color inheritance’: A newborn cell ‘inheriting’ the color from the average of the …

---

## [How can i save a small canvas with high resolution 8k image file](https://discourse.processing.org/t/how-can-i-save-a-small-canvas-with-high-resolution-8k-image-file/21422)

<div class="topic-metadata">

**Author:** [@biard](https://discourse.processing.org/u/biard)\
**Replies:** 4\
**Last updated:** [May 31, 2020, 11:15pm UTC](https://discourse.processing.org/t/how-can-i-save-a-small-canvas-with-high-resolution-8k-image-file/21422 "2020-05-31T23:15:21Z")

</div>

please format code with \</\> button \* homework policy \* asking questions i have a canvas of 500x500 .and i want to save the canvas as a super high resolution image. but i don’t know how to do it. i don’t wanna to incr…

---

## [Issue with a texture from createGraphics()](https://discourse.processing.org/t/issue-with-a-texture-from-creategraphics/21421)

<div class="topic-metadata">

**Author:** [@d128](https://discourse.processing.org/u/d128)\
**Replies:** 1\
**Last updated:** [May 30, 2020, 10:38am UTC](https://discourse.processing.org/t/issue-with-a-texture-from-creategraphics/21421 "2020-05-30T10:38:48Z")

</div>

Hi everyone, I’m applying a texture in a box from a createGraphics() with a rotating sphere. When I’m doing this, the sphere on the texture starts to ‘dissapear’ (something similar when the background isn’t updated). I’…

---

## [How to show xy coordinate scale itself](https://discourse.processing.org/t/how-to-show-xy-coordinate-scale-itself/21383)

<div class="topic-metadata">

**Author:** [@suvir](https://discourse.processing.org/u/suvir)\
**Replies:** 4\
**Last updated:** [May 29, 2020, 9:30pm UTC](https://discourse.processing.org/t/how-to-show-xy-coordinate-scale-itself/21383 "2020-05-29T21:30:03Z")

</div>

I am drawing a spectrum graph, like the one from fft example. Code looks bit like below and draws fine: for (let i = 0; i \< data.getRowCount() / 1; i++) { let x = p.map(i, 0, data.getRowCount() / 1, 0, p.width); …

---

## [Please help with set() and get()](https://discourse.processing.org/t/please-help-with-set-and-get/21403)

<div class="topic-metadata">

**Author:** [@noob](https://discourse.processing.org/u/noob)\
**Replies:** 3\
**Last updated:** [May 29, 2020, 3:39pm UTC](https://discourse.processing.org/t/please-help-with-set-and-get/21403 "2020-05-29T15:39:52Z")

</div>

Hello good people, I have been writing code to manipulate an image in p5.js. The effect that I want to achieve is simple. But I can’t get around to find a way to do it. Currently, the result from my code is that the ima…

---

## [Moving figures in z-coordinate (z-axis)](https://discourse.processing.org/t/moving-figures-in-z-coordinate-z-axis/21310)

<div class="topic-metadata">

**Author:** [@Nis](https://discourse.processing.org/u/Nis)\
**Replies:** 31\
**Last updated:** [May 29, 2020, 3:19pm UTC](https://discourse.processing.org/t/moving-figures-in-z-coordinate-z-axis/21310 "2020-05-29T15:19:16Z")

</div>

Can someone please tell me, how can I make figures move in(on) the z-axis in p5.js? Like, ‘X-axis’ makes things move ‘Right-Left’ and ‘Y-axis’ makes things move ‘Up-Down’. But both of them I know. I am frustrated at th…

---

## [Correct way to use ES6 modules and import classes](https://discourse.processing.org/t/correct-way-to-use-es6-modules-and-import-classes/21386)

<div class="topic-metadata">

**Author:** [@josephh](https://discourse.processing.org/u/josephh)\
**Replies:** 4\
**Last updated:** [May 29, 2020, 8:34am UTC](https://discourse.processing.org/t/correct-way-to-use-es6-modules-and-import-classes/21386 "2020-05-29T08:34:18Z")

</div>

Hi, I am making a project in p5.js where I have a simple class called Stone that I want to import into another file using ES6 modules. So I used export default : // js/src/Stone.js export default class Stone { con…

---

## [Highlighting an arc in P5](https://discourse.processing.org/t/highlighting-an-arc-in-p5/21267)

<div class="topic-metadata">

**Author:** [@viniciusfersil](https://discourse.processing.org/u/viniciusfersil)\
**Replies:** 3\
**Last updated:** [May 28, 2020, 7:10pm UTC](https://discourse.processing.org/t/highlighting-an-arc-in-p5/21267 "2020-05-28T19:10:37Z")

</div>

Hello to you all :slight\_smile: . I am trying to develop a pizza-like graph. Each “slice” of the full circle represents an element that will have some data attached to it. I am having trouble to acess each slice “individ…

---

## [Video + text tracks via .vtt file](https://discourse.processing.org/t/video-text-tracks-via-vtt-file/21324)

<div class="topic-metadata">

**Author:** [@stephanschulz](https://discourse.processing.org/u/stephanschulz)\
**Replies:** 2\
**Last updated:** [May 27, 2020, 1:44pm UTC](https://discourse.processing.org/t/video-text-tracks-via-vtt-file/21324 "2020-05-27T13:44:02Z")

</div>

I am using createVideo to load in a new video file. At the same time I would like to generate a text track and attach it to the video, so when it plays back I can see the text for each time cue and read the cue data via…

---

## [Possibility to avoid redraw with virtual mouse cursor](https://discourse.processing.org/t/possibility-to-avoid-redraw-with-virtual-mouse-cursor/21168)

<div class="topic-metadata">

**Author:** [@monade](https://discourse.processing.org/u/monade)\
**Replies:** 3\
**Last updated:** [May 25, 2020, 12:11pm UTC](https://discourse.processing.org/t/possibility-to-avoid-redraw-with-virtual-mouse-cursor/21168 "2020-05-25T12:11:40Z")

</div>

I am developing a little game with p5.js in which I need to draw my own mouse cursor (for reasons that are not so important). Apart from the mouse cursor, the game has mostly static content and each frame consist of arou…

---

## ["paste" event listener not working for a P5.Graphic?](https://discourse.processing.org/t/paste-event-listener-not-working-for-a-p5-graphic/20095)

<div class="topic-metadata">

**Author:** [@Yom](https://discourse.processing.org/u/Yom)\
**Replies:** 3\
**Last updated:** [May 25, 2020, 5:10am UTC](https://discourse.processing.org/t/paste-event-listener-not-working-for-a-p5-graphic/20095 "2020-05-25T05:10:42Z")

</div>

Hello :slight\_smile: I would like to add a “paste” event listener to a p5.Graphic, how can I do that ? I’ve tried like this: g = createGraphics(100, 100); g.elt.addEventListener("paste", pasteEvent =\> console.log("pas…

---

## [How to change picture on p5](https://discourse.processing.org/t/how-to-change-picture-on-p5/21231)

<div class="topic-metadata">

**Author:** [@Gravic216](https://discourse.processing.org/u/Gravic216)\
**Replies:** 1\
**Last updated:** [May 24, 2020, 8:41pm UTC](https://discourse.processing.org/t/how-to-change-picture-on-p5/21231 "2020-05-24T20:41:14Z")

</div>

Hi, I’m looking for how just mouse click once time and the load picture will change to another change picture as well as never change.

---

## [How to make a pulling mouse constraint?](https://discourse.processing.org/t/how-to-make-a-pulling-mouse-constraint/21200)

<div class="topic-metadata">

**Author:** [@Nis](https://discourse.processing.org/u/Nis)\
**Replies:** 1\
**Last updated:** [May 24, 2020, 5:06am UTC](https://discourse.processing.org/t/how-to-make-a-pulling-mouse-constraint/21200 "2020-05-24T05:06:36Z")

</div>

https://editor.p5js.org/Nis\_Collect/sketches/U0p3GjOK1 Above is the link of my code. Please check it and please let me know how can I make my player get pulled towards an enemy (like Spiderman is attracted with some sp…

---

## [Image Array from non-sequential image names](https://discourse.processing.org/t/image-array-from-non-sequential-image-names/20990)

<div class="topic-metadata">

**Author:** [@clintsleeper](https://discourse.processing.org/u/clintsleeper)\
**Replies:** 4\
**Last updated:** [May 23, 2020, 6:55pm UTC](https://discourse.processing.org/t/image-array-from-non-sequential-image-names/20990 "2020-05-23T18:55:54Z")

</div>

Hi all, I’m hoping I have a simple question - I’m trying to populate an image array from a folder where images are stored but will not have sequential naming schemes (the folder is populated by a PHP uploader with a han…

---

## [Someone please help me: enemy shooting](https://discourse.processing.org/t/someone-please-help-me-enemy-shooting/21197)

<div class="topic-metadata">

**Author:** [@Nis](https://discourse.processing.org/u/Nis)\
**Replies:** 4\
**Last updated:** [May 23, 2020, 3:12pm UTC](https://discourse.processing.org/t/someone-please-help-me-enemy-shooting/21197 "2020-05-23T15:12:36Z")

</div>

https://editor.p5js.org/Nis\_Collect/sketches/U0p3GjOK1 Above is the link of my code. Please check it and please tell me how can I make the circular enemies (which are moving towards left), fire small circular bullets a…

---

## [Player should move on drag, shouldn’t respond on click](https://discourse.processing.org/t/player-should-move-on-drag-shouldn-t-respond-on-click/21194)

<div class="topic-metadata">

**Author:** [@Nis](https://discourse.processing.org/u/Nis)\
**Replies:** 5\
**Last updated:** [May 23, 2020, 12:20pm UTC](https://discourse.processing.org/t/player-should-move-on-drag-shouldn-t-respond-on-click/21194 "2020-05-23T12:20:42Z")

</div>

https://editor.p5js.org/Nis\_Collect/sketches/U0p3GjOK1 Above is the link of my code in p5.js editor. As you can see in the code that the player which is in blue colour on the preview screen, moves on mouseX and mouseY. …

---

## [Question as drawing with pixels on Processing](https://discourse.processing.org/t/question-as-drawing-with-pixels-on-processing/21207)

<div class="topic-metadata">

**Author:** [@shinnn](https://discourse.processing.org/u/shinnn)\
**Replies:** 1\
**Last updated:** [May 23, 2020, 9:07am UTC](https://discourse.processing.org/t/question-as-drawing-with-pixels-on-processing/21207 "2020-05-23T09:07:56Z")

</div>

Hello Now I am trying to draw picture based on the data got from the original picture. It went quite successful on p5.js but it somehow did not work well on Processing. Am I doing wrong? and What is the problem? Thank y…

---

## [Please help with Perlin Noise problem](https://discourse.processing.org/t/please-help-with-perlin-noise-problem/21160)

<div class="topic-metadata">

**Author:** [@noob](https://discourse.processing.org/u/noob)\
**Replies:** 2\
**Last updated:** [May 23, 2020, 1:22am UTC](https://discourse.processing.org/t/please-help-with-perlin-noise-problem/21160 "2020-05-23T01:22:02Z")

</div>

Hi good people, I have been looking for this solutions in days now. I hope you can show me the light how to get it done. So I found this image in the internet: I try to replicate the image above using p5js, with pe…

---

## [Advice on setting width of the slider to cm or inches](https://discourse.processing.org/t/advice-on-setting-width-of-the-slider-to-cm-or-inches/21118)

<div class="topic-metadata">

**Author:** [@cperezl](https://discourse.processing.org/u/cperezl)\
**Replies:** 1\
**Last updated:** [May 22, 2020, 5:05pm UTC](https://discourse.processing.org/t/advice-on-setting-width-of-the-slider-to-cm-or-inches/21118 "2020-05-22T17:05:00Z")

</div>

Hi everyone, I have a very basic understanding of p5.js and I am working on a program using sliders for a psychological experiment. The sliders will be used to answer questions on a scale from “nothing” to “a lot”. When…

---

## [Send Value to slider in the index.html from p5sketch?](https://discourse.processing.org/t/send-value-to-slider-in-the-index-html-from-p5sketch/21157)

<div class="topic-metadata">

**Author:** [@ballinoates](https://discourse.processing.org/u/ballinoates)\
**Replies:** 2\
**Last updated:** [May 22, 2020, 4:13pm UTC](https://discourse.processing.org/t/send-value-to-slider-in-the-index-html-from-p5sketch/21157 "2020-05-22T16:13:42Z")

</div>

Hi All- I have a slightly complex index.html page with additional js that allows the user to switch between different sketches. In each sketch I have coded 2 sliders that live in the index outside of the canvas. The ide…

---

## [Printing the y coordinate is "undefined"](https://discourse.processing.org/t/printing-the-y-coordinate-is-undefined/21158)

<div class="topic-metadata">

**Author:** [@Nis](https://discourse.processing.org/u/Nis)\
**Replies:** 3\
**Last updated:** [May 22, 2020, 11:42am UTC](https://discourse.processing.org/t/printing-the-y-coordinate-is-undefined/21158 "2020-05-22T11:42:56Z")

</div>

The above the picture of my code, where it isn’t printing the y coordinate of the moving rectangles, instead it is printing “undefined”

---

## [Creating a class with multiple constructors and static variables in JavaScript](https://discourse.processing.org/t/creating-a-class-with-multiple-constructors-and-static-variables-in-javascript/21156)

<div class="topic-metadata">

**Author:** [@AndJ](https://discourse.processing.org/u/AndJ)\
**Replies:** 1\
**Last updated:** [May 22, 2020, 2:40am UTC](https://discourse.processing.org/t/creating-a-class-with-multiple-constructors-and-static-variables-in-javascript/21156 "2020-05-22T02:40:14Z")

</div>

I am familiar with Processing/Java but am trying to learn more p5.js/JavaScript. I am creating a class that, in Java, has multiple constructors with the same number of arguments with different data types. Example: clas…

---

## [Please plese please help me with my problem, appearing in a simple p5.js code](https://discourse.processing.org/t/please-plese-please-help-me-with-my-problem-appearing-in-a-simple-p5-js-code/21123)

<div class="topic-metadata">

**Author:** [@Nis](https://discourse.processing.org/u/Nis)\
**Replies:** 2\
**Last updated:** [May 21, 2020, 7:59am UTC](https://discourse.processing.org/t/please-plese-please-help-me-with-my-problem-appearing-in-a-simple-p5-js-code/21123 "2020-05-21T07:59:06Z")

</div>

https://editor.p5js.org/Nis\_Collect/sketches/U0p3GjOK1 The above provided link is of my project in which I want to make only one rectangle appear after particular frame-counts.But there appears a problem while doing thi…

---

## [Why does this Javascript sketch lag compared to the Java sketch?](https://discourse.processing.org/t/why-does-this-javascript-sketch-lag-compared-to-the-java-sketch/21019)

<div class="topic-metadata">

**Author:** [@the0ne](https://discourse.processing.org/u/the0ne)\
**Replies:** 3\
**Last updated:** [May 20, 2020, 9:15pm UTC](https://discourse.processing.org/t/why-does-this-javascript-sketch-lag-compared-to-the-java-sketch/21019 "2020-05-20T21:15:08Z")

</div>

So, I ported a Java Processing sketch to p5.js. The sketches should be simple to run - just basic image rasterization. I tried my best to optimize the JS code but have been unsuccessful at getting any decent performance …

---

## [How to rotate a sprite toward the direction of motion](https://discourse.processing.org/t/how-to-rotate-a-sprite-toward-the-direction-of-motion/21056)

<div class="topic-metadata">

**Author:** [@shinyogre](https://discourse.processing.org/u/shinyogre)\
**Replies:** 12\
**Last updated:** [May 20, 2020, 1:44pm UTC](https://discourse.processing.org/t/how-to-rotate-a-sprite-toward-the-direction-of-motion/21056 "2020-05-20T13:44:54Z")

</div>

I am trying to figure out how to align a sprite image to the angle of the hill that it “moves” along. I am using atan2 and the result is this (gif is multiplying the angle by 360 just to show the effect): Here is my …

---

## [How to reduce PoseNet inputResolution to make it perform faster](https://discourse.processing.org/t/how-to-reduce-posenet-inputresolution-to-make-it-perform-faster/21060)

<div class="topic-metadata">

**Author:** [@yuinjann](https://discourse.processing.org/u/yuinjann)\
**Replies:** 0\
**Last updated:** [May 19, 2020, 3:25pm UTC](https://discourse.processing.org/t/how-to-reduce-posenet-inputresolution-to-make-it-perform-faster/21060 "2020-05-19T15:25:02Z")

</div>

Hi! I’m using posenet and hence video capture, and not drawing the video image. My project uses node and want to track wrist positions of everyone who opens the browser. However, the size of my video is the size of my c…

---

## [Disable smooth/anti-alias for textures](https://discourse.processing.org/t/disable-smooth-anti-alias-for-textures/21078)

<div class="topic-metadata">

**Author:** [@d128](https://discourse.processing.org/u/d128)\
**Replies:** 0\
**Last updated:** [May 20, 2020, 4:53am UTC](https://discourse.processing.org/t/disable-smooth-anti-alias-for-textures/21078 "2020-05-20T04:53:37Z")

</div>

Hi, everyone. I’m using a 400x200 texture on a sphere and I want to disable the smooth/anti-alias only for the texture in order to get a sharp and pixelated look. Is this possible or there’s a workaround? If it’s disabl…

---

## [No graphics after resetShader()](https://discourse.processing.org/t/no-graphics-after-resetshader/13585)

<div class="topic-metadata">

**Author:** [@pazka](https://discourse.processing.org/u/pazka)\
**Replies:** 6\
**Last updated:** [May 18, 2020, 3:43pm UTC](https://discourse.processing.org/t/no-graphics-after-resetshader/13585 "2020-05-18T15:43:40Z")

</div>

Hello everybody ! I come to you because I have been encountering a problem that I have a lot of struggle to solve. At this point I am almost sure it’s a bug but I’d rather have your opinion first ! My goal is to draw t…

---

## [Draw on top of shader?](https://discourse.processing.org/t/draw-on-top-of-shader/20764)

<div class="topic-metadata">

**Author:** [@toom](https://discourse.processing.org/u/toom)\
**Replies:** 5\
**Last updated:** [May 18, 2020, 12:08pm UTC](https://discourse.processing.org/t/draw-on-top-of-shader/20764 "2020-05-18T12:08:32Z")

</div>

Hi there, how can I draw text or a primitive shape on top of a shader? resetShader() doesn’t appear to do anything. Every shape drawn after the shader is started is somehow under the shader. I’m capturing video from the…

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

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