# Coding Questions

**URL:** https://discourse.processing.org/c/processing/processing-questions/15.md?page=42

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

**Page:** 43

---

## [How to combine mousePressed function with "dist();" in Processing 3?](https://discourse.processing.org/t/how-to-combine-mousepressed-function-with-dist-in-processing-3/32713)

<div class="topic-metadata">

**Author:** [@sebest\_design](https://discourse.processing.org/u/sebest_design)\
**Replies:** 2\
**Last updated:** [October 10, 2021, 7:59am UTC](https://discourse.processing.org/t/how-to-combine-mousepressed-function-with-dist-in-processing-3/32713 "2021-10-10T07:59:02Z")

</div>

Hello. I am working on a school project. I am trying to control the radius value of 3 ellipses using the mousePressed function and the “dist()” thingy. //references float popDRed = dist(balloonRedX, balloonRedY, mouseX,…

---

## [Need help with classes and passing variables!](https://discourse.processing.org/t/need-help-with-classes-and-passing-variables/934)

<div class="topic-metadata">

**Author:** [@brianna0811](https://discourse.processing.org/u/brianna0811)\
**Replies:** 11\
**Last updated:** [October 5, 2018, 9:13pm UTC](https://discourse.processing.org/t/need-help-with-classes-and-passing-variables/934 "2018-10-05T21:13:33Z")

</div>

Hello all! I’m making a game where the player moves a character left and right and it touches candies. I have three classes - game, candy and player. In the player class - touchCandy() method, it says that some of the v…

---

## [Is there a way to avoid collisions? E.g. 20 circles that don’t overlap](https://discourse.processing.org/t/is-there-a-way-to-avoid-collisions-e-g-20-circles-that-don-t-overlap/32695)

<div class="topic-metadata">

**Author:** [@GoodJuJu](https://discourse.processing.org/u/GoodJuJu)\
**Replies:** 12\
**Last updated:** [October 9, 2021, 11:14am UTC](https://discourse.processing.org/t/is-there-a-way-to-avoid-collisions-e-g-20-circles-that-don-t-overlap/32695 "2021-10-09T11:14:21Z")

</div>

I am just starting out with processing. I wondered if there was a way to prevent ‘collisions‘? For example, I would like to have 20 circles on a canvas and ensure that none of them overlap or touch each other. Is this…

---

## [Fibonacci Numbers in Java - \`O(n)\` time and \`O(1)\` space complexity and without using Recursion](https://discourse.processing.org/t/fibonacci-numbers-in-java-o-n-time-and-o-1-space-complexity-and-without-using-recursion/32694)

<div class="topic-metadata">

**Author:** [@panahur](https://discourse.processing.org/u/panahur)\
**Replies:** 3\
**Last updated:** [October 9, 2021, 12:29am UTC](https://discourse.processing.org/t/fibonacci-numbers-in-java-o-n-time-and-o-1-space-complexity-and-without-using-recursion/32694 "2021-10-09T00:29:01Z")

</div>

How can I get the N-th Fibonacci number with O(n) time and O(1) space complexity. How to calculate Fibonacci numbers without Recursion or Iteration? This is the code that I took from here, using Recursion with Me…

---

## [Is it possible to have the reflect of light of facet ball? (Disco ball)](https://discourse.processing.org/t/is-it-possible-to-have-the-reflect-of-light-of-facet-ball-disco-ball/32532)

<div class="topic-metadata">

**Author:** [@bking](https://discourse.processing.org/u/bking)\
**Replies:** 2\
**Last updated:** [October 8, 2021, 8:22pm UTC](https://discourse.processing.org/t/is-it-possible-to-have-the-reflect-of-light-of-facet-ball-disco-ball/32532 "2021-10-08T20:22:49Z")

</div>

Hello, I made a program with two balls which returns the light coming from different place thanks to the mouse. I would like to change these balls into a mirror ball (like in clubs) and have the rays of light returned …

---

## [How to keep a square shape from blinking when spacebar is pressed](https://discourse.processing.org/t/how-to-keep-a-square-shape-from-blinking-when-spacebar-is-pressed/32683)

<div class="topic-metadata">

**Author:** [@newtothis](https://discourse.processing.org/u/newtothis)\
**Replies:** 1\
**Last updated:** [October 8, 2021, 5:33am UTC](https://discourse.processing.org/t/how-to-keep-a-square-shape-from-blinking-when-spacebar-is-pressed/32683 "2021-10-08T05:33:30Z")

</div>

int iArray\[\]=new int\[1000\]; int iIndex=0,iMax=25,iBeat=0; //\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* void setup() //\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*…

---

## [surface.setResizable(false); doesn't work in the P2D renderer](https://discourse.processing.org/t/surface-setresizable-false-doesnt-work-in-the-p2d-renderer/32620)

<div class="topic-metadata">

**Author:** [@s31](https://discourse.processing.org/u/s31)\
**Replies:** 1\
**Last updated:** [October 7, 2021, 4:10pm UTC](https://discourse.processing.org/t/surface-setresizable-false-doesnt-work-in-the-p2d-renderer/32620 "2021-10-07T16:10:26Z")

</div>

Hello, I have been trying to use the built-in surface.setResizable function to disable the option to resize the processing sketch window in my sketches. However, when I attempt to use this method with the P2D renderer i…

---

## [How to make a mirror ball? like in a nightclub](https://discourse.processing.org/t/how-to-make-a-mirror-ball-like-in-a-nightclub/32667)

<div class="topic-metadata">

**Author:** [@bking](https://discourse.processing.org/u/bking)\
**Replies:** 5\
**Last updated:** [October 7, 2021, 2:54pm UTC](https://discourse.processing.org/t/how-to-make-a-mirror-ball-like-in-a-nightclub/32667 "2021-10-07T14:54:07Z")

</div>

Hello everyone, For now in my project, I move spheres like pendulums or metronomes. Now instead of spheres, I would like to have mirror balls. Is it easy to create a mirror ball? Later, I would like to light it with …

---

## [Basic loadStrings() Question](https://discourse.processing.org/t/basic-loadstrings-question/32663)

<div class="topic-metadata">

**Author:** [@dtools22](https://discourse.processing.org/u/dtools22)\
**Replies:** 5\
**Last updated:** [October 7, 2021, 12:04pm UTC](https://discourse.processing.org/t/basic-loadstrings-question/32663 "2021-10-07T12:04:45Z")

</div>

Hello all, So I’m messing around with some data and I came across an issue. I would like to get the table from the following URL However the following code produces an error. Table testtable; void setup(){ testta…

---

## [Hello, some question from a beginner (drip effect)](https://discourse.processing.org/t/hello-some-question-from-a-beginner-drip-effect/32041)

<div class="topic-metadata">

**Author:** [@asacool](https://discourse.processing.org/u/asacool)\
**Replies:** 14\
**Last updated:** [October 7, 2021, 9:30am UTC](https://discourse.processing.org/t/hello-some-question-from-a-beginner-drip-effect/32041 "2021-10-07T09:30:04Z")

</div>

Hi, I want to do spray paint effect,but how to cancel the point of the drip effect? (just want only "line "drip) sorry,I just the beginner. thanks!! my code: final int maxIterations = 20; // float x=0; float y=0; …

---

## [Using PShader and GLSL to make swaying grass](https://discourse.processing.org/t/using-pshader-and-glsl-to-make-swaying-grass/32666)

<div class="topic-metadata">

**Author:** [@Vertexia](https://discourse.processing.org/u/Vertexia)\
**Replies:** 5\
**Last updated:** [October 7, 2021, 6:45am UTC](https://discourse.processing.org/t/using-pshader-and-glsl-to-make-swaying-grass/32666 "2021-10-07T06:45:23Z")

</div>

I’m trying to add swaying grass using both a vector and a fragment shader in a 2d game, and I’m up to the point where i need to add the image to the fragment shader. Right now I’m using image() to render the image, but t…

---

## [Trying to make objects move away from cursor](https://discourse.processing.org/t/trying-to-make-objects-move-away-from-cursor/27915)

<div class="topic-metadata">

**Author:** [@spamelim](https://discourse.processing.org/u/spamelim)\
**Replies:** 10\
**Last updated:** [October 6, 2021, 12:29pm UTC](https://discourse.processing.org/t/trying-to-make-objects-move-away-from-cursor/27915 "2021-10-06T12:29:28Z")

</div>

I have a class called ball and I’m creating 100 ellipses using an array and for loop in main. My goal is to make them all move away from the cursor and so far this is what I have: void cursor() { if(dist(x,y,mouse…

---

## [Creating voronoi patterns](https://discourse.processing.org/t/creating-voronoi-patterns/14635)

<div class="topic-metadata">

**Author:** [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Replies:** 16\
**Last updated:** [October 6, 2021, 10:34am UTC](https://discourse.processing.org/t/creating-voronoi-patterns/14635 "2021-10-06T10:34:01Z")

</div>

Hi again everyone, I’m trying to code a program to generate voronoi diagrams, however I’m having issues generating the function that draws arcs in between each line. Voronoi generation is supposed to produce this type …

---

## [Pick Random Number Based on Preceding Number](https://discourse.processing.org/t/pick-random-number-based-on-preceding-number/32558)

<div class="topic-metadata">

**Author:** [@alenmartel](https://discourse.processing.org/u/alenmartel)\
**Replies:** 12\
**Last updated:** [October 3, 2021, 11:40am UTC](https://discourse.processing.org/t/pick-random-number-based-on-preceding-number/32558 "2021-10-03T11:40:56Z")

</div>

Good morning all; I’m trying to write a random number generator that generates twelve different random numbers and displays them in a column. However, what random number can follow each other one is limited to certain n…

---

## [Why isn't the box in the center of the screen?](https://discourse.processing.org/t/why-isnt-the-box-in-the-center-of-the-screen/32580)

<div class="topic-metadata">

**Author:** [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)\
**Replies:** 10\
**Last updated:** [October 5, 2021, 1:50pm UTC](https://discourse.processing.org/t/why-isnt-the-box-in-the-center-of-the-screen/32580 "2021-10-05T13:50:02Z")

</div>

float x=height/2; float y=width/2; float z=0; void setup(){ size(400,400,P3D); } void draw(){ print(x,y,z); background(255); translate(x, y, z); noFill(); box(160); print(z); z++; }

---

## [A Processing Quine](https://discourse.processing.org/t/a-processing-quine/31332)

<div class="topic-metadata">

**Author:** [@TomD](https://discourse.processing.org/u/TomD)\
**Replies:** 16\
**Last updated:** [October 5, 2021, 1:29pm UTC](https://discourse.processing.org/t/a-processing-quine/31332 "2021-10-05T13:29:20Z")

</div>

Hi There, Earlier I made a Quine in Processing, that is code that prints it’s source code without any input. It works, it prints to the canvas what I can see in the text editor. I am wondering if anyone can see any fu…

---

## [Use a fragment and vertex shader through GL4](https://discourse.processing.org/t/use-a-fragment-and-vertex-shader-through-gl4/32585)

<div class="topic-metadata">

**Author:** [@honeyjar](https://discourse.processing.org/u/honeyjar)\
**Replies:** 1\
**Last updated:** [October 5, 2021, 8:46am UTC](https://discourse.processing.org/t/use-a-fragment-and-vertex-shader-through-gl4/32585 "2021-10-05T08:46:01Z")

</div>

I’m attempting to set up a fragment and vertex shader where the vertex shader outputs a quad that covers the entire screen and the fragment shader draws a signed distance function on it. I know that you can attach fragm…

---

## [How to have all platforms stay?](https://discourse.processing.org/t/how-to-have-all-platforms-stay/32610)

<div class="topic-metadata">

**Author:** [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)\
**Replies:** 2\
**Last updated:** [October 4, 2021, 9:33pm UTC](https://discourse.processing.org/t/how-to-have-all-platforms-stay/32610 "2021-10-04T21:33:47Z")

</div>

how to have all of the platforms stay visible? //visual PImage shrek; boolean invert= false; PImage\[\] soldier= new PImage\[3\]; platform platform; //timer //moving float charx=0; float chary=563-100; boolean jumping= fal…

---

## [Why is the bullet not shooting?](https://discourse.processing.org/t/why-is-the-bullet-not-shooting/32613)

<div class="topic-metadata">

**Author:** [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)\
**Replies:** 3\
**Last updated:** [October 4, 2021, 9:29pm UTC](https://discourse.processing.org/t/why-is-the-bullet-not-shooting/32613 "2021-10-04T21:29:40Z")

</div>

why is the bullet not shooting/ //visual PImage shrek; boolean invert= false; boolean shooting; PImage\[\] soldier= new PImage\[3\]; PImage crosseye; PImage nocrosseye; PImage eyebot; PImage heart; //timer //moving float…

---

## [Not shooting when inverted and eyebot not dissapearing](https://discourse.processing.org/t/not-shooting-when-inverted-and-eyebot-not-dissapearing/32615)

<div class="topic-metadata">

**Author:** [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)\
**Replies:** 0\
**Last updated:** [October 4, 2021, 8:30pm UTC](https://discourse.processing.org/t/not-shooting-when-inverted-and-eyebot-not-dissapearing/32615 "2021-10-04T20:30:57Z")

</div>

why can I not shoot when the screen is inverted? //visual PImage shrek; boolean invert= false; boolean shooting; PImage\[\] soldier= new PImage\[3\]; PImage crosseye; PImage nocrosseye; PImage eyebot; PImage heart; //time…

---

## [Help with improving my rect-rect collision detection](https://discourse.processing.org/t/help-with-improving-my-rect-rect-collision-detection/32609)

<div class="topic-metadata">

**Author:** [@Kenga123456](https://discourse.processing.org/u/Kenga123456)\
**Replies:** 1\
**Last updated:** [October 4, 2021, 5:21pm UTC](https://discourse.processing.org/t/help-with-improving-my-rect-rect-collision-detection/32609 "2021-10-04T17:21:30Z")

</div>

int ellipseRadius = 40; int r = 0; int b = 0; int g = 0; int rectPowerShowSize = 1; float xVel = 1; float yVel = 1; //images pImage img; void setup() { size(800, 400); background(0); frameRate(60); img = loadIm…

---

## [Collision Detection with Bullet](https://discourse.processing.org/t/collision-detection-with-bullet/32557)

<div class="topic-metadata">

**Author:** [@MarkShaker](https://discourse.processing.org/u/MarkShaker)\
**Replies:** 4\
**Last updated:** [October 4, 2021, 7:32am UTC](https://discourse.processing.org/t/collision-detection-with-bullet/32557 "2021-10-04T07:32:40Z")

</div>

Hi everyone, I’m unsure on how to code collision detection in processing. I get the overall idea of how it works and have watched tutorials on YouTube however they mainly show collision detection in terms of changing col…

---

## [Repositioning my bird character](https://discourse.processing.org/t/repositioning-my-bird-character/32529)

<div class="topic-metadata">

**Author:** [@CharrR](https://discourse.processing.org/u/CharrR)\
**Replies:** 6\
**Last updated:** [October 4, 2021, 5:12am UTC](https://discourse.processing.org/t/repositioning-my-bird-character/32529 "2021-10-04T05:12:16Z")

</div>

Hi all, I’m new to processing and I’m sorta stuck. I made a bird character and I want to make a duplicate right beside it without having to re-enter and adjust all the codes. I’m also a bit confused by the “translate” fu…

---

## [How to stop the ball from moving when no key is beying pressed?](https://discourse.processing.org/t/how-to-stop-the-ball-from-moving-when-no-key-is-beying-pressed/32559)

<div class="topic-metadata">

**Author:** [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)\
**Replies:** 4\
**Last updated:** [October 3, 2021, 9:07pm UTC](https://discourse.processing.org/t/how-to-stop-the-ball-from-moving-when-no-key-is-beying-pressed/32559 "2021-10-03T21:07:24Z")

</div>

how to stop the ellipse from moving when no key is being pressed? PImage shrek; float charx=0; float chary=0; boolean invert= false; void setup() { size(600, 500); shrek= loadImage("shrek.jpg"); chary= height/2; …

---

## [Change variable alternatingly](https://discourse.processing.org/t/change-variable-alternatingly/32230)

<div class="topic-metadata">

**Author:** [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)\
**Replies:** 8\
**Last updated:** [October 2, 2021, 9:30am UTC](https://discourse.processing.org/t/change-variable-alternatingly/32230 "2021-10-02T09:30:57Z")

</div>

how to change i to 2 every couple of seconds/frames and then back direction\[1\]= loadImage("left.png"); direction\[2\]= loadImage("right.png"); i; void setup(){ fullScreen(); } void draw(){ image(direction\[i\], image…

---

## [Stop ball less abruptly](https://discourse.processing.org/t/stop-ball-less-abruptly/32572)

<div class="topic-metadata">

**Author:** [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)\
**Replies:** 2\
**Last updated:** [October 3, 2021, 11:06am UTC](https://discourse.processing.org/t/stop-ball-less-abruptly/32572 "2021-10-03T11:06:22Z")

</div>

if you press space the ellipse jumps, but it stops very abruptly how can i slow it down instead? //visual PImage shrek; boolean invert= false; //timer //moving float charx=0; float chary=563-25; boolean jumping= false;…

---

## [Why does my program return the error, RuntimeException: Too many popStyle() without enough pushStyle()?](https://discourse.processing.org/t/why-does-my-program-return-the-error-runtimeexception-too-many-popstyle-without-enough-pushstyle/32560)

<div class="topic-metadata">

**Author:** [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)\
**Replies:** 3\
**Last updated:** [October 2, 2021, 1:27pm UTC](https://discourse.processing.org/t/why-does-my-program-return-the-error-runtimeexception-too-many-popstyle-without-enough-pushstyle/32560 "2021-10-02T13:27:59Z")

</div>

why does my program return the error, RuntimeException: Too many popStyle() without enough pushStyle()? i have the same amount of pop as i do push (I want to have the screen be inverted, and go back to normal every fiv…

---

## [Subtracting a 3D Sphere from a 3D Cube tutorials](https://discourse.processing.org/t/subtracting-a-3d-sphere-from-a-3d-cube-tutorials/32509)

<div class="topic-metadata">

**Author:** [@garyion](https://discourse.processing.org/u/garyion)\
**Replies:** 2\
**Last updated:** [October 1, 2021, 6:03am UTC](https://discourse.processing.org/t/subtracting-a-3d-sphere-from-a-3d-cube-tutorials/32509 "2021-10-01T06:03:49Z")

</div>

Hi, I am looking for a tutorial to subtract a 3D sphere shape from 3D cube similar to https://www.gograph.com/clipart/subtraction-of-cube-and-sphere-gg66311482.html thanks

---

## [Loading font from data folder in a second window](https://discourse.processing.org/t/loading-font-from-data-folder-in-a-second-window/32517)

<div class="topic-metadata">

**Author:** [@DonaldZhu](https://discourse.processing.org/u/DonaldZhu)\
**Replies:** 3\
**Last updated:** [October 1, 2021, 4:29am UTC](https://discourse.processing.org/t/loading-font-from-data-folder-in-a-second-window/32517 "2021-10-01T04:29:51Z")

</div>

The following code create two windows when my sketch is run: Main file: PWindow pwindow; PFont font; void setup() { size(800, 800); pwindow = new PWindow(); } Second file: class PWindow extends PApplet { PWind…

---

## [How can I turn an image or svg into Basic Shapes?](https://discourse.processing.org/t/how-can-i-turn-an-image-or-svg-into-basic-shapes/32465)

<div class="topic-metadata">

**Author:** [@Violet](https://discourse.processing.org/u/Violet)\
**Replies:** 1\
**Last updated:** [September 30, 2021, 11:53am UTC](https://discourse.processing.org/t/how-can-i-turn-an-image-or-svg-into-basic-shapes/32465 "2021-09-30T11:53:16Z")

</div>

How to intelligently recognize graphics and extract the outer contour of the icon, especially the third change in the figure. I can’t do it with my current level of knowledge, so I would like to ask if processing can…

[Previous page](https://discourse.processing.org/c/processing/processing-questions/15.md?page=41)

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