# Rosetta Examples development

**URL:** https://discourse.processing.org/t/rosetta-examples-development/18945
**Category:** Development
**Created:** [March 23, 2020, 8:04pm UTC](https://discourse.processing.org/t/rosetta-examples-development/18945 "2020-03-23T20:04:11Z")
**Posts on this page:** 20
**Page:** 4

<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: [September 1, 2020, 3:27pm UTC](https://discourse.processing.org/t/rosetta-examples-development/18945/62 "2020-09-01T15:27:21Z")

</div>

> [@noel](#):
>
> … it’s good to get rid of many “silent” errors that can occur.

Besides that, JS can perform some extra optimizations to the strict code as well: 😉

> <https://stackoverflow.com/questions/21814335/benefits-of-use-strict-in-js>

> [@noel](#):
>
> It isn’t strict necessary is it?

Nope! It’s a helper which can always be deleted. 😈

---

<div class="post-metadata">

### Author: ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)
#### Post date: [September 1, 2020, 3:44pm UTC](https://discourse.processing.org/t/rosetta-examples-development/18945/63 "2020-09-01T15:44:26Z")

</div>

So now I wonder; if it’s that good, why isn’t it already included in the compiler?

---

<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: [September 1, 2020, 3:47pm UTC](https://discourse.processing.org/t/rosetta-examples-development/18945/64 "2020-09-01T15:47:26Z")

</div>

Just like Java, the ECMA team takes care that future JS versions won’t break compatibility w/ older code! 🕶

---

<div class="post-metadata">

### Author: ![raron](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/raron/32/13651_2.png) [@raron](https://discourse.processing.org/u/raron)
#### Post date: [September 1, 2020, 4:21pm UTC](https://discourse.processing.org/t/rosetta-examples-development/18945/65 "2020-09-01T16:21:10Z")

</div>

All I can say is: Huh ?❓🙂 I’ve never seen Sierpinski’s like _that_. Really condensed code too! Not familiar with the p5.js syntax though. But wow. Great stuff!

---

<div class="post-metadata">

### Author: ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)
#### Post date: [September 1, 2020, 6:24pm UTC](https://discourse.processing.org/t/rosetta-examples-development/18945/66 "2020-09-01T18:24:28Z")

</div>

I’ve posted the Sierpinski Carpet task as well on Rosetta, with the usual [link](https://www.openprocessing.org/sketch/953411) to OpenProcessing.

---

<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: [September 2, 2020, 11:46pm UTC](https://discourse.processing.org/t/rosetta-examples-development/18945/67 "2020-09-02T23:46:36Z")

</div>

Hosting Sierpinski’s p5.js & Java Mode online versions on [OpenProcessing.org](http://OpenProcessing.org): 😋

https://www.openprocessing.org/sketch/954178/embed/?  
https://www.openprocessing.org/sketch/954181/embed/?

---

<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: [September 3, 2020, 12:08am UTC](https://discourse.processing.org/t/rosetta-examples-development/18945/68 "2020-09-03T00:08:01Z")

</div>

Also a Python Mode version on [Trinket.io](http://Trinket.io) for completeness’ sake. 🐍

https://trinket.io/embed/python/de6eddb155?toggleCode=true&runOption=run&start=result

Although not very condensed b/c assignments can’t be used as expressions on Python. 😒

---

<div class="post-metadata">

### Author: ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)
#### Post date: [September 3, 2020, 1:04pm UTC](https://discourse.processing.org/t/rosetta-examples-development/18945/69 "2020-09-03T13:04:47Z")

</div>

I posted the Sierpinski arrowhead curve on Rosetta with a [link](https://www.openprocessing.org/sketch/954181).  
I’m trying to code the still missing [Sierpinski pentagon](http://www.rosettacode.org/wiki/Sierpinski_pentagon) with sin/cos, but it’s still a mess.  
@GoToLoop did you give it a try?

---

<div class="post-metadata">

### Author: ![villares](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/villares/32/3166_2.png) [@villares](https://discourse.processing.org/u/villares)
#### Post date: [September 3, 2020, 2:02pm UTC](https://discourse.processing.org/t/rosetta-examples-development/18945/70 "2020-09-03T14:02:37Z")

</div>

Sorry I’m a bit slow these days! I have almost finished the Plasma example and then everything derailed 😕 Will try to get back 🙂

---

<div class="post-metadata">

### Author: ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)
#### Post date: [September 3, 2020, 10:14pm UTC](https://discourse.processing.org/t/rosetta-examples-development/18945/71 "2020-09-03T22:14:25Z")

</div>

> [@noel](#):
>
> I’m trying to code the still missing [Sierpinski pentagon](http://www.rosettacode.org/wiki/Sierpinski_pentagon) with sin/cos, but it’s still a mess.  
> @GoToLoop did you give it a try?

Solved.

```auto
float s_angle, scale, margin = 25, total = 4;
float size = 700;
float radius = size/2-2*margin;
float side = radius * sin(PI/5)*2;

void setup() {
  size(590, 590);
  background(0, 0, 200);
  stroke(255);
  s_angle = 72*PI/180;
  scale = 1/(2+cos(s_angle)*2);
  for (int i = 0; i < total; i++) {
    background(0, 0, 200);
    drawPentagon(width/2, (height-size)/2 + 3*margin, side, total);
  }
}

void drawPentagon(float x, float y, float side, float depth) {
  float angle = 3*s_angle; 
  if (depth == 0) {  
    for (int i = 0; i < 5; i++) {
      float px = x;
      float py = y;
      x = x+cos(angle)*side;
      y = y-sin(angle)*side;
      line(x, y, px, py);
      angle += s_angle;
    }
  } else {
    side *= scale;
    float distance = side+side*cos(s_angle)*2;
    for (int j = 0; j < 5; j++) {
      x = x+cos(angle)*distance;
      y = y-sin(angle)*distance;
      drawPentagon(x, y, side, depth-1);
      angle += s_angle;
    }
  }
}

```

 ![p](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/1/11b5c0a6e66816a469812c1aa658ecadd03635ca.png)

---

<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: [September 5, 2020, 1:55am UTC](https://discourse.processing.org/t/rosetta-examples-development/18945/72 "2020-09-05T01:55:07Z")

</div>

> [@noel](#):
>
> @GoToLoop did you give it a try?

Well, I did. But it took me more time. 🕰

I’ve based mine on the Go version (although I barely know anything about that Google language): 🥴  
[RosettaCode.org/wiki/Sierpinski\_pentagon#Go](http://RosettaCode.org/wiki/Sierpinski_pentagon#Go)

That version uses a fixed palette of 5 primary colors. 🖌

In my sketch conversion I keep track of the current palette's index by returning it at the end of the recursive **pentagon()** function. 📐

In order to get a free color **fill()** I’m using **beginDraw()** + **vertex()** to draw each Sierpinski pentagon. 🖼

The 1st sketch below is the Java Mode version w/ no special optimization: ☕

https://www.openprocessing.org/sketch/955443/embed/

2nd sketch is the p5.js version, which caches all **cos()** & **sin()** calcs inside 2 [Float32Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array) containers, similar to what I already did before to the Python Mode conversion: 💡

https://www.openprocessing.org/sketch/955445/embed/

---

<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: [September 5, 2020, 2:03am UTC](https://discourse.processing.org/t/rosetta-examples-development/18945/73 "2020-09-05T02:03:02Z")

</div>

And finally the Python Mode flavor which the p5.js is based upon: 🐍

https://trinket.io/embed/python/0ed06a198b?toggleCode=true&runOption=run&start=result

---

<div class="post-metadata">

### Author: ![paulstgeorge](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@paulstgeorge](https://discourse.processing.org/u/paulstgeorge)
#### Post date: [September 6, 2020, 5:28am UTC](https://discourse.processing.org/t/rosetta-examples-development/18945/74 "2020-09-06T05:28:16Z")

</div>

I am looking forward to starting! I am just have to get my book off to the editor and then I’m on it.

The task I want to tackle is combinations and permutations in Processing. I know there is a great library for this, but that is like using a robot to mow the lawn.

---

<div class="post-metadata">

### Author: ![monkstone](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/monkstone/32/64_2.png) [@monkstone](https://discourse.processing.org/u/monkstone)
#### Post date: [September 6, 2020, 6:14pm UTC](https://discourse.processing.org/t/rosetta-examples-development/18945/75 "2020-09-06T18:14:35Z")

</div>

@noel @jeremydouglass @villares For the Sierpinski Carpet, eventually I opted for a variant on the @noel processing variation for JRubyArt, partly to show off the [JRubyArt grid method](http://ruby-processing.github.io/JRubyArt/methods/grid) now on [rosetta code](https://rosettacode.org/wiki/Sierpinski_carpet#Ruby).

---

<div class="post-metadata">

### Author: ![villares](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/villares/32/3166_2.png) [@villares](https://discourse.processing.org/u/villares)
#### Post date: [October 3, 2020, 4:20pm UTC](https://discourse.processing.org/t/rosetta-examples-development/18945/76 "2020-10-03T16:20:40Z")

</div>

I have added the Python mode of Sierpinski carpet to the wiki and to the repository, @monkstone, could you add the JRubyArt one?

Also, I have been working on the N-queen problem, Java and Python. 🙂

 ![n-queens](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/9/955931b8d5fcfa6744f2c78971b6c08d1e108e80.gif)

---

<div class="post-metadata">

### Author: ![villares](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/villares/32/3166_2.png) [@villares](https://discourse.processing.org/u/villares)
#### Post date: [October 4, 2020, 7:52pm UTC](https://discourse.processing.org/t/rosetta-examples-development/18945/77 "2020-10-04T19:52:12Z")

</div>

> [@noel](#):
>
> This is a code for the Plasma effect task. I

This is my Python mode attempt! @noel you could perhaps format yours with header for the GitHub repo[GitHub - jeremydouglass/rosetta\_examples\_p5: Example set from Rosetta Code for P5 (Processing)](https://github.com/jeremydouglass/rosetta_examples_p5/) too?

```auto
"""
 Plasmas with Palette Looping
 https://lodev.org/cgtutor/plasma.html#Plasmas_with_Palette_Looping_
"""

pal = [0] * 128
r = 42
g = 84
b = 126
rd = gd = bd = False

def setup():
    global buffer
    size(600, 600)
    frameRate(25)
    buffer = [None] * width * height
    for x in range(width):
        for y in range(width):
            value = int(((128 + (128 * sin(x / 32.0)))
                         + (128 + (128 * cos(y / 32.0)))
                         + (128 + (128 * sin(sqrt((x * x + y * y)) / 32.0)))) / 4)
            buffer[x + y * width] = value

def draw():
    global r, g, b, rd, gd, bd
    if r > 128: rd = True
    if not rd: r+=1
    else: r-=1
    if r < 0: rd = False
    if g > 128: gd = True
    if not gd: g+=1
    else: g-=1
    if r < 0: gd = False 
    if b > 128: bd = True
    if not bd: b+=1
    else: b-=1
    if b < 0: bd = False
 
    for i in range(128):
          s_1 = sin(i * PI / 25)
          s_2 = sin(i * PI / 50 + PI / 4)
          pal[i] = color(r + s_1 * 128, g + s_2 * 128, b + s_1 * 128)

    loadPixels()
    for i, b in enumerate(buffer):
          pixels[i] = pal[(b + frameCount) % 127]
    updatePixels()

```

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [October 5, 2020, 12:17pm UTC](https://discourse.processing.org/t/rosetta-examples-development/18945/78 "2020-10-05T12:17:57Z")

</div>

This looks really great! So excited to review – I’ll be getting caught up on merging things to the repository and making a new release shortly – I just need to survive the process of launching a new class co-taught class (How Games Tell Stories) this week for our online Fall quarter…

---

<div class="post-metadata">

### Author: ![villares](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/villares/32/3166_2.png) [@villares](https://discourse.processing.org/u/villares)
#### Post date: [October 5, 2020, 12:52pm UTC](https://discourse.processing.org/t/rosetta-examples-development/18945/79 "2020-10-05T12:52:55Z")

</div>

Thank you @jeremydouglass you are a cape-less hero!

---

<div class="post-metadata">

### Author: ![villares](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/villares/32/3166_2.png) [@villares](https://discourse.processing.org/u/villares)
#### Post date: [October 21, 2020, 2:00am UTC](https://discourse.processing.org/t/rosetta-examples-development/18945/80 "2020-10-21T02:00:10Z")

</div>

I’m going to add this raster-VoronoiDiagram, I have ported from Rosetta’s Python example first.

```python

def setup():
    size(500, 500)
    generate_voronoi_diagram(width, height, 25)
    saveFrame("VoronoiDiagram.png")

def generate_voronoi_diagram(w, h, num_cells):
    nx, ny, nr, ng, nb = [], [], [], [], [] 
    for i in range(num_cells):
        nx.append(int(random(w)))
        ny.append(int(random(h)))
        nr.append(int(random(256)))
        ng.append(int(random(256)))
        nb.append(int(random(256)))
    for y in range(h):
        for x in range(w):
            dmin = dist(0, 0, w - 1, h - 1)
            j = -1
            for i in range(num_cells):
                d = dist(0, 0, nx[i] - x, ny[i] - y)
                if d < dmin:
                    dmin = d
                    j = i
            set(x, y, color(nr[j], ng[j], nb[j]))

```

And the Java mode version:

```java

void setup() {
  size(500, 500);
  generateVoronoiDiagram(width, height, 25);
  saveFrame("VoronoiDiagram.png");
}

void generateVoronoiDiagram(int w, int h, int num_cells) {
  int nx[] = new int[num_cells];
  int ny[] = new int[num_cells];
  int nr[] = new int[num_cells];
  int ng[] = new int[num_cells];
  int nb[] = new int[num_cells];
  for (int n=0; n < num_cells; n++) {
    nx[n]=int(random(w));
    ny[n]=int(random(h));
    nr[n]=int(random(256));
    ng[n]=int(random(256));
    nb[n]=int(random(256));
    for (int y = 0; y < h; y++) {
      for (int x = 0; x < w; x++) {
        float dmin = dist(0, 0, w - 1, h - 1);
        int j = -1;
        for (int i=0; i < num_cells; i++) {
          float d = dist(0, 0, nx[i] - x, ny[i] - y);
          if (d < dmin) {
            dmin = d;
            j = i;
          }
        }
        set(x, y, color(nr[j], ng[j], nb[j]));
      }
    }
  }
}

```

---

<div class="post-metadata">

### Author: ![monkstone](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/monkstone/32/64_2.png) [@monkstone](https://discourse.processing.org/u/monkstone)
#### Post date: [October 21, 2020, 4:17pm UTC](https://discourse.processing.org/t/rosetta-examples-development/18945/81 "2020-10-21T16:17:07Z")

</div>

@villares inspired by you I’ve just posted JRubyArt variant of [voronoi diagram](https://rosettacode.org/wiki/Voronoi_diagram#Ruby). The existing ruby example is in need of correction, which I’ll get round to next (for one thing Queue is part of ruby so can be monkey patched without sub-classing Array).

[Previous page](https://discourse.processing.org/t/rosetta-examples-development/18945.md?page=3)
