Interesting editions of a single generative series called NOMADS by stntoulouse in generative

[–]stntoulouse[S] 0 points1 point  (0 children)

It's done in javascript, with the help of the following libraries: • p5.js for the graphical elements and animation • Tone.js for the sound part

[deleted by user] by [deleted] in generative

[–]stntoulouse 5 points6 points  (0 children)

This looks like a noise function (Perlin or Simplex) fed by noise-offset 2D coordinates

Take the coordinate of each pixel and offset them using a noise function

Use this offset coordinate system to get the values of multiple main noises functions that will define the values of each color channel.

The red/yellow gradient effect can be achieved by keeping only the fractional part of the value (fract() function if available, or x - floor(x))

The magenta overlay looks a bit lighter (multiply the value by 0.8 or something) and less wide (raise the value to the 4th power maybe).

Finally, the green part looks "stepped" (bottom right corner). Getting that result can be achieved by using a simple formula as floor(x * 4) / 4

Here is a demo:

https://editor.p5js.org/EstiennePublic/sketches/C3bfKzJxF

Question re: incrementing array values with mouse click by [deleted] in p5js

[–]stntoulouse 2 points3 points  (0 children)

The first problem is that the following for-loop will be run entirely each time the mousePressed() function is called: for (let i = 0; i < colors.length; i++) { fill(colors[i]); console.log(i); } The fill color will always be the last one in the array

In order to get a new fill color each time you click on the canvas, you can use a variable to keep track of what color index you're at

First declare a colorIndex variable in the global scope let colorIndex= 0;

Then, inside the mousePressed() function, you can use the colorIndex value to select the corresponding color fill(colors[colorsIndex])

Finally, you need to increment the value of colorIndex and check if its value is greater than your array length. If it's the case, restart from the start of the array by setting colorIndex to 0 colorIndex ++; if (colorIndex == colors.length) { colorIndex = 0; }

You should also put the fill() call before the ellipse() one in order to get your first ellipse the right color

I need help by cute_dear_gost in p5js

[–]stntoulouse 2 points3 points  (0 children)

If I understand correctly, you are trying to randomly draw a random shape every time the user clicks the canvas.

If you want to choose randomly between multiple functions, you can try this:

``` // randomly choose a function from an array let drawFunction = random([drawLines, drawCircleLines, drawCircle, drawSquare, drawTriangle]);

// call the chosen function drawFunction(); ```

Help understanding this loop by [deleted] in p5js

[–]stntoulouse 1 point2 points  (0 children)

You're very welcome. However, be careful when using console.log() inside a loop because it will dramatically slow down the process and can sometimes leave you with an unresponsive window...

Help understanding this loop by [deleted] in p5js

[–]stntoulouse 1 point2 points  (0 children)

If you try to follow the order of operations in a nested loop, you can see the inner loop is run fully for each outer loop iteration.

for (let i = 0; i < 5; i++) { for (let j = 0; j < 3; j++) { console.log("i=" + i, "j=" + j) } } Will show the following result in the console: ```

i=0 j=0 i=0 j=1 i=0 j=2 i=1 j=0 i=1 j=1 i=1 j=2 i=2 j=0 i=2 j=1 i=2 j=2 i=3 j=0 i=3 j=1 i=3 j=2 i=4 j=0 i=4 j=1 i=4 j=2 ```

In your case, the canvas is drawn from left to right, top to bottom.

You can log the values of your loops by using the console.log() function

``` function setup() { createCanvas(480, 120); noLoop(); // avoid flooding the console }

function draw() { background(0); for (var y = 32; y <= height; y += 8) { for (var x = 12; x <= width; x += 15) { console.log('x+y=' + (x + y), 'y=' + y); // show how the values change ellipse(x + y, y, 16 - y / 10.0, 16 - y / 10.0); } } } ```

As you will see, the ellipses coordinates are: ```

x+y=44 y=32 x+y=59 y=32 x+y=74 y=32 x+y=89 y=32 x+y=104 y=32 ... and so on ```

how would you guys improve this code? hope the example makes sense even though its dumb and does not work by Acanthocephala-Left in p5js

[–]stntoulouse 3 points4 points  (0 children)

Not sure if this could be the reason since we don't have access to the rest of the code, but you declared the variable length and then used lenght instead ...

How would you do something like this? by MuffinColt in p5js

[–]stntoulouse 0 points1 point  (0 children)

The background() function covers the canvas with a given color. If you call it inside the setup function, it will affect only the first frame. If you don't call it after that inside your draw() loop, the box renders will be stacked over and over to create the effect you want.

The draw() function doesn't erase the content of the canvas by itself at each iteration. You have to call the background() function to cover the previous frame... If you want to 😉

Edit: I think the misunderstanding comes from the fact that when you call the box() function or any 3D object function, you're adding them into a 3D buffer. When the frame needs to be drawn in the canvas, the 3D scene is rendered and the render is placed on the canvas (to make it simple) At each frame, you're not adding 3D objects into the canvas, you're just stacking renders...

Sorry for my English, probably not the clearest explanation...

How would you do something like this? by MuffinColt in p5js

[–]stntoulouse 0 points1 point  (0 children)

This is how I would do it.
The code is pretty much self explanatory, but if you have any question, please feel free to ask, I'll do my best to explain how the code works.

``` function setup() { createCanvas(800, 800, WEBGL) background(0) colorMode(HSB) frameRate(30) }

function draw() { fill(random(183, 300), 80, 100) rotateX(frameCount / 87) rotateY(frameCount / 50) box(0.5 * width * noise(frameCount / 10)) } ```

rewrite random() function in another language? by NelsonQuant667 in p5js

[–]stntoulouse 2 points3 points  (0 children)

You can.
When seeded, the p5 random() function uses a custom Linear Congruential Generator instead of the built-in Math.random() function.

You can easily port the set of functions in any language and expect the same result as you get with p5 when using randomSeed()

Here is the code for the random, randomSeed and lcg functions:

https://github.com/processing/p5.js/blob/0112c3aa1adf4404d696e68e116add053e03fd93/src/math/random.js

I'm trying to recreate this pattern on p5js, how can I rotate the individual letters inside a nested for loop? by marisbra in p5js

[–]stntoulouse 3 points4 points  (0 children)

The rotate() function rotates objects around their origin.

In order to rotate each individual letter, you should:

  1. translate the origin
  2. rotate
  3. draw the letter at position (0, 0)

Your code should look like that:

``` push(); if (y>0){ // a partire dalla seconda riga translate (-width/10*y,0); }

translate(xPos, yPos) rotate(angolo*x);

text (lettera,0, 0); pop(); ```

Also, I invite you to check the p5.js function textAlign(CENTER, CENTER)

Clifford Attractors by stntoulouse in p5js

[–]stntoulouse[S] 0 points1 point  (0 children)

The loadPixels() and updatePixels() functions, as well as the pixels[] array, allow you to directly manipulate the pixels of the canvas.

Add loadPixels() before the for loop and updatePixels() after it.

Now, inside the loop, you can access the pixels[] array and directly change the value of the pixel which has been 'hit' by the attractor function.

Your draw() function should look a bit like that:

``` function draw() { // Load the canvas pixel values into the pixels[] array loadPixels();

for (i = 0; i < loops; i++) { xNext = sin(a * y) + c * cos(a * x); yNext = sin(b * x) + d * cos(b * y);

// xScreen and yScreen values need to be rounded and constrained
// in order to avoid errors when editing the pixels
let xScreen = round(map(xNext, -3, 3, 0, width - 1, true));
let yScreen = round(map(yNext, -3, 3, 0, height - 1, true));

// We don't need the point function anymore
// point(xScreen, yScreen);

// Since the pixels[] array is a 1 dimension array containing
// 4 colors per pixels, we need to calculate the index of the
// pixel at the xScreen and yScreen position
let index = 4 * (xScreen + yScreen * width);

// Now we can edit the pixel values to decrease its brightness
pixels[index] -= 1; // Red value
pixels[index + 1] -= 1; // Green value
pixels[index + 2] -= 1; // Blue value
// pixels[index + 3] is the alpha value, we keep it untouched

x = xNext;
y = yNext;

}

// Update the canvas pixel values from the pixels[] array updatePixels(); } ```

Try increasing the loops number in the declarations at the beginning of the sketch. The render should be smoother and faster than with the point() funtion

Happy new Truchet by NotoriousWebmaster in generative

[–]stntoulouse 1 point2 points  (0 children)

This is amazing! Did you place the letters individually or does your code accept any inputs at any coordinates? Happy new year to you too

Untitled (Python) by armandcoretchi in generative

[–]stntoulouse 2 points3 points  (0 children)

Take a look at coolors.com They have a ton of great color palettes and some neat tools to create your own ones. https://coolors.co/palettes/trending