Hi,
I’m just beginning with this library and I have trouble to start.
When I play my code, I have a "Script error. (:line 0) " message in the console.
I identified where the problem happpens in my code but I have no idea why.
It seems to be related to the z coordinate of my point (line 48 see code below).
Can anyone help ?
Thx in advance.
Sebastien
var ps = null;
function setup(){
createCanvas(1000, 400, WEBGL);
ps = new ParticleSystem (10, 10, 5, 5, createVector(width/2, height/2, 0));
}
function draw(){
background(0);
ps.run();
}
var ParticleSystem = function(numX,numZ,stepX,stepZ,v) {
this.particles = [];
this.origin = v.copy();
this.varDepth = stepZ;
for(var i = 0; i < numZ; ++i){
for(var j = 0; j < numX; ++j){
//Vector in absolute
var particlePos = createVector((numX*stepX/2)-j*stepX,0,(numZ*stepZ/2)-i*this.varDepth)
//Vector relative to Canvas
this.particles.push(new Particle(this.origin.sub(particlePos)));
}}
}
ParticleSystem.prototype.run = function() {
var len = this.particles.length;
//loop through and run particles
for (var i = len - 1; i >= 0; i--) {
var particle = this.particles[i];
particle.run()
}
}
var Particle = function (pos) {
this.loc = pos;
}
Particle.prototype.run = function() {
this.display()
}
Particle.prototype.display = function() {
stroke(255);
point(this.loc.x, this.loc.y, this.loc.z);
}
Hello WizardBear,
Nothing fancy about the HTML, just the canvas.
The code above is a first attempt to display a white 3d dot Matrix particles system.
If you have an idea about why nothing happens, I’m interested.
Thx
I think stuff is happening–you just can’t see it as it isn’t on the canvas. (Working in 3D is hard. )
I am just a bit confused as to why you are getting an error. Is the code running?
Yes
I also tried to replace the point with a sphere and it works. So it’s a problem with the use of the point with WEBGL.
This piece of code works almost as expected except I wanted to use real dots at first and also that I don’t understand why the animation is pausing for 2 secs every 1 sec (but that’s probably a completely different issue problem)
var ps = null;
function setup(){
createCanvas(1000, 400, WEBGL);
ps = new ParticleSystem (20, 20, 20, 20, createVector(0,50,0));
}
function draw(){
background(0);
ps.run();
}
var ParticleSystem = function(numX,numZ,stepX,stepZ,v) {
this.particles = [];
this.varDepth = stepZ;
for(var i = 0; i < numZ; ++i){
for(var j = 0; j < numX; ++j){
//Vector in absolute
var canvasOrigin = v.copy()
var matrixOrigin = createVector((numX*stepX/2)-j*stepX,0,(numZ*stepZ/2)-i*this.varDepth)
//Vector relative to Canvas
this.particles.push(new Particle(canvasOrigin.sub(matrixOrigin)));
}
}
}
ParticleSystem.prototype.run = function() {
var len = this.particles.length;
//loop through and run particles
for (var i = len - 1; i >= 0; i--) {
var particle = this.particles[i];
particle.run()
}
}
var Particle = function (pos) {
this.loc = pos.copy();
this.radius = 0.1;
}
Particle.prototype.run = function() {
this.update();
this.display()
}
Particle.prototype.update = function() {
this.radius = randomGaussian(0.2, 0.1);
}
Particle.prototype.display = function() {
stroke(255);
push();
translate(this.loc.x, this.loc.y, this.loc.z);
sphere(this.radius,4,4);
pop();
}
Hmmm not really … I would have preferred to use dots instead of spheres … and it’s frustrating not to understand why it doesn’t do what I want.
I will leave it opened just a little time more in case someone would have a flash.
Thank you though !
I think it is because point() works with pixels, which you can only really do in a 2D environment as the screen of pixels is 2D and you are essentially coloring one of those pixels. sphere() is much more versatile as it is built to be used in a 3D environment.
I will leave it opened just a little time more in case someone would have a flash.
But the point() object is accessible in WEBGL : https://p5js.org/reference/#/p5/point
I also have to try it on another development environment to confirm the issue.
No I will not delete the topic but I thought there was a “solved” button to click but I realise that not.
So the topic will stay as it is.