Closed JoleneTiffanyG closed 5 years ago
Try putting a semi colon at the end of line 2.
You could try:
let g = 150;
On Wed, Oct 3, 2018, 23:32 Don-Vincent Snell notifications@github.com wrote:
Try putting a semi colon at the end of line 2.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Montana-Media-Arts/120_CreativeCoding/issues/165#issuecomment-426890599, or mute the thread https://github.com/notifications/unsubscribe-auth/Ao1K1ZpLOC8HWder6cNfU2Y2hMoPuyBnks5uhZ2FgaJpZM4XHI2F .
I do not think rgb() is a p5 object, but color() is:
let g = 150 ;
function setup(){
createCanvas(500 , 500);
background(color(50,150,70)) ;
}
function draw() {
const cd = color(50,g,70) ;
fill(cd);
ellipse(100,400,100) ;
}
maybe I'm wrong about rbg() but color() will work; not sure why it works in background()...
BTW - const is just a constant. it works like let or var only it is not reassignable. sorry if that was confusing. you could use let or var there and it'd work just fine.
ETA:
you can also set a color component after the fact:
g = 150
fill_color = color(50,75,70) ;
fill_color.setGreen(g) ;
But I haven't successfully retrieved a color component yet. I assumed it'd be just: color.component
like bg_color.blue
Thanks guys for all the advice! I had tried all those things to no avail unfortunately. It seemed like on some forums I was reading, sometimes color doesn't work exactly like that? Oh well, I've found some other workarounds to get what I need done. Thanks so much for responding, it's super generous and incredibly helpful!:)
This isn't my project, it's just an example for the sake of simplicity. But I'm trying to do something very basic and it's not working. I want g to be a variable I can use in rgba notation to change colors, and every time I put g in the spot where the green value number would go, it breaks and makes the ellipse white instead of the orangeish color it would be if the variable g was properly set to 150. What am I doing wrong here?