Hex color in p5js web editor

#1

Hi forum,

Why does this not work in the p5js web editor?

function setup() {
  createCanvas(400, 400);
}

function draw() {
  background(220);
  
  let c1 = color('#f92804');
  fill(c1);
  rect(width/2,height/2,50,50);
}

Thanks for the help.

#2

In the future please try to be more specific. Saying it doesn’t work doesn’t tell us much, so try to describe the behavior you expected versus what you’re actually seeing.

Also, try to get into the habit of looking at your JavaScript console. Any errors you get will show up there.

Anyway, take a closer look at this line:

let c1 = color(’#f92804’);

Notice that the apostrophe characters in there are smart quotes instead of the straight up-and-down apostrophe character.

If I change that line to this:

let c1 = color('#f92804');

Then I see a single red rectangle on the screen, which is what I would expect.

2 Likes
#3

hi Leo_Aguiar,
you not posted / PASTED the code in the

</> code tag

so possible the mentioned

(’#f92804’)
('#f92804')

problem is not the real problem, just created here at the forum post ?

if you refer to the problem where in p5.js color can be defined
there is a good info at
https://github.com/processing/p5.js/wiki/p5.js-overview#why-cant-i-assign-variables-using-p5-functions-and-variables-before-setup ,
using this i got for example:
https://editor.p5js.org/kll/sketches/Ac56AkHp-
SNAG-0035


hi Kevin,
yes and no!
i show a little gallery what i see here: ( win7 64bit / firefox browser )
about p5js.org editor / and a possible problem with it.
-a- the change works when i was not login
SNAG-0036
-b- now i login and same code NOT work:
SNAG-0037
-c-
can not use global: ( if you not use the

new p5();


-d- officially must use setup() for it

what you make out of that? what i do wrong?

#4

Would you mind sharing your sketch link? I’ve tried to duplicate your code in firefox, but it seems to be working for me.

image

#5

yes, here check again and save “project”
https://editor.p5js.org/kll/sketches/RgyiH6udg

recheck again, copy code, logout / same
copy code into clean new edit window: works!
so same like i show above


call that sketch link from my Raspberry Pi / Raspbian OS / chromium browser /
works!
login

so, i have a bad name!!!

1 Like
#6

Hmm.

@kll – perhaps file a bug report?

1 Like
#7

not much to go on.

i should try first a new account.
possibly hand my old account to a admin for check…

( i mentioned already somewhere that i have that funny noise problem too
only when i am login ( and a sketch run and FPS drops)
even published a video as proof, here but no feedback so i think of it as a local bug?? but same, also on 2 computer with different OS and browser )

/ old man play old hardware / what i expect /
i not want to waste developers time