Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

198
Visualizações
p5.js — "Error: [object Arguments]is not a valid color representation" only when working with WEBGL

I'm trying to draw a field of stars (among other things) using p5.js.

I get this error when I create my canvas using WEBGL, but the error goes away when I don't use it. However, I need the canvas to use WEBGL for other aspects of the project. Clearly I'm missing something here.

var CANVAS_SIZE = 600;

var starfield;

function setup() {
  createCanvas(CANVAS_SIZE, CANVAS_SIZE, WEBGL);
  noStroke();
  buildStarfield();
  
  // noprotect
}

function buildStarfield() {
  
  starfield = createImage(CANVAS_SIZE,CANVAS_SIZE);
  starfield.loadPixels();
  
  var starThreshold = 205; //threshold to weed out "less bright" stars
  
  for (var i = 0; i < CANVAS_SIZE; i++) {
    for (var j = 0; j < CANVAS_SIZE; j++) {
      // generate a noise map on which to base the starfield
      var c = 255 * noise(0.1 * i, 0.1 * j, random(0,1));
          
          // if c > starThreshold the draw a star else draw empty space
          if (c>starThreshold) {
            starfield.set(i, j, color(255,255,255,1));         
          } else {
            starfield.set(i, j, color(0,0,0,10));
          }  
        }
    }
  
  starfield.updatePixels();
  
}

function draw() {
  background(starfield);  
}

Here's where I'm testing, if it matters:

https://editor.p5js.org/

Any idea as to why would this createCanvas(CANVAS_SIZE, CANVAS_SIZE); work, but not createCanvas(CANVAS_SIZE, CANVAS_SIZE, WEBGL); this?

How can I make it work using WEBGL?

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

It might be a temporary bug with background() and WEBGL.

While that gets fixed you can use:

image(starfield,-starfield.width / 2, -starfield.height / 2); 

instead of background(starfield) to get the same visual outcome using WEBGL (it will work as image(startfield, 0, 0); if you're not using WEBGL)

about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda