We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I'm new to controlP5 and am trying to figure out why my slider is only adjusting greyscale and not the color I have inputted. I assume I will have to use the color sliders for this implementation? Thanks
import controlP5.*;
ControlP5 cp5;
int sliderValue2 = 100;
color sliderValue = color(255, 0, 255);
Slider abc;
void setup() {
size(700, 400);
noStroke();
cp5 = new ControlP5(this);
cp5.addSlider("sliderValue2")
.setPosition(width/2 - 100, 50)
.setSize(200, 20)
.setRange(0, 255)
.setNumberOfTickMarks(5)
.setSliderMode(Slider.FLEXIBLE)
;
cp5.addSlider("sliderValue")
.setPosition(width/2 - 100, 150)
.setSize(200, 20)
.setRange(0, 255)
.setNumberOfTickMarks(5)
.setSliderMode(Slider.FLEXIBLE)
;
}
void draw() {
background(sliderValue);
fill(sliderValue2);
rect(0, 0, width, 100);
}
Answers
your background colour is a color but your slider is an int from 0-255. will that work?
add a line before 32,
In Processing, datatype
color
is merely syntactic sugar for the actualint
primitive type:https://Processing.org/reference/color_datatype.html
The initial value
color(255, 0, 255)
represents the color mask #FF00FF.I presume you intend to control the green channel w/ your Slider, doesn't it?
You're also gonna need to left-shift
<<
the 0-255 range w/ 8bytesbits (1 byte or octet) in order to place itself at green channel: https://Processing.org/reference/leftshift.htmlI believe @GoToLoop meant to say 8 bits.. not bytes <:-P
Kf
Oops! Fixed now! X_X
I appreciate the answer; however, I am having difficulty making sense of the concept of shifting in this application. I understand how the mask allows the color to be controlled; however, I am somewhat confused. I would think that since it is three integers the shifting should only be for 6 digits as opposed to 8. (head scratching). Its a cool method though and I appreciate it!
Datatype
color
is 32 bits or 4 bytes. Besides RGB, there's the alpha too: aRGB.Blue doesn't shift. While the alpha needs 24 bits to left. :-B
Ok nice. Gracias. makes sense :)>-