# Coding Questions

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

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

**Page:** 27

---

## [Code works correctly in p5, but translation to Processing outputs weird results](https://discourse.processing.org/t/code-works-correctly-in-p5-but-translation-to-processing-outputs-weird-results/24508)

<div class="topic-metadata">

**Author:** [@pablohotsauce](https://discourse.processing.org/u/pablohotsauce)\
**Replies:** 3\
**Last updated:** [October 12, 2020, 6:39am UTC](https://discourse.processing.org/t/code-works-correctly-in-p5-but-translation-to-processing-outputs-weird-results/24508 "2020-10-12T06:39:06Z")

</div>

I threw something together in p5, and it works as intended. Then I tried to translate it to (Java) Processing, and although it runs, the results are weird. I’ve checked everything I can think of, and I’m not sure what th…

---

## [How to detect trackpad actions like pinch, scroll, three finger actions etc](https://discourse.processing.org/t/how-to-detect-trackpad-actions-like-pinch-scroll-three-finger-actions-etc/23646)

<div class="topic-metadata">

**Author:** [@grege2](https://discourse.processing.org/u/grege2)\
**Replies:** 2\
**Last updated:** [October 12, 2020, 3:20am UTC](https://discourse.processing.org/t/how-to-detect-trackpad-actions-like-pinch-scroll-three-finger-actions-etc/23646 "2020-10-12T03:20:30Z")

</div>

Hi all, I recently had a need to detect a two-finger “pinch” action, on a Mac in p5.js, and had some trouble finding info. I found this … https://medium.com/@auchenberg/detecting-multi-touch-trackpad-gestures-in-javas…

---

## [Accidental fractal pattern using line(), and wonky line() behavior](https://discourse.processing.org/t/accidental-fractal-pattern-using-line-and-wonky-line-behavior/24425)

<div class="topic-metadata">

**Author:** [@KaliBrain](https://discourse.processing.org/u/KaliBrain)\
**Replies:** 3\
**Last updated:** [October 10, 2020, 8:18pm UTC](https://discourse.processing.org/t/accidental-fractal-pattern-using-line-and-wonky-line-behavior/24425 "2020-10-10T20:18:38Z")

</div>

So playing around with vectors for the first time I created a circle by drawing a line and rotating it: let count = 0 let slice = 6 let oddSize = 0.0625 function unitVectorGrade() { translate(width / 2, height / 2) …

---

## [loadTable - how to handle missing file error?](https://discourse.processing.org/t/loadtable-how-to-handle-missing-file-error/24476)

<div class="topic-metadata">

**Author:** [@RichardDL](https://discourse.processing.org/u/RichardDL)\
**Replies:** 3\
**Last updated:** [October 10, 2020, 5:00pm UTC](https://discourse.processing.org/t/loadtable-how-to-handle-missing-file-error/24476 "2020-10-10T17:00:38Z")

</div>

Hi, I have a web-page served by node.js. In the web-page is a loadTable which loads a csv file from disk. loadTable is async and the draw action is controlled by iLoadData. In the good callback, this is incremented …

---

## [Why isn't my canvas resizing in p5.js?](https://discourse.processing.org/t/why-isnt-my-canvas-resizing-in-p5-js/24466)

<div class="topic-metadata">

**Author:** [@sam101](https://discourse.processing.org/u/sam101)\
**Replies:** 2\
**Last updated:** [October 10, 2020, 3:25am UTC](https://discourse.processing.org/t/why-isnt-my-canvas-resizing-in-p5-js/24466 "2020-10-10T03:25:27Z")

</div>

Hey everyone, so I was editing my code and I believe when I added the translate function in my function draw, it somehow prevented my text and other contexts of my sketch to resize when I would resize my browser. Not sur…

---

## [Can you use a Slider to change a circle to square in p5.js?](https://discourse.processing.org/t/can-you-use-a-slider-to-change-a-circle-to-square-in-p5-js/24405)

<div class="topic-metadata">

**Author:** [@sam101](https://discourse.processing.org/u/sam101)\
**Replies:** 2\
**Last updated:** [October 9, 2020, 7:04pm UTC](https://discourse.processing.org/t/can-you-use-a-slider-to-change-a-circle-to-square-in-p5-js/24405 "2020-10-09T19:04:22Z")

</div>

Hey everyone was hoping if someone could direct me in a direction of how to code a slider to change a circle into a square? I’ve achieved being able to change the colour and shape and rotating it, but I haven’t been able…

---

## [How to rotate a single image?](https://discourse.processing.org/t/how-to-rotate-a-single-image/24465)

<div class="topic-metadata">

**Author:** [@Emilia444](https://discourse.processing.org/u/Emilia444)\
**Replies:** 2\
**Last updated:** [October 9, 2020, 1:56pm UTC](https://discourse.processing.org/t/how-to-rotate-a-single-image/24465 "2020-10-09T13:56:08Z")

</div>

Hey guys, I’m rather unfamiliar with ps5, and have recently been trying it out. I’ve tried looking this up and couldn’t find an answer for it, but I’m creating a program with multiple images in it. I was wondering if the…

---

## [How to write my code so that it adjusts to mobile screen for p5.js?](https://discourse.processing.org/t/how-to-write-my-code-so-that-it-adjusts-to-mobile-screen-for-p5-js/24456)

<div class="topic-metadata">

**Author:** [@sam101](https://discourse.processing.org/u/sam101)\
**Replies:** 1\
**Last updated:** [October 9, 2020, 7:02am UTC](https://discourse.processing.org/t/how-to-write-my-code-so-that-it-adjusts-to-mobile-screen-for-p5-js/24456 "2020-10-09T07:02:22Z")

</div>

Hey everyone, I was just wondering if I have a code that when I upload it as a website it works on a desktop, but then how would I write it out so that it also adjusts to a mobile screen as well. The code is in p5.js and…

---

## [Ways to hide the HTML text-input box? Or alternatives?](https://discourse.processing.org/t/ways-to-hide-the-html-text-input-box-or-alternatives/24429)

<div class="topic-metadata">

**Author:** [@aith](https://discourse.processing.org/u/aith)\
**Replies:** 4\
**Last updated:** [October 9, 2020, 4:22am UTC](https://discourse.processing.org/t/ways-to-hide-the-html-text-input-box-or-alternatives/24429 "2020-10-09T04:22:34Z")

</div>

Hi! I’m using p5 to fake a retro computer terminal for a spooky game. I want the user to be able to type in the terminal, but I find the html text-input box to be visually jarring. Is there a way to let the user click o…

---

## [Can I use shaders with electron and p5js?](https://discourse.processing.org/t/can-i-use-shaders-with-electron-and-p5js/24444)

<div class="topic-metadata">

**Author:** [@stephanschulz](https://discourse.processing.org/u/stephanschulz)\
**Replies:** 3\
**Last updated:** [October 9, 2020, 4:20am UTC](https://discourse.processing.org/t/can-i-use-shaders-with-electron-and-p5js/24444 "2020-10-09T04:20:17Z")

</div>

I am able to run this template, which create an electron app with p5js code. But as soon as I add shader loading the app displays a black window. Everything works fine when running the same code through Brackets as a…

---

## [How to get the words to appear in a horizontal line rather than vertical line in p5.js?](https://discourse.processing.org/t/how-to-get-the-words-to-appear-in-a-horizontal-line-rather-than-vertical-line-in-p5-js/24430)

<div class="topic-metadata">

**Author:** [@sam101](https://discourse.processing.org/u/sam101)\
**Replies:** 2\
**Last updated:** [October 8, 2020, 12:35pm UTC](https://discourse.processing.org/t/how-to-get-the-words-to-appear-in-a-horizontal-line-rather-than-vertical-line-in-p5-js/24430 "2020-10-08T12:35:20Z")

</div>

Hey everyone I was just wondering how do I get the words to appear in a horizontal line rather than a vertical line in this code??? any help would be great! var myText = 'S H O U T'; var words; function setup() { cr…

---

## [Trouble with Vector.add](https://discourse.processing.org/t/trouble-with-vector-add/24170)

<div class="topic-metadata">

**Author:** [@noonscoomo](https://discourse.processing.org/u/noonscoomo)\
**Replies:** 3\
**Last updated:** [October 8, 2020, 7:27am UTC](https://discourse.processing.org/t/trouble-with-vector-add/24170 "2020-10-08T07:27:40Z")

</div>

Hi, I am in trouble with the p5.Vector.add() method and I don’t see why. My code generates a 2D Vector in setup, adds a random 2D vector in draw, pushes the result in an array and draws the whole array in a loop. If I …

---

## [Can i de-load or selectively load in images?](https://discourse.processing.org/t/can-i-de-load-or-selectively-load-in-images/24392)

<div class="topic-metadata">

**Author:** [@jstodd](https://discourse.processing.org/u/jstodd)\
**Replies:** 2\
**Last updated:** [October 7, 2020, 8:35am UTC](https://discourse.processing.org/t/can-i-de-load-or-selectively-load-in-images/24392 "2020-10-07T08:35:14Z")

</div>

Im having performance problems in my application due to i believe a lot of different images and files being loaded in at once. My program starts off fast, but gets slower over time. I believe this is a memory issue and …

---

## [keyPressed to change image color, help!](https://discourse.processing.org/t/keypressed-to-change-image-color-help/24244)

<div class="topic-metadata">

**Author:** [@iwanttobelieve](https://discourse.processing.org/u/iwanttobelieve)\
**Replies:** 2\
**Last updated:** [October 1, 2020, 10:22pm UTC](https://discourse.processing.org/t/keypressed-to-change-image-color-help/24244 "2020-10-01T22:22:58Z")

</div>

Hey there! I was tasked to recreate the bouncing DVD logo screen - however I’m meant to make it so that when a key is pressed, the image changes a random color. I’ve tried a bunch of different combinations, and can’t se…

---

## [Trouble with code linking to JSON file in p5.js?](https://discourse.processing.org/t/trouble-with-code-linking-to-json-file-in-p5-js/24241)

<div class="topic-metadata">

**Author:** [@sam101](https://discourse.processing.org/u/sam101)\
**Replies:** 5\
**Last updated:** [October 1, 2020, 1:45pm UTC](https://discourse.processing.org/t/trouble-with-code-linking-to-json-file-in-p5-js/24241 "2020-10-01T13:45:51Z")

</div>

Hi everyone, so I’ve just changed my JSON data so that I can link it my “date” as well as the “hours”. So I wrote out this section two lines to get the data working, but so far no luck. Was wondering if anyone can help? …

---

## [Trouble Writing JSON code?](https://discourse.processing.org/t/trouble-writing-json-code/24232)

<div class="topic-metadata">

**Author:** [@sam101](https://discourse.processing.org/u/sam101)\
**Replies:** 1\
**Last updated:** [September 30, 2020, 1:12pm UTC](https://discourse.processing.org/t/trouble-writing-json-code/24232 "2020-09-30T13:12:33Z")

</div>

So I’m trying to nestle my “hours” array within my “Sunday” array. So the code below works and is validated, but when I repeat the code, that is of Mondays data underneath this code, it doesn’t validate anymore. I’ve tri…

---

## [How do I get my shapes to move/animate around the canvas on p5.js?](https://discourse.processing.org/t/how-do-i-get-my-shapes-to-move-animate-around-the-canvas-on-p5-js/24233)

<div class="topic-metadata">

**Author:** [@sam101](https://discourse.processing.org/u/sam101)\
**Replies:** 3\
**Last updated:** [September 30, 2020, 12:40pm UTC](https://discourse.processing.org/t/how-do-i-get-my-shapes-to-move-animate-around-the-canvas-on-p5-js/24233 "2020-09-30T12:40:33Z")

</div>

Hi everyone, I’m a bit lost in how I could get my shapes that I have created to move around the canvas. So far they are quite static. Any suggestions or methods I could look into would be great!

---

## [Changing data visualisation through MousePressed function in p5.js?](https://discourse.processing.org/t/changing-data-visualisation-through-mousepressed-function-in-p5-js/24196)

<div class="topic-metadata">

**Author:** [@sam101](https://discourse.processing.org/u/sam101)\
**Replies:** 4\
**Last updated:** [September 29, 2020, 10:59am UTC](https://discourse.processing.org/t/changing-data-visualisation-through-mousepressed-function-in-p5-js/24196 "2020-09-29T10:59:41Z")

</div>

Hey everyone, okay so this issue has got me super confused. So basically I would like the sketch to show a data visualisation of one JSON file. (being a Sunday data). But when I mousePress, the data would represent anot…

---

## [Is it possible to create more than one button for different actions in p5.js?](https://discourse.processing.org/t/is-it-possible-to-create-more-than-one-button-for-different-actions-in-p5-js/24194)

<div class="topic-metadata">

**Author:** [@sam101](https://discourse.processing.org/u/sam101)\
**Replies:** 1\
**Last updated:** [September 28, 2020, 4:27pm UTC](https://discourse.processing.org/t/is-it-possible-to-create-more-than-one-button-for-different-actions-in-p5-js/24194 "2020-09-28T16:27:13Z")

</div>

Hi everyone, was just wondering is there a way to create multiple buttons that can output different functions within p5.js. I’m looking into the button references on p5.js .org, but it looks like it hasn’t mentioned anyt…

---

## [How do I generate circles appearing one at a time, rather than a whole cluster of circles in p5.js](https://discourse.processing.org/t/how-do-i-generate-circles-appearing-one-at-a-time-rather-than-a-whole-cluster-of-circles-in-p5-js/24182)

<div class="topic-metadata">

**Author:** [@sam101](https://discourse.processing.org/u/sam101)\
**Replies:** 5\
**Last updated:** [September 28, 2020, 3:01pm UTC](https://discourse.processing.org/t/how-do-i-generate-circles-appearing-one-at-a-time-rather-than-a-whole-cluster-of-circles-in-p5-js/24182 "2020-09-28T15:01:15Z")

</div>

Hi everyone, so I was wondering how do I get the ellipse that I have drawn to appear one at a time, rather than having 10 all appear at once as a group? var data; var instagram, snapchat, messenger, facebook, email, in…

---

## [How do I generate colour based on my JSON data in p5.js?](https://discourse.processing.org/t/how-do-i-generate-colour-based-on-my-json-data-in-p5-js/24148)

<div class="topic-metadata">

**Author:** [@sam101](https://discourse.processing.org/u/sam101)\
**Replies:** 2\
**Last updated:** [September 28, 2020, 11:24am UTC](https://discourse.processing.org/t/how-do-i-generate-colour-based-on-my-json-data-in-p5-js/24148 "2020-09-28T11:24:25Z")

</div>

Hi everyone! I’m trying to figure out how I can generate colour that will respond to my JSON data. Heres the code so far and I’ve highlighted the bits at the end to show my attempt, but obviously it hasn’t worked. The …

---

## [MousePressed function not working?](https://discourse.processing.org/t/mousepressed-function-not-working/24187)

<div class="topic-metadata">

**Author:** [@sam101](https://discourse.processing.org/u/sam101)\
**Replies:** 3\
**Last updated:** [September 28, 2020, 10:59am UTC](https://discourse.processing.org/t/mousepressed-function-not-working/24187 "2020-09-28T10:59:00Z")

</div>

Hey everyone, so somehow my mousePressed function isn’t changing the days of the week text whenever I mousepress, but it is starting a new sketch… Don’t know whats preventing the text from changing? If anyone can figure…

---

## [P5js in an epub3 on kobo ereader?](https://discourse.processing.org/t/p5js-in-an-epub3-on-kobo-ereader/9266)

<div class="topic-metadata">

**Author:** [@mrbbp](https://discourse.processing.org/u/mrbbp)\
**Replies:** 3\
**Last updated:** [September 27, 2020, 9:06pm UTC](https://discourse.processing.org/t/p5js-in-an-epub3-on-kobo-ereader/9266 "2020-09-27T21:06:12Z")

</div>

Hello, I’m starting playing with kobo ereader and epub 3 format. I’ts xhtml5, on kobo ereader with the kepub.epub js are running. I’m able to run basic script and attempt to use P5js, to use it canvas abilities… I’ve…

---

## [Buffering videos fully before playing them](https://discourse.processing.org/t/buffering-videos-fully-before-playing-them/24080)

<div class="topic-metadata">

**Author:** [@agidron](https://discourse.processing.org/u/agidron)\
**Replies:** 8\
**Last updated:** [September 27, 2020, 7:37pm UTC](https://discourse.processing.org/t/buffering-videos-fully-before-playing-them/24080 "2020-09-27T19:37:49Z")

</div>

Hello! I’m relatively new to JS and P5 with limited coding background, and I’m learning as I go. This is my first post here. I’m building a website that needs to stream several videos simultaneously for a music/video p…

---

## [Hi guys, the console is showing me the result "undefined" about the api](https://discourse.processing.org/t/hi-guys-the-console-is-showing-me-the-result-undefined-about-the-api/24154)

<div class="topic-metadata">

**Author:** [@kappo25](https://discourse.processing.org/u/kappo25)\
**Replies:** 2\
**Last updated:** [September 27, 2020, 3:30pm UTC](https://discourse.processing.org/t/hi-guys-the-console-is-showing-me-the-result-undefined-about-the-api/24154 "2020-09-27T15:30:45Z")

</div>

var weather; function setup() { loadJSON( 'https://restcountries.eu/rest/v2/capital/tallinn', gotData ); } function gotData(data) { weather = data; } function draw() { background(0); if (weather) { …

---

## [Code not working in p5.js with JSON data?](https://discourse.processing.org/t/code-not-working-in-p5-js-with-json-data/24152)

<div class="topic-metadata">

**Author:** [@sam101](https://discourse.processing.org/u/sam101)\
**Replies:** 1\
**Last updated:** [September 27, 2020, 2:30pm UTC](https://discourse.processing.org/t/code-not-working-in-p5-js-with-json-data/24152 "2020-09-27T14:30:04Z")

</div>

I’m trying to tell the system to let the number value stored within my JSON file to determine the size of the ellipse. I referenced this https://editor.p5js.org/bavazzanos1/sketches/Bkkdrs11M MY CODE SO FAR: var data; …

---

## [How do I draw a circle based on my JSON data information in p5.js?](https://discourse.processing.org/t/how-do-i-draw-a-circle-based-on-my-json-data-information-in-p5-js/24146)

<div class="topic-metadata">

**Author:** [@sam101](https://discourse.processing.org/u/sam101)\
**Replies:** 2\
**Last updated:** [September 27, 2020, 11:18am UTC](https://discourse.processing.org/t/how-do-i-draw-a-circle-based-on-my-json-data-information-in-p5-js/24146 "2020-09-27T11:18:31Z")

</div>

So, I’m trying to grab data from my JSON file to my code and display the circle size according to the number on my JSON file. So far this is the code. var data; var instagram, snapchat, messenger, facebook, email, ins…

---

## [How do I get the mousePressed function to change to different words each time on p5.js?](https://discourse.processing.org/t/how-do-i-get-the-mousepressed-function-to-change-to-different-words-each-time-on-p5-js/24134)

<div class="topic-metadata">

**Author:** [@sam101](https://discourse.processing.org/u/sam101)\
**Replies:** 4\
**Last updated:** [September 26, 2020, 11:50am UTC](https://discourse.processing.org/t/how-do-i-get-the-mousepressed-function-to-change-to-different-words-each-time-on-p5-js/24134 "2020-09-26T11:50:51Z")

</div>

Hi everyone! Was wondering how do I get the text to change every time I mousePress it. E.g. Sunday, then to Monday, then to Tuesday and so forth until it get to Saturday? Any help will be much appreciated Would I use …

---

## [How to trigger keypress events in p5.js](https://discourse.processing.org/t/how-to-trigger-keypress-events-in-p5-js/24082)

<div class="topic-metadata">

**Author:** [@yashkhasgiwala](https://discourse.processing.org/u/yashkhasgiwala)\
**Replies:** 1\
**Last updated:** [September 24, 2020, 12:02am UTC](https://discourse.processing.org/t/how-to-trigger-keypress-events-in-p5-js/24082 "2020-09-24T00:02:52Z")

</div>

I want my code to press keyboard keys if a certain condition is True in p5.js library. For example: a = true if (a) { // Press UP Key } else { // Press DOWN Key }

---

## [Text adventure game: go back a page using if-clause?](https://discourse.processing.org/t/text-adventure-game-go-back-a-page-using-if-clause/23967)

<div class="topic-metadata">

**Author:** [@DariusKempton](https://discourse.processing.org/u/DariusKempton)\
**Replies:** 1\
**Last updated:** [September 23, 2020, 3:58pm UTC](https://discourse.processing.org/t/text-adventure-game-go-back-a-page-using-if-clause/23967 "2020-09-23T15:58:07Z")

</div>

I am trying to make it so that if you accidentally select a race that you don’t like, or change your mind, you can choose to go back a page, but i cant quite figure out how to make it more streamlined. currently, if you …

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

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