Compare Processing to Python Processing code?

Hello,

I’m new to the Processing, and I have a background in pyhton. I used to make patterns with python, but now I need something better. I’m having trouble finding examples of processing in python, but I have found many codes like this.

w=640;f=0;setup=_={createCanvas(w,w);stroke(36,28,24);background(255);fill(5,6,3)}draw=_=>{blendMode(DIFFERENCE);if(f<90{beginShape();for(i=-2;i<=642;i++){(g=curveVertex)(i*2,200+f*6-320*noise(i/100,f))}g(w,w);g(0,w);g(-w,w);endShape()}f++}

Can someone rewrite this (it doesn’t have to be this one, provide any other) code in processing and python processing? It would help me to compare differences and to learn.

Thanks in advance!

The code you’ve posted above is using the p5js flavor:

Anyways, I’ve got some sketch examples written in Processing’s Python Mode which are also available on other Processing flavors for you to compare:

1 Like

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