# Is it possible to trim a curveVertex() shape?

**URL:** <https://discourse.processing.org/t/is-it-possible-to-trim-a-curvevertex-shape/11314>\
**Category:** Coding Questions\
**Created:** [May 16, 2019, 9:14pm UTC](https://discourse.processing.org/t/is-it-possible-to-trim-a-curvevertex-shape/11314 "2019-05-16T21:14:14Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![nardove](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/nardove/32/7936_2.png) [@nardove](https://discourse.processing.org/u/nardove)\
**Post date:** [May 16, 2019, 9:14pm UTC](https://discourse.processing.org/t/is-it-possible-to-trim-a-curvevertex-shape/11314/1 "2019-05-16T21:14:14Z")

</div>

Hi,

I’m drawing a curveVertex shape by adding a point(x,y) at different intervals of time, this points are stored in an array, the array is use to draw the curve.

When my object goes to the edge of the screen, I render It at the opposite side of the screen. This cause the curveVertex to draw a straight line from one side of the screen to the other.

So I wander if it is possible to trim/cut the curveVertex to avoid the line that goes across the screen? Hope that makes sense.

Any helps will be much appreciated.

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [May 17, 2019, 1:25am UTC](https://discourse.processing.org/t/is-it-possible-to-trim-a-curvevertex-shape/11314/2 "2019-05-17T01:25:24Z")

</div>

i think it does not matter if it is a vertex drawing or just a circle,  
to do that what you want like

- leave right side pix by pix
- move in from left side ( like mirror )

you need for that short time 2 objects.  
( like when move right: left object.x = right object.x - width )

---

<div class="post-metadata">

**Author:** ![nardove](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/nardove/32/7936_2.png) [@nardove](https://discourse.processing.org/u/nardove)\
**Post date:** [May 17, 2019, 8:17am UTC](https://discourse.processing.org/t/is-it-possible-to-trim-a-curvevertex-shape/11314/3 "2019-05-17T08:17:07Z")

</div>

Hi kll,

Thank you for your time, but you didn’t understood my problem. The issue is not moving the object it self, the problem is that the curveVertex draws a line across the screen the the object travels to the opposite side, hope that makes sense.

Cheers  
rS

---

<div class="post-metadata">

**Author:** ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)\
**Post date:** [May 17, 2019, 8:25am UTC](https://discourse.processing.org/t/is-it-possible-to-trim-a-curvevertex-shape/11314/4 "2019-05-17T08:25:40Z")

</div>

Hi! You don’t need to move some vertices. You need to draw the whole shape twice, one of them displaced to the other side of the screen.

An example

```auto
function setup() {
  createCanvas(600, 600);
}
function draw() {
  background(200, 50, 100);

  // the original
  ellipse(mouseX, mouseY, 100, 100);

  // the clone
  if(mouseX > width/2) {
    translate(-width, 0);
  } else {
    translate(width, 0);
  }
  ellipse(mouseX, mouseY, 100, 100);
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 17, 2019, 8:30am UTC](https://discourse.processing.org/t/is-it-possible-to-trim-a-curvevertex-shape/11314/5 "2019-05-17T08:30:03Z")

</div>

> [@nardove](#):
>
> curveVertex

I think the issue here is that it’s a series of curveVertex in a long row. Hence a line from right side to left side.

To avoid this either just don’t go over the edge of the screen but just bounce

OR close the curve on the right and start a new one on the left

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [May 17, 2019, 8:49am UTC](https://discourse.processing.org/t/is-it-possible-to-trim-a-curvevertex-shape/11314/6 "2019-05-17T08:49:09Z")

</div>

hm.  
i think only if you try to do the mapping for the again let’s say x \>=width  
to x \> = 0 inside the one object.

that was the reason why i try to give you the idea with the 2 objects.

---

<div class="post-metadata">

**Author:** ![nardove](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/nardove/32/7936_2.png) [@nardove](https://discourse.processing.org/u/nardove)\
**Post date:** [May 17, 2019, 8:51am UTC](https://discourse.processing.org/t/is-it-possible-to-trim-a-curvevertex-shape/11314/7 "2019-05-17T08:51:24Z")

</div>

@Chrisir, yes I think those are my only options as I can’t see the availability of removing a section of the curveVertex

---

<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:** [May 19, 2019, 9:51pm UTC](https://discourse.processing.org/t/is-it-possible-to-trim-a-curvevertex-shape/11314/8 "2019-05-19T21:51:12Z")

</div>

> [@nardove](#):
>
> this points are stored in an array, the array is use to draw the curve.
> 
> When my object goes to the edge of the screen, I render It at the opposite side of the screen.

Are you trying to create a wrap-around object behavior, like Pac Man?

If so, @hamoid has put you on a correct path to a solution. You can define a PShape, detect if your object is overlapping a border, then draw it in two places if that is so.

---

<div class="post-metadata">

**Author:** ![nardove](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/nardove/32/7936_2.png) [@nardove](https://discourse.processing.org/u/nardove)\
**Post date:** [May 20, 2019, 10:59am UTC](https://discourse.processing.org/t/is-it-possible-to-trim-a-curvevertex-shape/11314/9 "2019-05-20T10:59:16Z")

</div>

Unfortunately PShape is not implemented in p5js as far as I know

---

<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:** [May 20, 2019, 5:40pm UTC](https://discourse.processing.org/t/is-it-possible-to-trim-a-curvevertex-shape/11314/10 "2019-05-20T17:40:02Z")

</div>

As an alternative you can wrap the commands in a function and call it twice.
