1

I am trying to understand the loop in this Processing syntax:

t=0
draw=_=>{t||createCanvas(W = 720,W)
t+=.01
B=blendMode
colorMode(HSB)
B(BLEND)
background(0,.1)
B(ADD)
for(y = 0; y < W; y += 7)
  for(x = 0; x < W; x+=7)
    dist(x, y, H = 360, H) +
      !fill(x * y % 360, W, W, 
            T=tan(noise(x, y) * 9 + t)) 
         < sin(atan2(y - H, x - H) * 2.5 + 84)**8 * 200 + 130?
circle(x, y + 30, 4/T) : 0}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.5.0/p5.js"></script>

from here.

I am making great progress, and I get now that the ending :0 is the ifelse of the Boolean in ?, but I want to focus solely on the t counter.

First off, it doesn't seem that t has any endpoints: it simply keeps incrementing.

Second, I see that the image that it would produce with a very stripped down code like this:

t=0
draw=_=>{t||createCanvas(W = 720,W)
t+=.01
console.log(frameCount)
for(y = 0; y < W; y += 70)
  for(x = 0; x < W; x+=70)
circle(x+random(10,20), y+ random(10,20) + 30, 30)}

is

enter image description here

whereas commenting out the t+=.01 produces constant wiggling between frames but no double contours:

enter image description here

plus the background is different.

Therefore I deduct that t+=.01 somehow concatenates each frame so that the information of one frame is overlapped on the previous until the new circles obscure the previous ones.

But does each frame start producing all the prior information from the very start t=0? Or is there a latency between frames, or somehow superimposition? How is the memory of previous frames retained? I see that t is a loop, so I guess the span of the iterations keeps on growing in each frame, and becomes larger and larger, but always starting at t=0?

A simple hacking test is to run:

t=0
draw=_=>{t||createCanvas(W = 720,W)
t +=0.01
console.log(frameCount)
for(y = 0; y < W; y += 2)
  for(x = 0; x < W; x+=2)

point(x+ random(0,frameCount), y+ random(0, frameCount))}

to see how quickly the entire canvas becomes homogeneously black, because each t (with t +=.01 operational) paints on top of the previous frame as in an infinity loop.

JAP
  • 405
  • 2
  • 11

1 Answers1

1

Your canvas frames are not 'stored'. For every frame, draw() is being executed and will draw everything on top of the current canvas. If your current frame has an opaque background, then it will be like a 'reset', a new frame, because all pixels are being redrawn. But if you put a semi-transparent background like on your first example (background(0,.1)) or don't put a background at all, then you'll still see some of the previous frame pixels.

In this case t is only being used with two purposes. First, to check if this is the first frame or not...

draw=_=>{t||createCanvas(W = 720,W)

...and second, to incrementally calculate T:

T=tan(noise(x, y) * 9 + t)).

Not sure if this is what you needed. Hopefully this clarifies how draw() works in this script.

zJorge
  • 798
  • 2
  • 13
  • 26
  • I didn't get "t is only used for two reasons. First to check if this is the first frame or not." – JAP Dec 29 '22 at 04:42
  • I meant, "t" is used for those 2 purposes. Let me check my grammar, I just noticed a couple of typos there too. Sorry :) – zJorge Dec 29 '22 at 15:03
  • Your grammar is great. I just don't get how this "checking if it's the first frame" works. – JAP Dec 29 '22 at 19:19