Compare Processing to Python Processing code?

As @GoToLoop has pointed out, this is JavaScript (p5.js) code. Any JavaScript guide for Python programmers will prove helpful to you. But – nobody actually writes JavaScript like this unless they’re trying to cram it into a single tweet (and I’m assuming you might have found this on Twitter?). In any other context, it’s bad practice.

Here’s a Python translation. Note that I haven’t crammed it all into a single line, although I could have (in addition to adding other tricks to abbreviate it at the expense of readability) –

w, f = 640, 0

def setup():
    size(w, w)
    stroke(36, 28, 24)
    background(255)
    fill(5, 6, 3)

def draw():
    global f
    blendMode(DIFFERENCE)
    if f < 90:
        beginShape()
        for i in range(-2, 642):
            curveVertex(i*2, 200+f*6-320*noise(i/100., f))
        curveVertex(w, w)
        curveVertex(0, w)
        curveVertex(-w, w)
        endShape()
    f += 1

The Processing IDE includes a bunch of Python Mode examples (File > Examples), and there are other collections of Python sketches online – to list a few:

2 Likes