# Coding Questions

**URL:** https://discourse.processing.org/c/p5js/p5js-questions/18.md

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

---

## [About the p5.js / Coding Questions category](https://discourse.processing.org/t/about-the-p5-js-coding-questions-category/29)

<div class="topic-metadata">

**Author:** [@ProcessingOrg](https://discourse.processing.org/u/ProcessingOrg)\
**Replies:** 0

</div>

Questions about a p5.js example, found code, or some code you’re writing

---

## [P5js 3D sketches - how to overlay a 2D image e.g. HUD or GUI](https://discourse.processing.org/t/p5js-3d-sketches-how-to-overlay-a-2d-image-e-g-hud-or-gui/49509)

<div class="topic-metadata">

**Author:** [@quark](https://discourse.processing.org/u/quark)\
**Replies:** 5\
**Last updated:** [September 27, 2026, 9:02pm UTC](https://discourse.processing.org/t/p5js-3d-sketches-how-to-overlay-a-2d-image-e-g-hud-or-gui/49509 "2026-09-27T21:02:12Z")

</div>

This sketch shows a p5.js animated sketch using WebGL (based on a library example) and there are three 2D images overlaying the animation. the inner frame the avatar the text The images are drawn by shaders created us…

---

## [Read error with TXT and CSV files. SyntaxError: expected expression, got keyword 'do' at undefined:965:8](https://discourse.processing.org/t/read-error-with-txt-and-csv-files-syntaxerror-expected-expression-got-keyword-do-at-undefined8/49463)

<div class="topic-metadata">

**Author:** [@mgdunefa2](https://discourse.processing.org/u/mgdunefa2)\
**Replies:** 2\
**Last updated:** [September 26, 2026, 2:59pm UTC](https://discourse.processing.org/t/read-error-with-txt-and-csv-files-syntaxerror-expected-expression-got-keyword-do-at-undefined8/49463 "2026-09-26T14:59:39Z")

</div>

‘’’ javascript let palabras = ; let palabraActual = “”; async function setup() { createCanvas(800, 500); try { const respuesta = await fetch(“palabras.txt”); const texto = await respuesta.text(); palabras = texto …

---

## [How do I get an obj file with one and only one texture?](https://discourse.processing.org/t/how-do-i-get-an-obj-file-with-one-and-only-one-texture/49437)

<div class="topic-metadata">

**Author:** [@EricRogerGarcia](https://discourse.processing.org/u/EricRogerGarcia)\
**Replies:** 1\
**Last updated:** [September 24, 2026, 6:40pm UTC](https://discourse.processing.org/t/how-do-i-get-an-obj-file-with-one-and-only-one-texture/49437 "2026-09-24T18:40:19Z")

</div>

Loading an obj file (with loadModel()) and then specifying the texture (with texture()) is not possible if there is no texture (in case the colors are specified in the mtl file) or if there are several images for texture…

---

## [P5js - inconsistent shader behaviour leading to program crashes](https://discourse.processing.org/t/p5js-inconsistent-shader-behaviour-leading-to-program-crashes/49386)

<div class="topic-metadata">

**Author:** [@quark](https://discourse.processing.org/u/quark)\
**Replies:** 6\
**Last updated:** [September 20, 2026, 10:33am UTC](https://discourse.processing.org/t/p5js-inconsistent-shader-behaviour-leading-to-program-crashes/49386 "2026-09-20T10:33:04Z")

</div>

Version 3 of canvasGUI (released April 2026) uses a shader to display the GUI over a webgl2 context within a p5.js sketch. This was successful and an example was created to demonstrate it. This example can be found here …

---

## [How would you change this sketch?](https://discourse.processing.org/t/how-would-you-change-this-sketch/47805)

<div class="topic-metadata">

**Author:** [@NickyDeep](https://discourse.processing.org/u/NickyDeep)\
**Replies:** 3\
**Last updated:** [September 19, 2026, 7:18pm UTC](https://discourse.processing.org/t/how-would-you-change-this-sketch/47805 "2026-09-19T19:18:44Z")

</div>

https://openprocessing.org/sketch/2857202 how would you change this sketch so that it got more interesting or funny or contrasted what would you do to it?

---

## [Problems with a shader overlaying a webgl2 canvas with a 2D image](https://discourse.processing.org/t/problems-with-a-shader-overlaying-a-webgl2-canvas-with-a-2d-image/49342)

<div class="topic-metadata">

**Author:** [@quark](https://discourse.processing.org/u/quark)\
**Replies:** 0\
**Last updated:** [September 11, 2026, 2:15pm UTC](https://discourse.processing.org/t/problems-with-a-shader-overlaying-a-webgl2-canvas-with-a-2d-image/49342 "2026-09-11T14:15:25Z")

</div>

EDIT: although the information in this discussion is accurate relevant it was based on the assumption there was a problem with the shader program used by canvasGUI. Since then I have carried out test that indicate the p…

---

## [Enable touch actions on mobile over the p5js canvas itself](https://discourse.processing.org/t/enable-touch-actions-on-mobile-over-the-p5js-canvas-itself/49199)

<div class="topic-metadata">

**Author:** [@dandan](https://discourse.processing.org/u/dandan)\
**Replies:** 2\
**Last updated:** [August 18, 2026, 7:13pm UTC](https://discourse.processing.org/t/enable-touch-actions-on-mobile-over-the-p5js-canvas-itself/49199 "2026-08-18T19:13:06Z")

</div>

Hello! I have an issue both on ios and android where all touch actions like scrolling, zooming, moving around while zoomed in, seem to be disabled when doing them over the canvas. They work fine on the outside edges. I’…

---

## [How to get the values of the current matrix (after translate, scale, rotateY...)?](https://discourse.processing.org/t/how-to-get-the-values-of-the-current-matrix-after-translate-scale-rotatey/48995)

<div class="topic-metadata">

**Author:** [@EricRogerGarcia](https://discourse.processing.org/u/EricRogerGarcia)\
**Replies:** 15\
**Last updated:** [July 28, 2026, 9:18am UTC](https://discourse.processing.org/t/how-to-get-the-values-of-the-current-matrix-after-translate-scale-rotatey/48995 "2026-07-28T09:18:07Z")

</div>

To see if I could get from it the Global position, the global scale, the global rotations x y z after using translate(), rotate x,y, z, scale()… multiple times :slight\_smile:

---

## [My beginner Number-growing code stopped working?](https://discourse.processing.org/t/my-beginner-number-growing-code-stopped-working/49033)

<div class="topic-metadata">

**Author:** [@sohelpme](https://discourse.processing.org/u/sohelpme)\
**Replies:** 3\
**Last updated:** [July 23, 2026, 3:22am UTC](https://discourse.processing.org/t/my-beginner-number-growing-code-stopped-working/49033 "2026-07-23T03:22:44Z")

</div>

hello guys, i had an artistic sketch i made that suddenly, (or around half a year ago) stopped working, and a bunch of errors that never happened are there. and here is one where it works fine p5.js Web Editor | Number…

---

## [Error: Multiple infinite loops detected. Stopping execution. at undefined:2:33088 \_ how do I resolve this?](https://discourse.processing.org/t/error-multiple-infinite-loops-detected-stopping-execution-at-undefined33088-how-do-i-resolve-this/48974)

<div class="topic-metadata">

**Author:** [@willdknyc](https://discourse.processing.org/u/willdknyc)\
**Replies:** 3\
**Last updated:** [July 8, 2026, 5:37pm UTC](https://discourse.processing.org/t/error-multiple-infinite-loops-detected-stopping-execution-at-undefined33088-how-do-i-resolve-this/48974 "2026-07-08T17:37:14Z")

</div>

\<!let img; let cnv; function preload() { img = loadImage(‘assets/IMG\_0299\_2.jpg’); } //only run once function setup() { cnv = createCanvas(img.width, img.height); let newCanvasX = (windowWidth - img.width)/2; le…

---

## [Chicago: July 2nd 6-8pm p5 workshop "Deconstructing the Image" workshop with Maddie Brucker](https://discourse.processing.org/t/chicago-july-2nd-6-8pm-p5-workshop-deconstructing-the-image-workshop-with-maddie-brucker/48849)

<div class="topic-metadata">

**Author:** [@hypergrace](https://discourse.processing.org/u/hypergrace)\
**Replies:** 0\
**Last updated:** [June 23, 2026, 4:28am UTC](https://discourse.processing.org/t/chicago-july-2nd-6-8pm-p5-workshop-deconstructing-the-image-workshop-with-maddie-brucker/48849 "2026-06-23T04:28:50Z")

</div>

Greetings Chicago p5.js community! On July 2nd from 6-8 at Mouse Arts and Letters Club in Bridgeport, CCAM: Center for Concrete and Abstract Machines and ALMANAC artist collective are hosting Maddie Brucker for a p5.js …

---

## [Fade in and fade out a sketch, or fade between sketches](https://discourse.processing.org/t/fade-in-and-fade-out-a-sketch-or-fade-between-sketches/48770)

<div class="topic-metadata">

**Author:** [@grege2](https://discourse.processing.org/u/grege2)\
**Replies:** 6\
**Last updated:** [June 9, 2026, 11:09pm UTC](https://discourse.processing.org/t/fade-in-and-fade-out-a-sketch-or-fade-between-sketches/48770 "2026-06-09T23:09:31Z")

</div>

Hi all, I’m looking for a technique in p5.js, either p5 1.x.x or p5 2.x.x, to “fade in” a moving sketch from a black screen to normal display. The converse would “fade out” the sketch, and what I’m really after is fadin…

---

## [webglVersion variable is not defined](https://discourse.processing.org/t/webglversion-variable-is-not-defined/48485)

<div class="topic-metadata">

**Author:** [@EricRogerGarcia](https://discourse.processing.org/u/EricRogerGarcia)\
**Replies:** 2\
**Last updated:** [May 5, 2026, 9:18am UTC](https://discourse.processing.org/t/webglversion-variable-is-not-defined/48485 "2026-05-05T09:18:24Z")

</div>

Hello, I tried this function setup() { createCanvas(800, 600); } function draw() { print(webglVersion); } with or without WEBGL in the createCanvas() function and I have in both cases Uncaught ReferenceError: …

---

## [Is it possible to load obj files with mtl files (it seems not to work !)?](https://discourse.processing.org/t/is-it-possible-to-load-obj-files-with-mtl-files-it-seems-not-to-work/48423)

<div class="topic-metadata">

**Author:** [@EricRogerGarcia](https://discourse.processing.org/u/EricRogerGarcia)\
**Replies:** 10\
**Last updated:** [April 28, 2026, 8:26pm UTC](https://discourse.processing.org/t/is-it-possible-to-load-obj-files-with-mtl-files-it-seems-not-to-work/48423 "2026-04-28T20:26:52Z")

</div>

Hello, I read in the documentation that loadModel() can load a obj file and use the mtl file and read the textures but it seems not to work at all. model() draws the meshes but without any textures. I’ve seen a lot of …

---

## [Video doesn't play on the canvas. I don't understand why!](https://discourse.processing.org/t/video-doesnt-play-on-the-canvas-i-dont-understand-why/48095)

<div class="topic-metadata">

**Author:** [@EricRogerGarcia](https://discourse.processing.org/u/EricRogerGarcia)\
**Replies:** 5\
**Last updated:** [March 13, 2026, 8:17am UTC](https://discourse.processing.org/t/video-doesnt-play-on-the-canvas-i-dont-understand-why/48095 "2026-03-13T08:17:16Z")

</div>

Hello, I tried this let video; function setup() { createCanvas(900, 600); video = createVideo("video.mp4"); video.hide(); video.loop(); } function draw() { background(200); image(video,10, 10); } video.m…

---

## [Convert touch events to mouse events for running sketches on iOS](https://discourse.processing.org/t/convert-touch-events-to-mouse-events-for-running-sketches-on-ios/48037)

<div class="topic-metadata">

**Author:** [@poppanona](https://discourse.processing.org/u/poppanona)\
**Replies:** 1\
**Last updated:** [March 6, 2026, 9:27am UTC](https://discourse.processing.org/t/convert-touch-events-to-mouse-events-for-running-sketches-on-ios/48037 "2026-03-06T09:27:39Z")

</div>

---

## [TypeError when accessing an Image?](https://discourse.processing.org/t/typeerror-when-accessing-an-image/47990)

<div class="topic-metadata">

**Author:** [@StormmInABottle](https://discourse.processing.org/u/StormmInABottle)\
**Replies:** 1\
**Last updated:** [February 27, 2026, 8:15pm UTC](https://discourse.processing.org/t/typeerror-when-accessing-an-image/47990 "2026-02-27T20:15:29Z")

</div>

I’m new to learning p5.js and I’m following a video right now. I’m trying to import an image but for some reason I keep getting TypeErrors: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘w…

---

## [How to know if a variable is a color?](https://discourse.processing.org/t/how-to-know-if-a-variable-is-a-color/47945)

<div class="topic-metadata">

**Author:** [@EricRogerGarcia](https://discourse.processing.org/u/EricRogerGarcia)\
**Replies:** 2\
**Last updated:** [February 23, 2026, 12:20pm UTC](https://discourse.processing.org/t/how-to-know-if-a-variable-is-a-color/47945 "2026-02-23T12:20:33Z")

</div>

(Another funny question) :upside\_down\_face: if let c=color(15,20,56) typeof c : object and c.constructor.name : nothing !!! Help! How can I check that it is indeed a color ??? This code doesn’t work obviously with…

---

## [About static methods in p5.js](https://discourse.processing.org/t/about-static-methods-in-p5-js/47909)

<div class="topic-metadata">

**Author:** [@EricRogerGarcia](https://discourse.processing.org/u/EricRogerGarcia)\
**Replies:** 2\
**Last updated:** [February 20, 2026, 7:55am UTC](https://discourse.processing.org/t/about-static-methods-in-p5-js/47909 "2026-02-20T07:55:55Z")

</div>

Hello, Is it possible to access P5js functions in a static functions ? I tried in this sketch but it doesnt work "use strict"; function setup() { createCanvas(800, 600); fill(255); } function draw() { backgro…

---

## [Overlay a 3D sketch with HUD using shaders](https://discourse.processing.org/t/overlay-a-3d-sketch-with-hud-using-shaders/47795)

<div class="topic-metadata">

**Author:** [@quark](https://discourse.processing.org/u/quark)\
**Replies:** 8\
**Last updated:** [January 27, 2026, 12:37pm UTC](https://discourse.processing.org/t/overlay-a-3d-sketch-with-hud-using-shaders/47795 "2026-01-27T12:37:40Z")

</div>

I am trying to display a 2D overlay (head-up-display) over a 3D sketch using a shader. Now I have never created a shader before but have spent the last couple of days researching and experimenting. I am very close in th…

---

## [Speed of set(x, y, color) in p5.js 2.1.2 vs 1.11.11](https://discourse.processing.org/t/speed-of-set-x-y-color-in-p5-js-2-1-2-vs-1-11-11/47769)

<div class="topic-metadata">

**Author:** [@norm\_krumpe](https://discourse.processing.org/u/norm_krumpe)\
**Replies:** 2\
**Last updated:** [January 19, 2026, 7:54pm UTC](https://discourse.processing.org/t/speed-of-set-x-y-color-in-p5-js-2-1-2-vs-1-11-11/47769 "2026-01-19T19:54:34Z")

</div>

Hello, I will be teaching a course starting next week (Mathematics and Computer Science). I typically use p5.js to teach it, and will do that again this year. I was thinking about moving up to version 2.1.2 (because it’s…

---

## [I'm trying to make a game inspired by the puzzles of The Witness](https://discourse.processing.org/t/im-trying-to-make-a-game-inspired-by-the-puzzles-of-the-witness/47747)

<div class="topic-metadata">

**Author:** [@Fluffy1oo](https://discourse.processing.org/u/Fluffy1oo)\
**Replies:** 6\
**Last updated:** [January 13, 2026, 10:22am UTC](https://discourse.processing.org/t/im-trying-to-make-a-game-inspired-by-the-puzzles-of-the-witness/47747 "2026-01-13T10:22:52Z")

</div>

from p5 import run,createCanvas,noLoop,background,stroke,line,fill,noStroke,rect,strokeWeight,noFill,ellipse,point,mouseIsPressed # DÉFINITION DES NIVEAUX LEVELS = \[ { "grid": (4, 4), # taille de l…

---

## [Wrong blending of flat elements in WEBGL mode](https://discourse.processing.org/t/wrong-blending-of-flat-elements-in-webgl-mode/47402)

<div class="topic-metadata">

**Author:** [@JuanIrache](https://discourse.processing.org/u/JuanIrache)\
**Replies:** 13\
**Last updated:** [November 13, 2025, 12:03am UTC](https://discourse.processing.org/t/wrong-blending-of-flat-elements-in-webgl-mode/47402 "2025-11-13T00:03:04Z")

</div>

Hi, When drawing text, or images, or other flat elements, the opacity of transparent areas breaks. See for example how the text behaves here if drawn before or after a series of rects (simulating fog): type-load-google…

---

## [createCapture on Android (Nokia 7.2)](https://discourse.processing.org/t/createcapture-on-android-nokia-7-2/47419)

<div class="topic-metadata">

**Author:** [@jjjochennn](https://discourse.processing.org/u/jjjochennn)\
**Replies:** 1\
**Last updated:** [October 23, 2025, 8:00am UTC](https://discourse.processing.org/t/createcapture-on-android-nokia-7-2/47419 "2025-10-23T08:00:12Z")

</div>

Hi all I have this stripped down basic code that I want to run on my Nokia 7.2 smartphone: \<!-- let capture; let options = { video: { facingMode: { exact: "environment" }, width: { ideal: 2280 }, height: …

---

## [Sketch behaves differently on macbook and raspi](https://discourse.processing.org/t/sketch-behaves-differently-on-macbook-and-raspi/47145)

<div class="topic-metadata">

**Author:** [@noahhsmith](https://discourse.processing.org/u/noahhsmith)\
**Replies:** 10\
**Last updated:** [September 17, 2025, 6:23am UTC](https://discourse.processing.org/t/sketch-behaves-differently-on-macbook-and-raspi/47145 "2025-09-17T06:23:18Z")

</div>

Hi, this sketch was created on a macbook and works fine there - decwar / galaxy · GitLab There’s a grid of white dots, and then some white squares superimposed, as shown in the pic below. On raspi, the grid of white do…

---

## [Repeatedly read a JSON file, refreshing sketch each time](https://discourse.processing.org/t/repeatedly-read-a-json-file-refreshing-sketch-each-time/47053)

<div class="topic-metadata">

**Author:** [@noahhsmith](https://discourse.processing.org/u/noahhsmith)\
**Replies:** 5\
**Last updated:** [August 31, 2025, 12:35pm UTC](https://discourse.processing.org/t/repeatedly-read-a-json-file-refreshing-sketch-each-time/47053 "2025-08-31T12:35:06Z")

</div>

Hi everyone, the ‘reading json example’ JSON is very close to what am needing. If could ‘loop’ this to repeatedly read json and refresh sketch, should have everything needed. Are there examples of such a ‘looping’ skelet…

---

## [Performance differences with POINTS between 1.11 and 2.0](https://discourse.processing.org/t/performance-differences-with-points-between-1-11-and-2-0/46959)

<div class="topic-metadata">

**Author:** [@hx2A](https://discourse.processing.org/u/hx2A)\
**Replies:** 9\
**Last updated:** [August 25, 2025, 6:02am UTC](https://discourse.processing.org/t/performance-differences-with-points-between-1-11-and-2-0/46959 "2025-08-25T06:02:06Z")

</div>

I have some questions about performance differences for POINTS shapes and related POINTS questions. Compared to 1.11, the below code is much slower in p5.js 2.0. The goal is to draw 50K points with WEBGL. (I am drawing …

---

## [My regular expression is not working](https://discourse.processing.org/t/my-regular-expression-is-not-working/47004)

<div class="topic-metadata">

**Author:** [@quark](https://discourse.processing.org/u/quark)\
**Replies:** 2\
**Last updated:** [August 21, 2025, 10:07pm UTC](https://discourse.processing.org/t/my-regular-expression-is-not-working/47004 "2025-08-21T22:07:13Z")

</div>

I am trying to parse this string to find attribute assignments \<body width="500" linegap="2" paragap="8" align="justify" font="courier new"\>' An attribute assignment is of the format name="value" where the format is …

---

## [Error when using preload() with Vite + TypeScript: “Cannot read properties of undefined (reading 'pixels')”](https://discourse.processing.org/t/error-when-using-preload-with-vite-typescript-cannot-read-properties-of-undefined-reading-pixels/46431)

<div class="topic-metadata">

**Author:** [@tomokikun](https://discourse.processing.org/u/tomokikun)\
**Replies:** 3\
**Last updated:** [June 30, 2025, 9:08am UTC](https://discourse.processing.org/t/error-when-using-preload-with-vite-typescript-cannot-read-properties-of-undefined-reading-pixels/46431 "2025-06-30T09:08:19Z")

</div>

TL;DR: I’m using p5.js with TypeScript + Vite. When I try to use preload(), I get runtime errors like: Uncaught FESError: Stopping sketch to prevent more errors Uncaught TypeError: Cannot read properties of undefined (…

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