# Monet Art loop issue

**URL:** https://discourse.processing.org/t/monet-art-loop-issue/38089
**Category:** Coding Questions
**Created:** [July 25, 2022, 7:24am UTC](https://discourse.processing.org/t/monet-art-loop-issue/38089 "2022-07-25T07:24:34Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![druchtie](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/druchtie/32/16692_2.png) [@druchtie](https://discourse.processing.org/u/druchtie)
#### Post date: [July 25, 2022, 7:24am UTC](https://discourse.processing.org/t/monet-art-loop-issue/38089/1 "2022-07-25T07:24:34Z")

</div>

Hi, I have been watching some tutorials this weekend and came across a tutorial that I started to tweak to create some Monet-like artworks from my pictures. The only problem is that it has some strange behavior on the right side of the image (long lines), and I’m not sure what is causing it. I guess they are the last pixels of every column.

Does anyone have an idea how I could change my code not to get this effect?

 ![Screenshot 2022-07-25 at 09.22.34](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/6/d/6d0cf5d717563f528c36ee224e413746c689ac8b.jpeg)

I created a Sandbox for the project:

> **[Monet - CodeSandbox](https://codesandbox.io/s/monet-iud0lm?file=%2Fsketch.js)**
>
> Monet by DannyRuchtie

Code:

```auto
let img;
let cnv;

function preload() {
  img = [
    "/assets/temp-1.jpeg",
    "/assets/temp-2.jpeg",
    "/assets/temp-3.jpeg",
    "/assets/temp-4.jpeg",
    "/assets/temp-5.jpeg",
    "/assets/temp-6.jpeg",
    "/assets/temp-7.jpeg",
    "/assets/temp-8.jpeg",
    "/assets/temp-9.jpeg",
    "/assets/temp-11.jpeg",
    "/assets/temp-13.jpeg"
  ];

  var pos = floor(random(img.length));
  img = loadImage(img[pos]);
}

function setup() {
  // img.resize(img.width, img.height);

  cnv = createCanvas(img.width, img.height);

  let newCanvasX = (windowWidth - img.width) / 2;
  let newCanvasy = (windowHeight - img.height) / 2;

  cnv.position(newCanvasX, newCanvasy);

  for (let col = 0; col < img.width; col += 1) {
    for (let row = 0; row < img.height; row += 1) {
      let xPos = col;
      let yPos = row;

      let c = img.get(xPos, yPos);

      push();
      translate(xPos, yPos);
      rotate(radians(random(90, 360)));
      noFill();
      stroke(color(c));
      strokeWeight(random(1, 3));

      curve(
        xPos,
        yPos,
        sin(xPos) * random(4, 10),
        cos(xPos) * sin(xPos) * random(2, 10),
        random(10),
        random(2, 10),
        cos(yPos) * sin(yPos) * random(2, 3),
        cos(xPos) * sin(xPos) * 2
      );
      pop();
    }
  }
}

```

---

<div class="post-metadata">

### Author: ![druchtie](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/druchtie/32/16692_2.png) [@druchtie](https://discourse.processing.org/u/druchtie)
#### Post date: [July 25, 2022, 9:20am UTC](https://discourse.processing.org/t/monet-art-loop-issue/38089/2 "2022-07-25T09:20:09Z")

</div>

I added an additional test image to verify that it’s only happening on the last row of pixels but not sure why.

 ![Screenshot 2022-07-25 at 11.20.32](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/8/2/826e39af8d945d98b1f8f4d1b0f072bfcdcb8461.jpeg)

---

<div class="post-metadata">

### Author: ![javagar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/javagar/32/11434_2.png) [@javagar](https://discourse.processing.org/u/javagar)
#### Post date: [July 25, 2022, 10:37am UTC](https://discourse.processing.org/t/monet-art-loop-issue/38089/3 "2022-07-25T10:37:47Z")

</div>

Hello, @druchtie, and welcome to the Processing Foundation Forum!

What is the purpose of this line in the `setup()` function?

```auto
  img.resize(img.width, img.height);

```

By the way, Monet is one of my favorite artists! 🙂

---

<div class="post-metadata">

### Author: ![druchtie](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/druchtie/32/16692_2.png) [@druchtie](https://discourse.processing.org/u/druchtie)
#### Post date: [July 25, 2022, 11:13am UTC](https://discourse.processing.org/t/monet-art-loop-issue/38089/4 "2022-07-25T11:13:56Z")

</div>

Hi @javagar good questions.  
I was playing around with reducing the image size for performance but I forgot to delete it.

---

<div class="post-metadata">

### Author: ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)
#### Post date: [July 25, 2022, 12:07pm UTC](https://discourse.processing.org/t/monet-art-loop-issue/38089/5 "2022-07-25T12:07:46Z")

</div>

Hi @druchtie,

slow but nice. 🙂

Guess you want this …

Cheers  
— mnse

```auto
      curve(
        0, // already on xPos by translate above
        0, // already on yPos by translate above
        sin(xPos) * random(4, 10),
        cos(xPos) * sin(xPos) * random(2, 10),
        random(1, 10),
        random(2, 10),
        cos(yPos) * sin(yPos) * random(2, 3),
        cos(xPos) * sin(xPos) * 2
      );

```

---

<div class="post-metadata">

### Author: ![druchtie](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/druchtie/32/16692_2.png) [@druchtie](https://discourse.processing.org/u/druchtie)
#### Post date: [July 25, 2022, 12:23pm UTC](https://discourse.processing.org/t/monet-art-loop-issue/38089/6 "2022-07-25T12:23:13Z")

</div>

That was it! Thank you so much @mnse.  
Unfortunately it’s a bit slow, but it does the trick!

I guess there is no other way to speed things up in JS?

---

<div class="post-metadata">

### Author: ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)
#### Post date: [July 25, 2022, 1:10pm UTC](https://discourse.processing.org/t/monet-art-loop-issue/38089/7 "2022-07-25T13:10:49Z")

</div>

Hi @druchtie,

maybe you can try out this in your setup. Should be speed up things, at least a bit …

Cheers  
— mnse

```auto
function setup() {
  cnv = createCanvas(img.width, img.height);
  let newCanvasX = (windowWidth - img.width) / 2;
  let newCanvasy = (windowHeight - img.height) / 2;
  cnv.position(newCanvasX, newCanvasy);
  
  img.loadPixels();
  for (let idx = 0,pidx = 0; idx < img.width * img.height; idx++,pidx+=4) {
    let xPos = floor(idx % img.width);
    let yPos = floor(idx / img.width);
    push();
    translate(xPos, yPos);
    rotate(radians(random(90, 360)));
    noFill();
    stroke(color(img.pixels[pidx],img.pixels[pidx + 1], img.pixels[pidx + 2], img.pixels[pidx + 3]));
    strokeWeight(random(1, 3));

    curve(
      0,
      0,
      sin(xPos) * random(4, 10),
      cos(xPos) * sin(xPos) * random(2, 10),
      random(10),
      random(2, 10),
      cos(yPos) * sin(yPos) * random(2, 3),
      cos(xPos) * sin(xPos) * 2
    );
    pop();
  } 
}

```

EDIT: just added alpha channel for the sake of completeness.

---

<div class="post-metadata">

### Author: ![javagar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/javagar/32/11434_2.png) [@javagar](https://discourse.processing.org/u/javagar)
#### Post date: [July 25, 2022, 5:45pm UTC](https://discourse.processing.org/t/monet-art-loop-issue/38089/8 "2022-07-25T17:45:35Z")

</div>

Nice work, @druchtie and @mnse!

> [@druchtie](#):
>
> … came across a tutorial that I started to tweak to create some Monet-like artworks …

Could we have a link to that tutorial?

Thanks! 🙂

---

<div class="post-metadata">

### Author: ![druchtie](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/druchtie/32/16692_2.png) [@druchtie](https://discourse.processing.org/u/druchtie)
#### Post date: [July 25, 2022, 6:15pm UTC](https://discourse.processing.org/t/monet-art-loop-issue/38089/9 "2022-07-25T18:15:45Z")

</div>

@javagar this is the tutorial I followed: [https://youtu.be/me04ZrTJqWA](https://youtu.be/me04ZrTJqWA)

---

<div class="post-metadata">

### Author: ![javagar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/javagar/32/11434_2.png) [@javagar](https://discourse.processing.org/u/javagar)
#### Post date: [July 25, 2022, 6:56pm UTC](https://discourse.processing.org/t/monet-art-loop-issue/38089/10 "2022-07-25T18:56:30Z")

</div>

Thanks for the link!

🙂
