# Calling different draw functions

**URL:** <https://discourse.processing.org/t/calling-different-draw-functions/31709>\
**Category:** Coding Questions\
**Created:** [August 13, 2021, 10:31am UTC](https://discourse.processing.org/t/calling-different-draw-functions/31709 "2021-08-13T10:31:56Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![odecode](https://avatars.discourse-cdn.com/v4/letter/o/a8b319/32.png) [@odecode](https://discourse.processing.org/u/odecode)\
**Post date:** [August 13, 2021, 10:31am UTC](https://discourse.processing.org/t/calling-different-draw-functions/31709/1 "2021-08-13T10:31:56Z")

</div>

Hello! I followed TheCodingTrain’s youtube video for the Rubik’s cube, and am now adding some functionality which I need help with. I am using java mode. I created a simple solver (brute force), and now I want to create a visualizer that shows how the solver searches the tree of possible solutions. I need some help to get me started with the drawing code.

what I have is something like this:  
class Cube{ methods for turning cube}  
class Solver {  
takes Cube → constructs tree → searches tree for solution  
// i want to add a drawTree() function that draws each step of creating and searching the tree, the  
// algorithm for drawing I can try and figure out  
}

void draw(){  
if(boolean solving==true){  
solver.drawTree();  
}

else drawCube();  
}

I don’t know how to make it draw() interact with solver.drawTree();. I made so that when I press button to start solving (creating the tree), i then call drawTree(); manually from inside the solver and it enters the drawTree function, but it isnt drawing anything from there and the cube stays on the screen. Other thing I tried is when I press button → set solving = true, then start solving. But the draw() never checks the boolean while the solving is in progress, so it doesnt call drawTree. Any suggestions?

Sorry if this is vague, ask clarifying questions and I’ll try to answer!

---

<div class="post-metadata">

**Author:** ![odecode](https://avatars.discourse-cdn.com/v4/letter/o/a8b319/32.png) [@odecode](https://discourse.processing.org/u/odecode)\
**Post date:** [August 13, 2021, 10:52am UTC](https://discourse.processing.org/t/calling-different-draw-functions/31709/2 "2021-08-13T10:52:20Z")

</div>

Update: I can make the void draw() call the drawTree() function, but it doesn’t actually draw anything on the screen. I am trying to just draw some lines at first. drawTree looks like this:

void drawTree(){  
println(“drawTree”);  
for(int i = 0; i \< 50000; i++){  
line(50,50,200,200,i,i+100);  
}  
}  
I am using P3D so I figure I need to give 3D coordinates. Anyone know what I am doing wrong?

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [August 13, 2021, 11:12am UTC](https://discourse.processing.org/t/calling-different-draw-functions/31709/3 "2021-08-13T11:12:30Z")

</div>

hi  
about functions helpful videos

### [Function parameters and return values](https://funprogramming.org/31-Function-parameters-and-return-values.html)

### [Use a function to simplify a program](https://funprogramming.org/32-Use-a-function-to-simplify-a-program.html)

### [Draw gradients, review functions and image loading](https://funprogramming.org/84-Draw-gradients-review-functions-and-image-loading.html)

### [Functions help keep code organized](https://funprogramming.org/103-Functions-help-keep-code-organized.html)

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [August 13, 2021, 11:51am UTC](https://discourse.processing.org/t/calling-different-draw-functions/31709/4 "2021-08-13T11:51:16Z")

</div>

```auto
void setup (){
  size(600,600,P3D);

}

void draw(){
drawTree();
}
void drawTree(){
println("drawTree");
for(int i = 0; i < 50000; i++){
line(50,50,200,200,i,i+100);
}
}

```

---

<div class="post-metadata">

**Author:** ![odecode](https://avatars.discourse-cdn.com/v4/letter/o/a8b319/32.png) [@odecode](https://discourse.processing.org/u/odecode)\
**Post date:** [August 13, 2021, 12:14pm UTC](https://discourse.processing.org/t/calling-different-draw-functions/31709/5 "2021-08-13T12:14:31Z")

</div>

thanks, that makes sense. It actually calls the drawTree that way, but the lines are not showing on the screen. Do you know why?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [August 13, 2021, 12:16pm UTC](https://discourse.processing.org/t/calling-different-draw-functions/31709/6 "2021-08-13T12:16:17Z")

</div>

The thing is that draw() only updates the screen at the end and not throughout

And you cannot force the screen to update.

The work around is that you use thread and it changes an image that you can display in draw () - when you do it right. I posted one example here

And jeremy douglas made another approach

links see below -

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [August 13, 2021, 12:16pm UTC](https://discourse.processing.org/t/calling-different-draw-functions/31709/7 "2021-08-13T12:16:30Z")

</div>

> [@odecode](#):
>
> the lines are not showing on the screen. Do you know why?

> [@odecode](#):
>
> line(50,50,200,200,i,i+100);

You keep increasing the z = i+100 from 100 to 50100 and it is out of the field of view.

Reference:  
[https://processing.org/reference/line\_.html[https://processing.org/reference/line\_.html](https://processing.org/reference/line\_.html)](https://processing.org/reference/line_.html%5Bhttps://processing.org/reference/line_.html%5D(https://processing.org/reference/line_.html))

`:)`

---

<div class="post-metadata">

**Author:** ![odecode](https://avatars.discourse-cdn.com/v4/letter/o/a8b319/32.png) [@odecode](https://discourse.processing.org/u/odecode)\
**Post date:** [August 13, 2021, 12:18pm UTC](https://discourse.processing.org/t/calling-different-draw-functions/31709/8 "2021-08-13T12:18:03Z")

</div>

I see, I will try that approach. Thanks for the suggestion 👍

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [August 13, 2021, 12:19pm UTC](https://discourse.processing.org/t/calling-different-draw-functions/31709/9 "2021-08-13T12:19:41Z")

</div>

There is lines on the top left

 ![Screenshot_2021-08-13-16-18-24-469](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/6/6810f495b0996c952bb21cd3281cae1596a0d85b.jpeg)

---

<div class="post-metadata">

**Author:** ![odecode](https://avatars.discourse-cdn.com/v4/letter/o/a8b319/32.png) [@odecode](https://discourse.processing.org/u/odecode)\
**Post date:** [August 13, 2021, 12:21pm UTC](https://discourse.processing.org/t/calling-different-draw-functions/31709/10 "2021-08-13T12:21:42Z")

</div>

Oh, for me they don’t show, originally it showed just the Cube and didnt do anything, but with your version it actually stopped drawing the cube (like I wanted), but I couldnt see the lines. They might have been somewhere out of the camera for me.

---

<div class="post-metadata">

**Author:** ![odecode](https://avatars.discourse-cdn.com/v4/letter/o/a8b319/32.png) [@odecode](https://discourse.processing.org/u/odecode)\
**Post date:** [August 13, 2021, 12:25pm UTC](https://discourse.processing.org/t/calling-different-draw-functions/31709/11 "2021-08-13T12:25:55Z")

</div>

Thank you! That is probably my issue since I got it to stop drawing the cube but I didnt see the lines.

---

<div class="post-metadata">

**Author:** ![odecode](https://avatars.discourse-cdn.com/v4/letter/o/a8b319/32.png) [@odecode](https://discourse.processing.org/u/odecode)\
**Post date:** [August 13, 2021, 12:37pm UTC](https://discourse.processing.org/t/calling-different-draw-functions/31709/12 "2021-08-13T12:37:56Z")

</div>

@glv @jafal (and Chrisir)  
Thank you guys, I got it to draw the lines now. I can start working on my solution from here. Thank you so much for helping me so quickly!

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [August 13, 2021, 1:04pm UTC](https://discourse.processing.org/t/calling-different-draw-functions/31709/13 "2021-08-13T13:04:48Z")

</div>

> [@jafal](#):
>
> ```auto
> void drawTree(){
> println("drawTree");
> for(int i = 0; i < 50000; i++){
> line(50,50,200,200,i,i+100);
> }
> 
> ```

I don’t really see how this would help

Because you would see the lines only at the end of draw() and not throughout

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [August 13, 2021, 6:13pm UTC](https://discourse.processing.org/t/calling-different-draw-functions/31709/14 "2021-08-13T18:13:56Z")

</div>

@Chrisir hi

I understand that he just want to activate his function void drawTree(){ and his demand is the function Regardless of the content of the function

Because he used experimental values

> [@odecode](#):
>
> but it doesn’t actually draw anything on the screen. I am trying to just draw some lines at first. drawTree looks like this:

> [@odecode](#):
>
> I got it to draw the lines now. I can start working on my solution from here.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [August 13, 2021, 8:20pm UTC](https://discourse.processing.org/t/calling-different-draw-functions/31709/15 "2021-08-13T20:20:49Z")

</div>

> [@odecode](#):
>
> want to add a drawTree() function that draws each step of creating and searching the tree, the

I wrote solvers myself. They run a long time figuring stuff out. When OP wants a solver that has a visible animation, your approach won’t work.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [August 14, 2021, 6:38pm UTC](https://discourse.processing.org/t/calling-different-draw-functions/31709/16 "2021-08-14T18:38:34Z")

</div>

for the thread / image approach see [Image resize animation and duplication using squareroot size - #13 by Chrisir](https://discourse.processing.org/t/image-resize-animation-and-duplication-using-squareroot-size/20438/13)

for Jeremy’s approach see [Update screen during draw() without thread?](https://discourse.processing.org/t/update-screen-during-draw-without-thread/18599)
