I can't make my lorenz attractor balls opaque help pls

I want to make the balls in this code opaque but whenever I try the balls stop appearing
help plssssssssss im going crazyyyyy :anguished: :anguished: :sob: :sob: :cry: :confounded: :confounded:

<let o = 10;
let p = 28;
let b = 8 / 3;

const num = 100;
const intertemp = 35 * 30;
let a = ;

function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
blendMode(ADD);

nLorenz();

}

function nLorenz() {
for (let i = 0; i < num; i++) {
a.push(new Lorenz(random(-1, 1), random(-1, 1), random(-1, 1)));
}
}

class Lorenz {

constructor(x, y, z) {
	this.pos = createVector(x, y, z);
	this.dV = createVector(0, 0, 0);
}

calcula(t) {
	this.dV.set(
		this.pos.x + t * o * (this.pos.y - this.pos.x),
		this.pos.y + t * (this.pos.x * (p - this.pos.z) - this.pos.y),
		this.pos.z + t * ((this.pos.x * this.pos.y) - (b * this.pos.z))
	);
	this.pos.set(this.dV);
}

draw() {
	push();
			
	translate(this.pos.x * 5, this.pos.y * 5, (this.pos.z - 25) * 5);
	sphere(1); // raio das bolota
	pop();
}

}
function draw() {
background(0);

if (frameCount % intertemp === 0) {
	a = [];
	nLorenz();
}

for (let i = 0; i < num; i++) {
	a[i].calcula(0.01);
	a[i].draw();
}

}>

Hello @mayara,

Welcome.

Please read:
Guidelines—Asking Questions

You did not format your code correctly.

What is the source of this code?

Hints only:

  • reference | p5.js < Add some color with opacity to the sphere.
  • Remove the background()
  • Make the sphere larger and remove the stroke.
  • Add the end of draw() overlay the the entire sketch window with a rect() that is black and also has opacity.

Experiment a little with above to achieve desired results.

I did the above to achieve this:

It looks much better live than in a screen grab.

:)

I’m sorry, but I didn’t understand correctly. when I tried to do what you said, my attractor got a little weird.

sorry for having the wrong code format and about where the code is from, I saw a lorenz attractor in the processing search tab and tried to do it

Hello again!

  fill(255, 255, 0, 128); //yellow and opacity 128
  noStroke();
  sphere(3); // raio das bolota

At the end of function draw():

function draw() {
//background(0);

// Your code...

fill(0, 10);  //black and opacity 10
rectMode(CENTER);
rect(0, 0, width, height);
}

Always fill() before the shape!

My background was black so that is why I chose black… you may have to change things on your end.

Experiment a little… I was just playing around with this and was done very quickly.

You can always go back and edit your code… as a new user you may have some limitations and have to wait a day.

This will be off the screen:
rect(windoWidth, windowHeight, windoWidth, windowHeight);

I suggest you visit the p5.js web page for tutorials, examples and references and it also has an editor:

In the p5.js editor on web page I added this to function setup() so it was initially black:
background(0);

I was using the Processing p5 mode editor initially.

This was in the p5.js editor with my suggested code changes:

:)

1 Like