# Compare Processing to Python Processing code?

**URL:** <https://discourse.processing.org/t/compare-processing-to-python-processing-code/36886>\
**Category:** Processing.py\
**Created:** [May 14, 2022, 10:50pm UTC](https://discourse.processing.org/t/compare-processing-to-python-processing-code/36886 "2022-05-14T22:50:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![firefox](https://avatars.discourse-cdn.com/v4/letter/f/9de053/32.png) [@firefox](https://discourse.processing.org/u/firefox)\
**Post date:** [May 14, 2022, 10:50pm UTC](https://discourse.processing.org/t/compare-processing-to-python-processing-code/36886/1 "2022-05-14T22:50:20Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [May 14, 2022, 11:16pm UTC](https://discourse.processing.org/t/compare-processing-to-python-processing-code/36886/2 "2022-05-14T23:16:03Z")

</div>

> [@firefox](#):
>
> It would help me to compare differences and to learn.

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

> **[Processing transition](https://github.com/processing/p5.js/wiki/Processing-transition)**
>
> p5.js is a client-side JS platform that empowers artists, designers, students, and anyone to learn to code and express themselves creatively on the web. It is based on the core principles of Proces...

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:

> **[Put Python and ProcessingJS Anywhere on the Web](https://trinket.io/processing/de6eddb155)**
>
> Python in the browser. No installation required.

> **[Put Python and ProcessingJS Anywhere on the Web](https://trinket.io/processing/0ed06a198b)**
>
> Python in the browser. No installation required.

> **[Put Python and ProcessingJS Anywhere on the Web](https://trinket.io/processing/94a110f666)**
>
> Python in the browser. No installation required.

> **[Put Python and ProcessingJS Anywhere on the Web](https://trinket.io/processing/4f96265ee0)**
>
> Python in the browser. No installation required.

> **[Put Python and ProcessingJS Anywhere on the Web](https://trinket.io/processing/62fab051ed)**
>
> Python in the browser. No installation required.

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [May 15, 2022, 1:40am UTC](https://discourse.processing.org/t/compare-processing-to-python-processing-code/36886/3 "2022-05-15T01:40:00Z")

</div>

As @GoToLoop has pointed out, this is JavaScript ([p5.js](https://p5js.org/)) 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) –

```python
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:

- [https://github.com/tabreturn/processing.py-book](https://github.com/tabreturn/processing.py-book)
- [https://abav.lugaralgum.com/sketch-a-day](https://abav.lugaralgum.com/sketch-a-day)
- [http://pyde.org](http://pyde.org)
