# Coding Questions

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

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

**Page:** 41

---

## [Set drawing style in one function](https://discourse.processing.org/t/set-drawing-style-in-one-function/13254)

<div class="topic-metadata">

**Author:** [@philipplehmann](https://discourse.processing.org/u/philipplehmann)\
**Replies:** 3\
**Last updated:** [August 10, 2019, 8:30am UTC](https://discourse.processing.org/t/set-drawing-style-in-one-function/13254 "2019-08-10T08:30:05Z")

</div>

Hey there What do you guys think about the idea of a all-in-one function to set the drawing style. I created such a function as a shortcut and find it very handy. Is there already a similar behavior which i missed? D…

---

## [loadTable in constructor - check data is loaded](https://discourse.processing.org/t/loadtable-in-constructor-check-data-is-loaded/13257)

<div class="topic-metadata">

**Author:** [@gxkendall](https://discourse.processing.org/u/gxkendall)\
**Replies:** 1\
**Last updated:** [August 9, 2019, 11:24pm UTC](https://discourse.processing.org/t/loadtable-in-constructor-check-data-is-loaded/13257 "2019-08-09T23:24:25Z")

</div>

I know that you should call loadTable in preload, so that the data will will be loaded before setup is called. But I want to call loadTable in a constructor, but make sure it is loaded before continuing. I don’t have E…

---

## [Can't read pixels from capture](https://discourse.processing.org/t/cant-read-pixels-from-capture/13245)

<div class="topic-metadata">

**Author:** [@joshuajenkins](https://discourse.processing.org/u/joshuajenkins)\
**Replies:** 2\
**Last updated:** [August 8, 2019, 4:53am UTC](https://discourse.processing.org/t/cant-read-pixels-from-capture/13245 "2019-08-08T04:53:19Z")

</div>

Hi, I’m obviously missing something foundational. But at the moment I’m trying to simply get the pixels array from a video capture. My code sample follows, note this is on up-to-date versions Chrome and MacOS. let capt…

---

## [Processing alternative to inline onclick()](https://discourse.processing.org/t/processing-alternative-to-inline-onclick/13179)

<div class="topic-metadata">

**Author:** [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Replies:** 3\
**Last updated:** [August 7, 2019, 8:45pm UTC](https://discourse.processing.org/t/processing-alternative-to-inline-onclick/13179 "2019-08-07T20:45:55Z")

</div>

menu = new button({ x:menuxy\[0\]+xx, y:menuxy\[1\]+yy-10, width:190+12, height:30\*10, id:"menu", col:color(255,255,255,20), label:"", onClick: function(){ setups(); } }); This is what I am converting …

---

## [Generating a new color for each circle](https://discourse.processing.org/t/generating-a-new-color-for-each-circle/13163)

<div class="topic-metadata">

**Author:** [@epignosis567](https://discourse.processing.org/u/epignosis567)\
**Replies:** 2\
**Last updated:** [August 5, 2019, 10:37am UTC](https://discourse.processing.org/t/generating-a-new-color-for-each-circle/13163 "2019-08-05T10:37:13Z")

</div>

Hi. I have been following a tutorial and I came up with the following code. However, it’s not doing what I wanted. I would expect that everything individual circle would change a different color, but instead they’re all …

---

## [Saving image from CreateGraphics doubles resolution](https://discourse.processing.org/t/saving-image-from-creategraphics-doubles-resolution/13160)

<div class="topic-metadata">

**Author:** [@rkdnson](https://discourse.processing.org/u/rkdnson)\
**Replies:** 1\
**Last updated:** [August 4, 2019, 12:37am UTC](https://discourse.processing.org/t/saving-image-from-creategraphics-doubles-resolution/13160 "2019-08-04T00:37:41Z")

</div>

Hello! I am working on a bit of code, and have recently put in the createGraphics() function. When saving the image created by createGraphics, my resolution is doubled. print(graphics.width); //gives me 800 - the corre…

---

## [How to light a vertex](https://discourse.processing.org/t/how-to-light-a-vertex/13148)

<div class="topic-metadata">

**Author:** [@lofi](https://discourse.processing.org/u/lofi)\
**Replies:** 2\
**Last updated:** [August 3, 2019, 9:54am UTC](https://discourse.processing.org/t/how-to-light-a-vertex/13148 "2019-08-03T09:54:53Z")

</div>

I’m trying to make little “hills” and was hoping to light them up. I’m using sets of vertexes but cant get light to act on them. I can make light work on a sphere or a box, but not my shapes made with vertexes. I feel l…

---

## [Tank Controls Help](https://discourse.processing.org/t/tank-controls-help/13043)

<div class="topic-metadata">

**Author:** [@Samira](https://discourse.processing.org/u/Samira)\
**Replies:** 4\
**Last updated:** [July 29, 2019, 9:17pm UTC](https://discourse.processing.org/t/tank-controls-help/13043 "2019-07-29T21:17:47Z")

</div>

I’m creating a tank for a game I am making. I want the tank to move in the direction it is facing. How can I do that?

---

## [Translation from Processing to p5 not working](https://discourse.processing.org/t/translation-from-processing-to-p5-not-working/13051)

<div class="topic-metadata">

**Author:** [@SheCurvesMobius](https://discourse.processing.org/u/SheCurvesMobius)\
**Replies:** 2\
**Last updated:** [July 29, 2019, 7:22pm UTC](https://discourse.processing.org/t/translation-from-processing-to-p5-not-working/13051 "2019-07-29T19:22:14Z")

</div>

Hi all, I can’t figure out why this isn’t spinning. Any tips? (It works in Processing). var spin; function setup() { createCanvas(400, 400); background(255); } function draw() { } function mouseDragged() { push…

---

## [3D mode creating an offset](https://discourse.processing.org/t/3d-mode-creating-an-offset/13042)

<div class="topic-metadata">

**Author:** [@SheCurvesMobius](https://discourse.processing.org/u/SheCurvesMobius)\
**Replies:** 2\
**Last updated:** [July 29, 2019, 5:24pm UTC](https://discourse.processing.org/t/3d-mode-creating-an-offset/13042 "2019-07-29T17:24:00Z")

</div>

Hello, I’m wondering if anyone can let me know why the rectangle is offset from the mouse by about 300px in the x and y direction? here’s the code: var angle = 0; function setup() { createCanvas(700, 700, WEBGL); …

---

## [Prevent p5.dom.js input widget generating keyPressed() events](https://discourse.processing.org/t/prevent-p5-dom-js-input-widget-generating-keypressed-events/13019)

<div class="topic-metadata">

**Author:** [@grege2](https://discourse.processing.org/u/grege2)\
**Replies:** 3\
**Last updated:** [July 28, 2019, 11:44pm UTC](https://discourse.processing.org/t/prevent-p5-dom-js-input-widget-generating-keypressed-events/13019 "2019-07-28T23:44:35Z")

</div>

Ciao tutti. I’m using a p5.dom.js “input” widget to get some text input, but each character entered generates a call to keyPressed(). I only want to action the input when CR is typed at the end. Example at: https://edito…

---

## [Move inside div and center on div not page](https://discourse.processing.org/t/move-inside-div-and-center-on-div-not-page/13024)

<div class="topic-metadata">

**Author:** [@nicolas\_nqn](https://discourse.processing.org/u/nicolas_nqn)\
**Replies:** 1\
**Last updated:** [July 28, 2019, 5:06pm UTC](https://discourse.processing.org/t/move-inside-div-and-center-on-div-not-page/13024 "2019-07-28T17:06:02Z")

</div>

Hi, i know how to move the canvas inside the div with .parent, but i cant seem to position the canvas centered on the div, when i use .position it uses the page coordinates not the div var offsets = document.getElementB…

---

## [Duplicating a canvas and its state](https://discourse.processing.org/t/duplicating-a-canvas-and-its-state/12902)

<div class="topic-metadata">

**Author:** [@hoticewater](https://discourse.processing.org/u/hoticewater)\
**Replies:** 3\
**Last updated:** [July 28, 2019, 12:47am UTC](https://discourse.processing.org/t/duplicating-a-canvas-and-its-state/12902 "2019-07-28T00:47:02Z")

</div>

I’ve been searching for this answer for longer than I care to admit, and after many google searches and many hours of skipping around The Coding Train’s innumerous videos I’ve felt close but have yet to find the answer. …

---

## [Smooth scrollIntoView?](https://discourse.processing.org/t/smooth-scrollintoview/13010)

<div class="topic-metadata">

**Author:** [@pastuh](https://discourse.processing.org/u/pastuh)\
**Replies:** 0\
**Last updated:** [July 26, 2019, 11:20pm UTC](https://discourse.processing.org/t/smooth-scrollintoview/13010 "2019-07-26T23:20:35Z")

</div>

I want to move slowly in to element view. Code: let testSelect = document.getElementById('gridMarked'); testSelect.scrollIntoView({block: 'center'}); But view moves immediately, additional ‘Smooth’ option not works…

---

## [Sending Values Between Functions](https://discourse.processing.org/t/sending-values-between-functions/12927)

<div class="topic-metadata">

**Author:** [@shodai](https://discourse.processing.org/u/shodai)\
**Replies:** 2\
**Last updated:** [July 23, 2019, 8:13pm UTC](https://discourse.processing.org/t/sending-values-between-functions/12927 "2019-07-23T20:13:19Z")

</div>

I am trying to use the p5js.gui library to collect a simple text input and then just output that input to the screen. I have tried a number of different approaches but keep running into errors. This is what I have so far…

---

## [How to add a tooltip to a p5.dom.js button](https://discourse.processing.org/t/how-to-add-a-tooltip-to-a-p5-dom-js-button/12758)

<div class="topic-metadata">

**Author:** [@grege2](https://discourse.processing.org/u/grege2)\
**Replies:** 5\
**Last updated:** [July 18, 2019, 12:01am UTC](https://discourse.processing.org/t/how-to-add-a-tooltip-to-a-p5-dom-js-button/12758 "2019-07-18T00:01:23Z")

</div>

Hi all. I’d like to add a “tooltip” to a button in a p5.js code. The button is added with createButton() from the p5.dom.js library. There’s a ton of discussion out there, a lot in Stack Overflow, about tooltips … a typi…

---

## [Loop(), noLoop(), redraw()](https://discourse.processing.org/t/loop-noloop-redraw/12534)

<div class="topic-metadata">

**Author:** [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Replies:** 5\
**Last updated:** [July 16, 2019, 2:11pm UTC](https://discourse.processing.org/t/loop-noloop-redraw/12534 "2019-07-16T14:11:12Z")

</div>

Having read the documentation on the p5.js site, I’m still a little confused as to how to use the redraw() function and the loop function. What I’m trying to achieve is something which allows me to stop the draw function…

---

## [Draw a line from center to mouse with vector](https://discourse.processing.org/t/draw-a-line-from-center-to-mouse-with-vector/12729)

<div class="topic-metadata">

**Author:** [@Erjaeger](https://discourse.processing.org/u/Erjaeger)\
**Replies:** 5\
**Last updated:** [July 16, 2019, 9:53am UTC](https://discourse.processing.org/t/draw-a-line-from-center-to-mouse-with-vector/12729 "2019-07-16T09:53:25Z")

</div>

Hi everyone, I’m reading The Nature of Code but I stuck with a stupid question on vector. I tried to make a line drawn from the center of the screen to my mouse with the help of vectors. Here : https://editor.p5js.org…

---

## [Merge/ blend p5.Image or base64 image](https://discourse.processing.org/t/merge-blend-p5-image-or-base64-image/12699)

<div class="topic-metadata">

**Author:** [@josebv](https://discourse.processing.org/u/josebv)\
**Replies:** 2\
**Last updated:** [July 15, 2019, 12:02pm UTC](https://discourse.processing.org/t/merge-blend-p5-image-or-base64-image/12699 "2019-07-15T12:02:57Z")

</div>

Hi, im currently working on a paint-like project. right now I have 3 p5.images: \*template // this is kinda of legal notepad \*doodles // a canvas were I draw \*oldDoodles // old doodles that I get from my database is …

---

## [How can i color or texture each faces of a loaded .obj file?](https://discourse.processing.org/t/how-can-i-color-or-texture-each-faces-of-a-loaded-obj-file/12688)

<div class="topic-metadata">

**Author:** [@mraposka](https://discourse.processing.org/u/mraposka)\
**Replies:** 1\
**Last updated:** [July 14, 2019, 3:49pm UTC](https://discourse.processing.org/t/how-can-i-color-or-texture-each-faces-of-a-loaded-obj-file/12688 "2019-07-14T15:49:08Z")

</div>

I’m doing a 3D object texturing and coloring website. (For example a kitchen set. I want to change color or texture the kitchen cupboards, marble and fridge.) I’m loading the 3d kitchen set model on website. Customer sho…

---

## [How can I not draw on top of something](https://discourse.processing.org/t/how-can-i-not-draw-on-top-of-something/10793)

<div class="topic-metadata">

**Author:** [@josebv](https://discourse.processing.org/u/josebv)\
**Replies:** 18\
**Last updated:** [July 14, 2019, 12:22pm UTC](https://discourse.processing.org/t/how-can-i-not-draw-on-top-of-something/10793 "2019-07-14T12:22:22Z")

</div>

I’m trying to program something for my cs class. I want to make a program that I can use to write notes with my Wacom tablet. the problem is that I don’t know how not draw things on top of each other. when I erased so…

---

## [Creating and Populating a Table From Scratch](https://discourse.processing.org/t/creating-and-populating-a-table-from-scratch/12658)

<div class="topic-metadata">

**Author:** [@hbtousa](https://discourse.processing.org/u/hbtousa)\
**Replies:** 11\
**Last updated:** [July 12, 2019, 4:13am UTC](https://discourse.processing.org/t/creating-and-populating-a-table-from-scratch/12658 "2019-07-12T04:13:55Z")

</div>

Hello everyone. Completely new to P5JS. I am trying to create a table and populate it with data already collected by the same code.The table will have three columns: name, position\_x, and position\_y. The code below didn…

---

## [Getting a strange error while using shader](https://discourse.processing.org/t/getting-a-strange-error-while-using-shader/12522)

<div class="topic-metadata">

**Author:** [@Sudev](https://discourse.processing.org/u/Sudev)\
**Replies:** 5\
**Last updated:** [July 11, 2019, 4:32pm UTC](https://discourse.processing.org/t/getting-a-strange-error-while-using-shader/12522 "2019-07-11T16:32:29Z")

</div>

Am getting a very strange error when I use shader in my sketch. Uncaught TypeError: Cannot read property 'isP3D' of undefined (sketch: line 5) and this is the code let img; function preload(){ img = loadImage('htt…

---

## [Make class get all functions of p5.js](https://discourse.processing.org/t/make-class-get-all-functions-of-p5-js/12558)

<div class="topic-metadata">

**Author:** [@Choky](https://discourse.processing.org/u/Choky)\
**Replies:** 1\
**Last updated:** [July 9, 2019, 7:10am UTC](https://discourse.processing.org/t/make-class-get-all-functions-of-p5-js/12558 "2019-07-09T07:10:23Z")

</div>

When creating a class I cannot make it so the class gets all the functions of p5.js library. Can anyone help me? it says fill is not defined code : var game = function(g) { g.setup = function() { g.createCanvas(…

---

## [Coding problem(character Animation Program)](https://discourse.processing.org/t/coding-problem-character-animation-program/12598)

<div class="topic-metadata">

**Author:** [@megarou](https://discourse.processing.org/u/megarou)\
**Replies:** 1\
**Last updated:** [July 9, 2019, 1:03am UTC](https://discourse.processing.org/t/coding-problem-character-animation-program/12598 "2019-07-09T01:03:46Z")

</div>

Hello there, i’m facing a some kind of coding problem?!!, the problem is, i’ve loaded some images of a character to animate, i’ve succeeded to animate the first loaded images of the character, but i couldn’t know how to …

---

## [Change Font Weight in p5](https://discourse.processing.org/t/change-font-weight-in-p5/12514)

<div class="topic-metadata">

**Author:** [@redmoncoreyl](https://discourse.processing.org/u/redmoncoreyl)\
**Replies:** 3\
**Last updated:** [July 5, 2019, 3:20am UTC](https://discourse.processing.org/t/change-font-weight-in-p5/12514 "2019-07-05T03:20:43Z")

</div>

I want to have a p5 sketch with the same font but multiple weights. In my index.html I have the following line: \<link href="https://fonts.googleapis.com/css?family=Montserrat:400,800&display=swap" rel="stylesheet"\> In …

---

## [(p5js) how can i structure an if then statement so that a few but not all conditions are met?](https://discourse.processing.org/t/p5js-how-can-i-structure-an-if-then-statement-so-that-a-few-but-not-all-conditions-are-met/12394)

<div class="topic-metadata">

**Author:** [@cryptacritic](https://discourse.processing.org/u/cryptacritic)\
**Replies:** 10\
**Last updated:** [July 5, 2019, 2:24am UTC](https://discourse.processing.org/t/p5js-how-can-i-structure-an-if-then-statement-so-that-a-few-but-not-all-conditions-are-met/12394 "2019-07-05T02:24:56Z")

</div>

Imagine you have ten boolean (or otherwise) variables. You want three of the ten variables to be true, but no more than 3, and no less. You do not want to create a complicated nested if-then function that requires writin…

---

## [Strange behavior from a sketch](https://discourse.processing.org/t/strange-behavior-from-a-sketch/12492)

<div class="topic-metadata">

**Author:** [@rbytes](https://discourse.processing.org/u/rbytes)\
**Replies:** 7\
**Last updated:** [July 4, 2019, 10:09pm UTC](https://discourse.processing.org/t/strange-behavior-from-a-sketch/12492 "2019-07-04T22:09:30Z")

</div>

I recently translated this sketch, Dynafractal, to P5.js from another language (Smart Basic, if anyone is familiar with it.) My code runs fine, and the final output looks exactly like it did in Smart Basic, but it doe…

---

## [\[SOLVED\] Ordering items on canvas](https://discourse.processing.org/t/solved-ordering-items-on-canvas/12421)

<div class="topic-metadata">

**Author:** [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Replies:** 6\
**Last updated:** [July 4, 2019, 7:24pm UTC](https://discourse.processing.org/t/solved-ordering-items-on-canvas/12421 "2019-07-04T19:24:30Z")

</div>

Hi, I’m having trouble ordering drawn items on canvas, I’m looking to draw the path and the info table on top of the fill, however this is causing some issues. This is the function which draws, the items on canvas, f…

---

## [Zooming in on specific point. (Translate and scale)](https://discourse.processing.org/t/zooming-in-on-specific-point-translate-and-scale/12310)

<div class="topic-metadata">

**Author:** [@Kiwipai](https://discourse.processing.org/u/Kiwipai)\
**Replies:** 5\
**Last updated:** [July 3, 2019, 4:36am UTC](https://discourse.processing.org/t/zooming-in-on-specific-point-translate-and-scale/12310 "2019-07-03T04:36:12Z")

</div>

So I’m fairly new to graphical programming and I’m stuck at something that I’m guessing has a simple solution. I want to make some lines out of points and then translate and scale so that my lines will be visible no mat…

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

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