# Coding Questions

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

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

**Page:** 18

---

## [Shader performance vs drawing array of points](https://discourse.processing.org/t/shader-performance-vs-drawing-array-of-points/31373)

<div class="topic-metadata">

**Author:** [@rkdnson](https://discourse.processing.org/u/rkdnson)\
**Replies:** 3\
**Last updated:** [July 22, 2021, 9:02am UTC](https://discourse.processing.org/t/shader-performance-vs-drawing-array-of-points/31373 "2021-07-22T09:02:39Z")

</div>

Hello all. I have a project where I want every other pixel to be black. This could be accomplished with two simple for loops; for (let x = 0; x \< width; x+=2) { for (let y = 0; y \< height; y+=2) { point(x,y);…

---

## [How to cycle between two colors using lerp](https://discourse.processing.org/t/how-to-cycle-between-two-colors-using-lerp/31370)

<div class="topic-metadata">

**Author:** [@cottonchipper](https://discourse.processing.org/u/cottonchipper)\
**Replies:** 2\
**Last updated:** [July 21, 2021, 8:37pm UTC](https://discourse.processing.org/t/how-to-cycle-between-two-colors-using-lerp/31370 "2021-07-21T20:37:12Z")

</div>

I’m trying to smoothly lerp back and forth between two colors repeatedly. The following changes from red to blue and then suddenly shifts back to red when the sketch loops. Is there a way to shift from red to blue to red…

---

## [indexOf does not match unicode string](https://discourse.processing.org/t/indexof-does-not-match-unicode-string/31319)

<div class="topic-metadata">

**Author:** [@JoseMY](https://discourse.processing.org/u/JoseMY)\
**Replies:** 2\
**Last updated:** [July 20, 2021, 12:00pm UTC](https://discourse.processing.org/t/indexof-does-not-match-unicode-string/31319 "2021-07-20T12:00:07Z")

</div>

Hi! I am reading a file called “Symbola605.txt” with loadStrings(). Then I use .indexOf at each line in order to find a word that marks the beginning of a character list. But it seems that .indexOf does not work with …

---

## [Moving effect of a set of dots](https://discourse.processing.org/t/moving-effect-of-a-set-of-dots/31263)

<div class="topic-metadata">

**Author:** [@k5221](https://discourse.processing.org/u/k5221)\
**Replies:** 3\
**Last updated:** [July 19, 2021, 9:54am UTC](https://discourse.processing.org/t/moving-effect-of-a-set-of-dots/31263 "2021-07-19T09:54:14Z")

</div>

Hi, I have a function to create one set of dots, which are individually created by ellipse() function. I hope to move one set (=individual dots within the set) right and left according to the frame rate, and each set mov…

---

## [Breathing Data (how to determine & calculate inhale/exhale duration)](https://discourse.processing.org/t/breathing-data-how-to-determine-calculate-inhale-exhale-duration/31278)

<div class="topic-metadata">

**Author:** [@Nick76](https://discourse.processing.org/u/Nick76)\
**Replies:** 2\
**Last updated:** [July 17, 2021, 11:38am UTC](https://discourse.processing.org/t/breathing-data-how-to-determine-calculate-inhale-exhale-duration/31278 "2021-07-17T11:38:17Z")

</div>

Hi everybody, I’m currently working on a project in which I use a breath-belt (arduino+stretch sensor attached around the chest) to capture the breathing patterns of a user. The data is transferred and integrated into t…

---

## [Fill an imagined ellipse with dots](https://discourse.processing.org/t/fill-an-imagined-ellipse-with-dots/31221)

<div class="topic-metadata">

**Author:** [@k5221](https://discourse.processing.org/u/k5221)\
**Replies:** 5\
**Last updated:** [July 15, 2021, 8:44am UTC](https://discourse.processing.org/t/fill-an-imagined-ellipse-with-dots/31221 "2021-07-15T08:44:54Z")

</div>

Hi, what I would like to do is fill an imagined ellipse (x, y, w, h) with tiny dots whose size is specified by “dotSize” of the “drawHead” function. But I struggle coming up a way to fit dots inside an ellipse (so the nu…

---

## [Randomly select file to preload (p5.js)](https://discourse.processing.org/t/randomly-select-file-to-preload-p5-js/31148)

<div class="topic-metadata">

**Author:** [@fleshcircuit](https://discourse.processing.org/u/fleshcircuit)\
**Replies:** 9\
**Last updated:** [July 14, 2021, 12:46pm UTC](https://discourse.processing.org/t/randomly-select-file-to-preload-p5-js/31148 "2021-07-14T12:46:31Z")

</div>

I am working on a project where I am using data from a json file, but I am wondering if it is possible to randomly select a file from the data folder for a sketch to use. I don’t want to load all the files, since I fear …

---

## [Draw() overlay shapes on the canvas](https://discourse.processing.org/t/draw-overlay-shapes-on-the-canvas/31222)

<div class="topic-metadata">

**Author:** [@k5221](https://discourse.processing.org/u/k5221)\
**Replies:** 1\
**Last updated:** [July 13, 2021, 7:08am UTC](https://discourse.processing.org/t/draw-overlay-shapes-on-the-canvas/31222 "2021-07-13T07:08:12Z")

</div>

Hi, I’m writing a code to call another custom render function I created inside the draw() to render shapes (which is essentially a bunch of ellipses) on the screen. But, it draws shapes on top of each other and doesn’t r…

---

## [Mitigating Periodicity in Perlin Noise](https://discourse.processing.org/t/mitigating-periodicity-in-perlin-noise/31211)

<div class="topic-metadata">

**Author:** [@javagar](https://discourse.processing.org/u/javagar)\
**Replies:** 4\
**Last updated:** [July 13, 2021, 6:13am UTC](https://discourse.processing.org/t/mitigating-periodicity-in-perlin-noise/31211 "2021-07-13T06:13:24Z")

</div>

I’m working on a Racing Eggs! animation, wherein four Egg objects race across the canvas from left to right. They each speed up and slow down independently of each other. When an Egg reaches the right edge of the canvas,…

---

## [Get a 3d cube made of cubes to expand from the center](https://discourse.processing.org/t/get-a-3d-cube-made-of-cubes-to-expand-from-the-center/31220)

<div class="topic-metadata">

**Author:** [@LuluLuna](https://discourse.processing.org/u/LuluLuna)\
**Replies:** 1\
**Last updated:** [July 13, 2021, 1:25am UTC](https://discourse.processing.org/t/get-a-3d-cube-made-of-cubes-to-expand-from-the-center/31220 "2021-07-13T01:25:41Z")

</div>

Hello, I made this sketch Link to sketch as you can see its a cube made of smaller cubes that expand and retract using sin. My problem is that the smaller cubes expand and retract from the corner cube and not from the…

---

## [P5js blendmode is so strange](https://discourse.processing.org/t/p5js-blendmode-is-so-strange/30958)

<div class="topic-metadata">

**Author:** [@yang](https://discourse.processing.org/u/yang)\
**Replies:** 6\
**Last updated:** [July 12, 2021, 5:02pm UTC](https://discourse.processing.org/t/p5js-blendmode-is-so-strange/30958 "2021-07-12T17:02:00Z")

</div>

Hello guys,I’m trying to make an animation of rains flowing down a window, but there’s still some color left that doesn’t blend with the background. So I look up the blendMode() reference, and find a fomula for BLEND C…

---

## [Drawing a flower-like shape](https://discourse.processing.org/t/drawing-a-flower-like-shape/31200)

<div class="topic-metadata">

**Author:** [@k5221](https://discourse.processing.org/u/k5221)\
**Replies:** 3\
**Last updated:** [July 12, 2021, 8:54am UTC](https://discourse.processing.org/t/drawing-a-flower-like-shape/31200 "2021-07-12T08:54:53Z")

</div>

Hi, I want to draw shapes like this. The function called “seed1” is supposed to take care of one of the curvy triangles, but when I call this function within the draw(), the second and third triangles look smashed (ma…

---

## [Get() returns an empty pixels array](https://discourse.processing.org/t/get-returns-an-empty-pixels-array/31132)

<div class="topic-metadata">

**Author:** [@k5221](https://discourse.processing.org/u/k5221)\
**Replies:** 3\
**Last updated:** [July 11, 2021, 8:13am UTC](https://discourse.processing.org/t/get-returns-an-empty-pixels-array/31132 "2021-07-11T08:13:52Z")

</div>

Hi, I want to show the cropped picture created by shuffling the certain portion of the original videocam image. “capture.get()” function in draw() works correctly, but because the returning object has an empty array as t…

---

## [Frame count delay in showing button](https://discourse.processing.org/t/frame-count-delay-in-showing-button/31116)

<div class="topic-metadata">

**Author:** [@fleshcircuit](https://discourse.processing.org/u/fleshcircuit)\
**Replies:** 2\
**Last updated:** [July 9, 2021, 7:04am UTC](https://discourse.processing.org/t/frame-count-delay-in-showing-button/31116 "2021-07-09T07:04:00Z")

</div>

Hello, I would like to make a button appear after a delay using frame count. When I put the button in the setup, it appears at the bottom of the screen and only moves to correct place later. let phrase = \['Time' ,'is' …

---

## [HELP : can´t remove sliders from home page](https://discourse.processing.org/t/help-can-t-remove-sliders-from-home-page/31072)

<div class="topic-metadata">

**Author:** [@axelen](https://discourse.processing.org/u/axelen)\
**Replies:** 2\
**Last updated:** [July 7, 2021, 8:04pm UTC](https://discourse.processing.org/t/help-can-t-remove-sliders-from-home-page/31072 "2021-07-07T20:04:29Z")

</div>

I can’t remove sliders from the home page. They should only be visible and working when you press “Start Mixing”. Help please!! Thanks! let myFont let relleno let data let r let b let g let ariana let billie let…

---

## [Creating a grid with objects that store their index number (X and Y)](https://discourse.processing.org/t/creating-a-grid-with-objects-that-store-their-index-number-x-and-y/31094)

<div class="topic-metadata">

**Author:** [@rkdnson](https://discourse.processing.org/u/rkdnson)\
**Replies:** 4\
**Last updated:** [July 6, 2021, 8:55pm UTC](https://discourse.processing.org/t/creating-a-grid-with-objects-that-store-their-index-number-x-and-y/31094 "2021-07-06T20:55:01Z")

</div>

Hello everyone, coming back after a long hiatus of not coding and my mind is a bit stumped. I am revisiting an old project so my brain keeps going back to my previous solutions even though I know that wasn’t the best way…

---

## [Help code \_ Climate Clock - Countdown events](https://discourse.processing.org/t/help-code-climate-clock-countdown-events/31070)

<div class="topic-metadata">

**Author:** [@HVK370](https://discourse.processing.org/u/HVK370)\
**Replies:** 1\
**Last updated:** [July 5, 2021, 4:32pm UTC](https://discourse.processing.org/t/help-code-climate-clock-countdown-events/31070 "2021-07-05T16:32:13Z")

</div>

Hello p5js community! This is my first code, sorry for that. the result should be YRS: Y Day: DDD hh: mm: ss such as https://climateclock.world I wrote this code but the days calculation doesn’t work. can you help me…

---

## [P5.js unit testing with Jest](https://discourse.processing.org/t/p5-js-unit-testing-with-jest/2638)

<div class="topic-metadata">

**Author:** [@kabatwa](https://discourse.processing.org/u/kabatwa)\
**Replies:** 6\
**Last updated:** [July 4, 2021, 11:48am UTC](https://discourse.processing.org/t/p5-js-unit-testing-with-jest/2638 "2021-07-04T11:48:04Z")

</div>

Hello, I’m trying to get Jest setup with p5.js. I’ve managed to get it all working with npm and able to run some basic unit tests however I’m having an issue when Jest hits a piece of p5 code. I have a sketch.js file w…

---

## [Can you extract the seed from randomly generated perlin noise?](https://discourse.processing.org/t/can-you-extract-the-seed-from-randomly-generated-perlin-noise/31023)

<div class="topic-metadata">

**Author:** [@TonyG](https://discourse.processing.org/u/TonyG)\
**Replies:** 4\
**Last updated:** [July 3, 2021, 11:21am UTC](https://discourse.processing.org/t/can-you-extract-the-seed-from-randomly-generated-perlin-noise/31023 "2021-07-03T11:21:59Z")

</div>

Can you get the seed from a randomly generated perlin noise graph?

---

## [Splitting a text into separate words while maintaining linebreaks](https://discourse.processing.org/t/splitting-a-text-into-separate-words-while-maintaining-linebreaks/31019)

<div class="topic-metadata">

**Author:** [@AndreasRef](https://discourse.processing.org/u/AndreasRef)\
**Replies:** 2\
**Last updated:** [July 3, 2021, 1:00am UTC](https://discourse.processing.org/t/splitting-a-text-into-separate-words-while-maintaining-linebreaks/31019 "2021-07-03T01:00:02Z")

</div>

Hi I have a string of text that contains linebreaks (\\n). I want to make one word at a time appear every time I press the mouse. I can do that, however, I have an issue maintaining the linebreaks as they seem to get los…

---

## [Why the rectMode(CENTER) doesn't work for me?](https://discourse.processing.org/t/why-the-rectmode-center-doesnt-work-for-me/31009)

<div class="topic-metadata">

**Author:** [@jexilo](https://discourse.processing.org/u/jexilo)\
**Replies:** 6\
**Last updated:** [July 2, 2021, 10:50am UTC](https://discourse.processing.org/t/why-the-rectmode-center-doesnt-work-for-me/31009 "2021-07-02T10:50:40Z")

</div>

please format code with \</\> button \* homework policy \* asking questions I followed the tutorial and try to have my rectangle in the center but why it’s still not in the center?

---

## [How to set canvas size to 100% of a container div?](https://discourse.processing.org/t/how-to-set-canvas-size-to-100-of-a-container-div/18734)

<div class="topic-metadata">

**Author:** [@spoke123](https://discourse.processing.org/u/spoke123)\
**Replies:** 5\
**Last updated:** [July 1, 2021, 1:42pm UTC](https://discourse.processing.org/t/how-to-set-canvas-size-to-100-of-a-container-div/18734 "2021-07-01T13:42:51Z")

</div>

Hi everyone! How could I go about setting my canvas size to be 100% width and height of its container div, so that I could position and scale the sketch via the div with CSS and have it react to window size adjustment? …

---

## [Problems with converting a P5.js sketch to Processing](https://discourse.processing.org/t/problems-with-converting-a-p5-js-sketch-to-processing/30963)

<div class="topic-metadata">

**Author:** [@lmato](https://discourse.processing.org/u/lmato)\
**Replies:** 4\
**Last updated:** [June 29, 2021, 5:01pm UTC](https://discourse.processing.org/t/problems-with-converting-a-p5-js-sketch-to-processing/30963 "2021-06-29T17:01:47Z")

</div>

Hi, we have to research about particles and I found one sketch that I liked, but noticed its on P5.js. I’ve trying to open remake this sketch in processing but i’m having a really hard time doing it (3 and half hours unt…

---

## [Stuck with trying to remove points close to the edge, how can I do this?](https://discourse.processing.org/t/stuck-with-trying-to-remove-points-close-to-the-edge-how-can-i-do-this/30939)

<div class="topic-metadata">

**Author:** [@alt](https://discourse.processing.org/u/alt)\
**Replies:** 1\
**Last updated:** [June 28, 2021, 8:03pm UTC](https://discourse.processing.org/t/stuck-with-trying-to-remove-points-close-to-the-edge-how-can-i-do-this/30939 "2021-06-28T20:03:44Z")

</div>

I have a problem, I’m trying to remove “stations” or points less than a certain length from the edge, let’s say, 120px from the edge. Now, I tried using a function that removes the stations if they get too close, but tha…

---

## [How to play multiple of a gif in in different positions each loop?](https://discourse.processing.org/t/how-to-play-multiple-of-a-gif-in-in-different-positions-each-loop/30920)

<div class="topic-metadata">

**Author:** [@LuluLuna](https://discourse.processing.org/u/LuluLuna)\
**Replies:** 2\
**Last updated:** [June 26, 2021, 12:30am UTC](https://discourse.processing.org/t/how-to-play-multiple-of-a-gif-in-in-different-positions-each-loop/30920 "2021-06-26T00:30:36Z")

</div>

So what I’m trying to do is play a 5 frame gif of a star I made in multiple random positions. And every time the gif is finished playing it then plays in a new random position. This is the code I current have // Variab…

---

## [Object disappears between Setup() and Draw()?](https://discourse.processing.org/t/object-disappears-between-setup-and-draw/30911)

<div class="topic-metadata">

**Author:** [@pbissell](https://discourse.processing.org/u/pbissell)\
**Replies:** 5\
**Last updated:** [June 25, 2021, 8:30pm UTC](https://discourse.processing.org/t/object-disappears-between-setup-and-draw/30911 "2021-06-25T20:30:49Z")

</div>

I’m a little perplexed. Is there anything that happens between Setup() and Draw() in the sketch? This is my 20th or so ‘mover’ based project. No arrays on this one, but a basic Mover class (position, velocity, radius, e…

---

## [Changing shapes for mouseX movement](https://discourse.processing.org/t/changing-shapes-for-mousex-movement/30889)

<div class="topic-metadata">

**Author:** [@afuria](https://discourse.processing.org/u/afuria)\
**Replies:** 5\
**Last updated:** [June 25, 2021, 2:11am UTC](https://discourse.processing.org/t/changing-shapes-for-mousex-movement/30889 "2021-06-25T02:11:01Z")

</div>

Hello, I am new to P5.js and have made a simple sketch with an ellipse shape that follows the mouseX movement. I would like to understand how to draw a different shape at mouseX based on three different mouseX movements…

---

## [Image() on a 3d canvas on draw() and setup()](https://discourse.processing.org/t/image-on-a-3d-canvas-on-draw-and-setup/30812)

<div class="topic-metadata">

**Author:** [@JoseMY](https://discourse.processing.org/u/JoseMY)\
**Replies:** 7\
**Last updated:** [June 23, 2021, 6:53am UTC](https://discourse.processing.org/t/image-on-a-3d-canvas-on-draw-and-setup/30812 "2021-06-23T06:53:54Z")

</div>

Hi! I’m continuing with my efforts to replicate early works of computer art. I made this nice sketch to replicate Manfred Mohr’s Pascal triangle: http://p5js.sketchpad.cc/NbccVM8Nvk And then I made an animated versio…

---

## [Can I make these animations on curveVertex smooth?](https://discourse.processing.org/t/can-i-make-these-animations-on-curvevertex-smooth/30805)

<div class="topic-metadata">

**Author:** [@cog](https://discourse.processing.org/u/cog)\
**Replies:** 2\
**Last updated:** [June 20, 2021, 11:15pm UTC](https://discourse.processing.org/t/can-i-make-these-animations-on-curvevertex-smooth/30805 "2021-06-20T23:15:29Z")

</div>

https://editor.p5js.org/CarlyRaeJepsenStan/sketches/xH6tvmKep Sorry about the poor code - I’m going to rewrite it with arrays. In any case, as you can see the blob changes bounds and position quite often. However, I w…

---

## [Why is curveTightness acting so weird?](https://discourse.processing.org/t/why-is-curvetightness-acting-so-weird/30770)

<div class="topic-metadata">

**Author:** [@cog](https://discourse.processing.org/u/cog)\
**Replies:** 2\
**Last updated:** [June 19, 2021, 1:06am UTC](https://discourse.processing.org/t/why-is-curvetightness-acting-so-weird/30770 "2021-06-19T01:06:17Z")

</div>

https://editor.p5js.org/CarlyRaeJepsenStan/sketches/xH6tvmKep I am applying curveTightness to a shape made out of points and curveVertex. For some reason, after a certain level of tightness on the curve, this strang…

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

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