# Simple Perlin noise random walk behavior in C++

**URL:** https://discourse.processing.org/t/simple-perlin-noise-random-walk-behavior-in-c/44975
**Category:** Coding Questions
**Created:** [August 22, 2024, 12:11pm UTC](https://discourse.processing.org/t/simple-perlin-noise-random-walk-behavior-in-c/44975 "2024-08-22T12:11:08Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Tilman](https://avatars.discourse-cdn.com/v4/letter/t/90db22/32.png) [@Tilman](https://discourse.processing.org/u/Tilman)
#### Post date: [August 22, 2024, 12:11pm UTC](https://discourse.processing.org/t/simple-perlin-noise-random-walk-behavior-in-c/44975/1 "2024-08-22T12:11:08Z")

</div>

We are trying to get this same random walk behaviour from the simple perlin noise random walk as in the p5.js sketch below. But for us in C++ with openFrameworks Perlin Noise we get a behaviour where the dot is always drifting to the center and not having these random rests at certain positions…

See this video for the behaviour we get with C++

[https://www.dropbox.com/scl/fi/nr79zqlsz4wdig568ztr6/CPlusPlus.mp4?rlkey=t4e3ag0cth35e6k0bzcysdtkd&dl=0](https://www.dropbox.com/scl/fi/nr79zqlsz4wdig568ztr6/CPlusPlus.mp4?rlkey=t4e3ag0cth35e6k0bzcysdtkd&dl=0)

Cheers!

```JS
let radiusSlider;
let speedSlider;
let smallCircleRadius = 12;
let noiseOffsetX = 0;
let noiseOffsetY = 10000;

function setup() {
  createCanvas(windowWidth, windowHeight);
  radiusSlider = createSlider(10, min(windowWidth, windowHeight) / 10, 90);
  radiusSlider.position(10, 10);
  speedSlider = createSlider(0.001, 0.1, 0.01, 0.001);
  speedSlider.position(10, 40);
}

function draw() {
  background(255);
  let radius = radiusSlider.value();
  let speed = speedSlider.value();
  
  stroke(0);
  strokeWeight(2);
  noFill();
  ellipse(width / 2, height / 2, radius * 2, radius * 2);

  let noiseX = noise(noiseOffsetX) * 2 - 1;
  let noiseY = noise(noiseOffsetY) * 2 - 1;
  
  let smallCircleX = width / 2 + noiseX * (radius - smallCircleRadius);
  let smallCircleY = height / 2 + noiseY * (radius - smallCircleRadius);
  
  fill(0);
  noStroke();
  ellipse(smallCircleX, smallCircleY, smallCircleRadius * 2, smallCircleRadius * 2);
  
  noiseOffsetX += speed;
  noiseOffsetY += speed;
}

function windowResized() {
  resizeCanvas(windowWidth, windowHeight);
}

```

---

<div class="post-metadata">

### Author: ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)
#### Post date: [August 22, 2024, 4:27pm UTC](https://discourse.processing.org/t/simple-perlin-noise-random-walk-behavior-in-c/44975/2 "2024-08-22T16:27:14Z")

</div>

Unable to view the video get the warning

> No video with supported format and MIME type found
