# Create random curve from X points

**URL:** <https://discourse.processing.org/t/create-random-curve-from-x-points/31218>\
**Category:** Beginners\
**Created:** [July 12, 2021, 9:34pm UTC](https://discourse.processing.org/t/create-random-curve-from-x-points/31218 "2021-07-12T21:34:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![yalaniv](https://avatars.discourse-cdn.com/v4/letter/y/7993a0/32.png) [@yalaniv](https://discourse.processing.org/u/yalaniv)\
**Post date:** [July 12, 2021, 9:34pm UTC](https://discourse.processing.org/t/create-random-curve-from-x-points/31218/1 "2021-07-12T21:34:02Z")

</div>

I want to draw curve from X points, random points.

I try to read about the bezierPoint() but not understood completely

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [July 13, 2021, 8:46am UTC](https://discourse.processing.org/t/create-random-curve-from-x-points/31218/2 "2021-07-13T08:46:15Z")

</div>

Hi @yalaniv,

If you want to draw a random curve, `bezierPoint()` is not the right function to use because it lets you do this :

> Evaluates the Bezier at point t for points a, b, c, d. The parameter t varies between 0 and 1, a and d are points on the curve, and b and c are the control points.

Which allow you to get a point on a bezier curve at a certain position on that curve (from 0 to 1). Usually you use it with the [`bezier()`](https://processing.org/reference/bezier_.html) function to display it.

The easiest way is to use [`curveVertex()`](https://processing.org/reference/curveVertex_.html) to display a curve, you just give points and it construct a curve for you.

Then for randomness you need :

- [`random()`](https://processing.org/reference/random_.html)
- [`for loop`](https://processing.org/reference/for.html)

---

<div class="post-metadata">

**Author:** ![philipplehmann](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/philipplehmann/32/4111_2.png) [@philipplehmann](https://discourse.processing.org/u/philipplehmann)\
**Post date:** [July 13, 2021, 9:42am UTC](https://discourse.processing.org/t/create-random-curve-from-x-points/31218/3 "2021-07-13T09:42:16Z")

</div>

Here is a solution with bezierCurve.

```auto

int prevX;
int prevY;

void setup() {
  size(400, 400);  
  strokeWeight(2);
  noFill();
}

void draw() {
  background(200);
  
  
  // First point at the left edge
  prevX = 0;
  prevY = height/2;
  
  
  // For loop gets repeated till right edge is reached
  for(int i = 1; i < 11; i++) {
   
    // Updatet x positino and create a new random Y value
    int x = i * 40;
    int y = int(random(height));
    
    // Draw a bezier line from the previous to the current point
    // Comment: replace "15" to adjust the handles
    bezier(prevX, prevY, prevX+15, prevY, x-15, y, x, y);
    
    
    // Make the current point the previous one.
    prevX = x;
    prevY = y;
  }
  
  // Stop drawing
  noLoop();
}

void mouseClicked() {
  loop();
}

```

`bezierPoint` is used to get a point on a `bezierCurve`.

---

<div class="post-metadata">

**Author:** ![jackyjoy123](https://avatars.discourse-cdn.com/v4/letter/j/d6d6ee/32.png) [@jackyjoy123](https://discourse.processing.org/u/jackyjoy123)\
**Post date:** [July 17, 2021, 11:38am UTC](https://discourse.processing.org/t/create-random-curve-from-x-points/31218/4 "2021-07-17T11:38:55Z")

</div>

thanks for the awesome information.

---

<div class="post-metadata">

**Author:** ![jackyjoy123](https://avatars.discourse-cdn.com/v4/letter/j/d6d6ee/32.png) [@jackyjoy123](https://discourse.processing.org/u/jackyjoy123)\
**Post date:** [December 12, 2021, 1:13pm UTC](https://discourse.processing.org/t/create-random-curve-from-x-points/31218/5 "2021-12-12T13:13:09Z")

</div>

> [@jackyjoy123](#):
>
> thanks for the awesome information.  
> [https://krogerfeedback.nl](https://krogerfeedback.nl) [https://talktosonic.onl](https://talktosonic.onl)

thanks my issue has been fixed.
