# Coding Questions

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

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

**Page:** 51

---

## [Sliding matrix of circles, can't generate or fill new row of circles in 2D array](https://discourse.processing.org/t/sliding-matrix-of-circles-cant-generate-or-fill-new-row-of-circles-in-2d-array/5925)

<div class="topic-metadata">

**Author:** [@gio](https://discourse.processing.org/u/gio)\
**Replies:** 3\
**Last updated:** [November 26, 2018, 1:38pm UTC](https://discourse.processing.org/t/sliding-matrix-of-circles-cant-generate-or-fill-new-row-of-circles-in-2d-array/5925 "2018-11-26T13:38:22Z")

</div>

Hi am creating a 2D array of circles, which slides down every second. Right now if the height of the circles is bigger than the sketch height, it resets the height of the circles to the top. So, i generate once a grid …

---

## [Full opacity of pixel alpha on image border](https://discourse.processing.org/t/full-opacity-of-pixel-alpha-on-image-border/5858)

<div class="topic-metadata">

**Author:** [@slow\_izzm](https://discourse.processing.org/u/slow_izzm)\
**Replies:** 6\
**Last updated:** [November 25, 2018, 2:48am UTC](https://discourse.processing.org/t/full-opacity-of-pixel-alpha-on-image-border/5858 "2018-11-25T02:48:21Z")

</div>

I am seeing full opacity on the border of my image when painting pixels … why is this? My source image has 0 opacity around the edges. If you uncomment lines 21 and 27, and comment out line 52 you will see. In the prov…

---

## [Draw function not looping](https://discourse.processing.org/t/draw-function-not-looping/5694)

<div class="topic-metadata">

**Author:** [@Ramsayrex](https://discourse.processing.org/u/Ramsayrex)\
**Replies:** 4\
**Last updated:** [November 23, 2018, 9:36pm UTC](https://discourse.processing.org/t/draw-function-not-looping/5694 "2018-11-23T21:36:20Z")

</div>

I’m having issues with the draw function and I’m not sure whats causing them var theta = 0 var xcoor = 0 var ycoor = 0 var xint1 = 0 var xint2 = 0 var yint1 = 0 var yint2 = 0 var r = 10 var radius = r\*10 function setu…

---

## [Uneven distrobution instead of normal map()](https://discourse.processing.org/t/uneven-distrobution-instead-of-normal-map/5791)

<div class="topic-metadata">

**Author:** [@noFun](https://discourse.processing.org/u/noFun)\
**Replies:** 3\
**Last updated:** [November 21, 2018, 12:05pm UTC](https://discourse.processing.org/t/uneven-distrobution-instead-of-normal-map/5791 "2018-11-21T12:05:32Z")

</div>

If you use something like map(n,0,100, 0,200), it will map things evenly. 0 maps to 0, 100 maps to 200, and each integer in-between is evenly spaced. But what if you don’t want the mapping to be as even? As in, when lowe…

---

## [Modyfing headers in P5 HttpPost request?](https://discourse.processing.org/t/modyfing-headers-in-p5-httppost-request/5713)

<div class="topic-metadata">

**Author:** [@Noxid](https://discourse.processing.org/u/Noxid)\
**Replies:** 2\
**Last updated:** [November 20, 2018, 4:55am UTC](https://discourse.processing.org/t/modyfing-headers-in-p5-httppost-request/5713 "2018-11-20T04:55:56Z")

</div>

Is it possible to modify the headers of an httpPost request made trough the httpPost() function in P5?For example adding a http authorization header?

---

## [Rotate a Sphere to have a point on the surface be centered on screen](https://discourse.processing.org/t/rotate-a-sphere-to-have-a-point-on-the-surface-be-centered-on-screen/5712)

<div class="topic-metadata">

**Author:** [@FedFod](https://discourse.processing.org/u/FedFod)\
**Replies:** 2\
**Last updated:** [November 20, 2018, 4:50am UTC](https://discourse.processing.org/t/rotate-a-sphere-to-have-a-point-on-the-surface-be-centered-on-screen/5712 "2018-11-20T04:50:25Z")

</div>

Hi all, this is the scenario: I have a sphere made up of an array of vec3 vertices. When I click a button, I want that the whole sphere rotates in a way that the vertex I selected gets positioned in the center of the s…

---

## [Array of Lines that move different to each other Perlin Noise](https://discourse.processing.org/t/array-of-lines-that-move-different-to-each-other-perlin-noise/5564)

<div class="topic-metadata">

**Author:** [@ronantuite](https://discourse.processing.org/u/ronantuite)\
**Replies:** 5\
**Last updated:** [November 19, 2018, 5:45pm UTC](https://discourse.processing.org/t/array-of-lines-that-move-different-to-each-other-perlin-noise/5564 "2018-11-19T17:45:55Z")

</div>

I have a sketch that makes a multiple of vertex lines using beginShape(); and endShape();. They move using Perlin Noise. My problem is that I want each line to move differently while at this moment they all have the same…

---

## [Newbie question: can't load JSON with url](https://discourse.processing.org/t/newbie-question-cant-load-json-with-url/5665)

<div class="topic-metadata">

**Author:** [@Ivano](https://discourse.processing.org/u/Ivano)\
**Replies:** 7\
**Last updated:** [November 19, 2018, 8:30am UTC](https://discourse.processing.org/t/newbie-question-cant-load-json-with-url/5665 "2018-11-19T08:30:14Z")

</div>

Hi I manage to solve all of the problems i encountered on my own, by reading reference page, googling, by watching yt tutorials… but i have problem with loading JSON with url which is not working even thought I done eve…

---

## [Walking removes scale of snake](https://discourse.processing.org/t/walking-removes-scale-of-snake/1657)

<div class="topic-metadata">

**Author:** [@ville2008](https://discourse.processing.org/u/ville2008)\
**Replies:** 1\
**Last updated:** [November 18, 2018, 9:24pm UTC](https://discourse.processing.org/t/walking-removes-scale-of-snake/1657 "2018-11-18T21:24:50Z")

</div>

when i play my game and eat a food and then move it sometimes removes my scale heres my source code sketch source: (where my move runs) var s; var scl = 20; var food = 20; var foods = 0; var foodU = foods; functio…

---

## [Wait until Canvas gets created in DOM](https://discourse.processing.org/t/wait-until-canvas-gets-created-in-dom/5602)

<div class="topic-metadata">

**Author:** [@FedFod](https://discourse.processing.org/u/FedFod)\
**Replies:** 2\
**Last updated:** [November 16, 2018, 3:42pm UTC](https://discourse.processing.org/t/wait-until-canvas-gets-created-in-dom/5602 "2018-11-16T15:42:13Z")

</div>

Hi all, I have this code: canvas2 = mCreateCanvas(m4.windowWidth, m4.windowHeight, m4.WEBGL); m4.setAttributes('antialias', true); glCanvas = document.getElementById('defaultCanvas0').getContext('webgl'); …

---

## [P5.js - Mouse and keys stuck](https://discourse.processing.org/t/p5-js-mouse-and-keys-stuck/5556)

<div class="topic-metadata">

**Author:** [@Sarah](https://discourse.processing.org/u/Sarah)\
**Replies:** 12\
**Last updated:** [November 16, 2018, 10:02am UTC](https://discourse.processing.org/t/p5-js-mouse-and-keys-stuck/5556 "2018-11-16T10:02:19Z")

</div>

Hi, I’ve been experimenting with p5.js for a bit, and I’ve noticed that the mouse and key functions sometimes get stuck. The problem is caused for me when you right-click, or hold a key, then right-click. (In the sketc…

---

## [What to do about variables that are not assigned in a class?](https://discourse.processing.org/t/what-to-do-about-variables-that-are-not-assigned-in-a-class/5517)

<div class="topic-metadata">

**Author:** [@yangs](https://discourse.processing.org/u/yangs)\
**Replies:** 6\
**Last updated:** [November 16, 2018, 2:56am UTC](https://discourse.processing.org/t/what-to-do-about-variables-that-are-not-assigned-in-a-class/5517 "2018-11-16T02:56:18Z")

</div>

Hi all! I’m trying to convert Daniel Shiffman’s sine wave example to a class so I can have multiple instances of it. However, when I start creating the class: class Wave { constructor(){ this.xspacing = 20; t…

---

## [Offline video masking](https://discourse.processing.org/t/offline-video-masking/5495)

<div class="topic-metadata">

**Author:** [@dirkk0](https://discourse.processing.org/u/dirkk0)\
**Replies:** 0\
**Last updated:** [November 13, 2018, 12:39pm UTC](https://discourse.processing.org/t/offline-video-masking/5495 "2018-11-13T12:39:06Z")

</div>

Hi, is there a way to load a video, mask it and create a new, already masked video from it? Thanks, Dirk

---

## [Resize canvas from windowResize() distorts proportions of 3D objects](https://discourse.processing.org/t/resize-canvas-from-windowresize-distorts-proportions-of-3d-objects/5492)

<div class="topic-metadata">

**Author:** [@FedFod](https://discourse.processing.org/u/FedFod)\
**Replies:** 0\
**Last updated:** [November 13, 2018, 12:08pm UTC](https://discourse.processing.org/t/resize-canvas-from-windowresize-distorts-proportions-of-3d-objects/5492 "2018-11-13T12:08:38Z")

</div>

Hi everybody, so when I resize the canvas in this way: m4.windowResized = function() { m4.resizeCanvas(m4.windowWidth, m4.windowHeight); // sphereVertices = pointsOnSphere(etiquetasLength); } the 3D objects on my w…

---

## [Animation frames overwrite themselves. Why?](https://discourse.processing.org/t/animation-frames-overwrite-themselves-why/5452)

<div class="topic-metadata">

**Author:** [@Arnoldovna](https://discourse.processing.org/u/Arnoldovna)\
**Replies:** 3\
**Last updated:** [November 12, 2018, 9:55pm UTC](https://discourse.processing.org/t/animation-frames-overwrite-themselves-why/5452 "2018-11-12T21:55:34Z")

</div>

I am using a video input to draw onto a canvas in order to get the color of the pixel in the very middle of the canvas. With the recent code I have the pixel color and pass it as a color value to draw a line. This line …

---

## [Loading Video from URL?](https://discourse.processing.org/t/loading-video-from-url/5480)

<div class="topic-metadata">

**Author:** [@Arnoldovna](https://discourse.processing.org/u/Arnoldovna)\
**Replies:** 3\
**Last updated:** [November 12, 2018, 7:15pm UTC](https://discourse.processing.org/t/loading-video-from-url/5480 "2018-11-12T19:15:32Z")

</div>

hello. Im trying to create a Video with createVideo() from a youtube URL. In order to draw it on a canvas later on. Is this possible? I saw something like this “URL.createObjectURL”. Is this pointing in the right direc…

---

## [Why is the function Fill not found? but the rest of the functions on the library yes?](https://discourse.processing.org/t/why-is-the-function-fill-not-found-but-the-rest-of-the-functions-on-the-library-yes/5447)

<div class="topic-metadata">

**Author:** [@gio](https://discourse.processing.org/u/gio)\
**Replies:** 1\
**Last updated:** [November 11, 2018, 2:57pm UTC](https://discourse.processing.org/t/why-is-the-function-fill-not-found-but-the-rest-of-the-functions-on-the-library-yes/5447 "2018-11-11T14:57:50Z")

</div>

Im workingon a P5.js sketch… Instead of creating objects with a constructor function, and then using the new keyword. I want to use a factory function. It seems to work fine, and renders correclty when using for examp…

---

## [Trouble rotating an array of objects](https://discourse.processing.org/t/trouble-rotating-an-array-of-objects/5423)

<div class="topic-metadata">

**Author:** [@Speedofox](https://discourse.processing.org/u/Speedofox)\
**Replies:** 2\
**Last updated:** [November 11, 2018, 9:57am UTC](https://discourse.processing.org/t/trouble-rotating-an-array-of-objects/5423 "2018-11-11T09:57:01Z")

</div>

I have created an array of objects using a class call Triangle. How can I translate each of these objects so that they all spin independently on their own axis? So far I have gotten them all to rotate correctly but the a…

---

## [Applying specific colors to a p5.Geometry](https://discourse.processing.org/t/applying-specific-colors-to-a-p5-geometry/5228)

<div class="topic-metadata">

**Author:** [@philippe](https://discourse.processing.org/u/philippe)\
**Replies:** 0\
**Last updated:** [November 5, 2018, 2:51pm UTC](https://discourse.processing.org/t/applying-specific-colors-to-a-p5-geometry/5228 "2018-11-05T14:51:51Z")

</div>

I have made a sphere using new p5.Geometry() geometry = new p5.Geometry(definition, definition, ellipsoid); geometry.computeFaces().\_makeTriangleEdges().\_edgesToVertices(); renderer.createBuffers(gId, geometry); rendere…

---

## [Dynamically update alpha in color()](https://discourse.processing.org/t/dynamically-update-alpha-in-color/5339)

<div class="topic-metadata">

**Author:** [@slow\_izzm](https://discourse.processing.org/u/slow_izzm)\
**Replies:** 5\
**Last updated:** [November 9, 2018, 2:16am UTC](https://discourse.processing.org/t/dynamically-update-alpha-in-color/5339 "2018-11-09T02:16:35Z")

</div>

So, what if I wanted to dynamically change each individual rgba argument of color(), can I say this.col.r = 200; , or some equivalent? let btn; function setup() { createCanvas(400, 400); btn = new Btn(color(50, 127, …

---

## [Load sketch.js dynamically](https://discourse.processing.org/t/load-sketch-js-dynamically/5354)

<div class="topic-metadata">

**Author:** [@edufissure](https://discourse.processing.org/u/edufissure)\
**Replies:** 0\
**Last updated:** [November 8, 2018, 8:00pm UTC](https://discourse.processing.org/t/load-sketch-js-dynamically/5354 "2018-11-08T20:00:09Z")

</div>

Hello im a newbie here in p5.js and i need some help: Im trying to launch sketch.js when i click on start game… but i cant get it… This is my code: \<!DOCTYPE html\> \<html lang="en"\> \<head\> \<meta charset="UTF-8"\> …

---

## [Gentle jiggle with sine wave](https://discourse.processing.org/t/gentle-jiggle-with-sine-wave/5291)

<div class="topic-metadata">

**Author:** [@yangs](https://discourse.processing.org/u/yangs)\
**Replies:** 5\
**Last updated:** [November 7, 2018, 11:15pm UTC](https://discourse.processing.org/t/gentle-jiggle-with-sine-wave/5291 "2018-11-07T23:15:42Z")

</div>

Hi all! I’m hoping someone could point me in the right direction. I’m attempting to create a function that allows the user to draw lines, but the lines will gently wiggle, like if they are being blown in the wind. For th…

---

## [Pass an array to a new instance of my class](https://discourse.processing.org/t/pass-an-array-to-a-new-instance-of-my-class/5183)

<div class="topic-metadata">

**Author:** [@slow\_izzm](https://discourse.processing.org/u/slow_izzm)\
**Replies:** 20\
**Last updated:** [November 6, 2018, 10:21pm UTC](https://discourse.processing.org/t/pass-an-array-to-a-new-instance-of-my-class/5183 "2018-11-06T22:21:19Z")

</div>

How would I go about passing an array of images to a class? My endgame is to have one class that creates an animation, so when I create multiple instances of this class they build a 3x3 grid of animations with each insta…

---

## [Raining effect in transparent background](https://discourse.processing.org/t/raining-effect-in-transparent-background/4565)

<div class="topic-metadata">

**Author:** [@juju11](https://discourse.processing.org/u/juju11)\
**Replies:** 7\
**Last updated:** [November 5, 2018, 2:57pm UTC](https://discourse.processing.org/t/raining-effect-in-transparent-background/4565 "2018-11-05T14:57:45Z")

</div>

Hi, I’m really new to p5js :tired\_face: and right now I’m making a rain effect in p5. It went well with a background color in my canvas. ( https://cl.ly/d49185682356 ) However, What I want to do is making the background…

---

## [Using the Array of Objects Resource with unique objects](https://discourse.processing.org/t/using-the-array-of-objects-resource-with-unique-objects/5182)

<div class="topic-metadata">

**Author:** [@yangs](https://discourse.processing.org/u/yangs)\
**Replies:** 8\
**Last updated:** [November 4, 2018, 7:39pm UTC](https://discourse.processing.org/t/using-the-array-of-objects-resource-with-unique-objects/5182 "2018-11-04T19:39:37Z")

</div>

Hi all! I’m stuck on something and I’m sure the answer is a simple one but I can’t seem to find the issue. Using the p5js Array of Objects, I’m essentially trying to exactly that, with squiggly objects instead of ellips…

---

## [Changing stroke colour using recursion](https://discourse.processing.org/t/changing-stroke-colour-using-recursion/4951)

<div class="topic-metadata">

**Author:** [@greg500](https://discourse.processing.org/u/greg500)\
**Replies:** 9\
**Last updated:** [November 1, 2018, 10:51pm UTC](https://discourse.processing.org/t/changing-stroke-colour-using-recursion/4951 "2018-11-01T22:51:38Z")

</div>

I am struggling with the error of which throw me once I am trying to recursively change a colour. The error is: “Uncaught TypeError Cannot read property ‘map’ of undefined (sketch: line 18)” and reference to this piece o…

---

## [Issue with loading images](https://discourse.processing.org/t/issue-with-loading-images/5061)

<div class="topic-metadata">

**Author:** [@Quillbert1](https://discourse.processing.org/u/Quillbert1)\
**Replies:** 9\
**Last updated:** [November 1, 2018, 3:05am UTC](https://discourse.processing.org/t/issue-with-loading-images/5061 "2018-11-01T03:05:12Z")

</div>

When I run this program with the editor, it works fine. But when I download the files and try to use Chrome to run the program, it just says “Loading…” but it never loads. It works fine in other browsers. https://editor…

---

## [Offscreen buffer offset weirdness - "works on THIS mac"](https://discourse.processing.org/t/offscreen-buffer-offset-weirdness-works-on-this-mac/4926)

<div class="topic-metadata">

**Author:** [@kirkjerk](https://discourse.processing.org/u/kirkjerk)\
**Replies:** 7\
**Last updated:** [October 31, 2018, 5:27pm UTC](https://discourse.processing.org/t/offscreen-buffer-offset-weirdness-works-on-this-mac/4926 "2018-10-31T17:27:00Z")

</div>

I made a version of A.K.Dewdney’s famous Wa-Tor - https://toys.alienbill.com/wator/index2.html I used instance mode, because I wanted to have the main cellular automata area send data to a seperate canvas for it to gra…

---

## [P5.js sketches with terrible framerate on chrome](https://discourse.processing.org/t/p5-js-sketches-with-terrible-framerate-on-chrome/499)

<div class="topic-metadata">

**Author:** [@colin](https://discourse.processing.org/u/colin)\
**Replies:** 19\
**Last updated:** [October 31, 2018, 3:06am UTC](https://discourse.processing.org/t/p5-js-sketches-with-terrible-framerate-on-chrome/499 "2018-10-31T03:06:23Z")

</div>

Hi, I developed several games using P5.js and I managed to make them work around 60fps. Sadly, I discovered that they’re working around 10fps on a lot of browsers including recent versions of chrome and safari. Here is …

---

## [Image filter example in a loop draw](https://discourse.processing.org/t/image-filter-example-in-a-loop-draw/4905)

<div class="topic-metadata">

**Author:** [@antocreo](https://discourse.processing.org/u/antocreo)\
**Replies:** 4\
**Last updated:** [October 30, 2018, 6:39pm UTC](https://discourse.processing.org/t/image-filter-example-in-a-loop-draw/4905 "2018-10-30T18:39:23Z")

</div>

Hi, I’ve been playing around with P5js and I am trying to use the image filter on an event like mouseMoved. I am having lot of trouble. The only examples I found use the filter in the setup function. so, how do you c…

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

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