使用处理制作离散滑块
如何使用处理使我的滑块离散?这是我的代码。我需要将其与0-10的值进行离散。我已经提出了一些线指标,我只需要使其离散。您能给我一个关于如何做的想法吗?
到目前为止,我们现在所做的只是连续的滑块,拇指的行驶非常顺利。我们如何在同一滑块中添加步骤以制作离散的滑块?这是同一滑块的一个示例,但是有10个步骤,而不是返回之间的每个值。
int x=75;
void setup() {
size(600,400);
}
void draw() {
background(100);
fill (200);
rect (75, 25, 400, 50);
stroke(0);
if(mousePressed) {
if (mouseX >75 && mouseX <= 475)
{x=mouseX;}
}
fill(127,0,0);
rect (x, 20, 9, 60);
fill (255);
// Left Button
fill (200);
rect (10, 25, 50, 50);
{
if (mousePressed == true) {
if (mouseX <= 50 && (mouseY >= 40 && mouseY <= 60)) {
fill(255);
if (x>100){
x-=20;
} else {
x=75;
}
} else {
fill(0);
}
}
if (mousePressed == false) {
fill (0);
}
triangle (50, 60, 50, 40, 15, 50);
}
// Right button
fill (200);
rect (490, 25, 50, 50);
{
if (mousePressed == true) {
if (mouseX >= 500 && (mouseY >= 40 && mouseY <= 60)) {
fill(255);
if (x<470){
x+=20;
}
else {
x=470;
}
} else {
fill(0);
}
}
if (mousePressed == false) {
fill (0);
}
triangle (500, 60, 500, 40, 535, 50);
}
println(x);
line (115, 60, 115, 90);
line (155, 60, 155, 90);
line (195, 60, 195, 90);
line (235, 60, 235, 90);
line (275, 60, 275, 90);
line (315, 60, 315, 90);
line (355, 60, 355, 90);
line (395, 60, 395, 90);
line (435, 60, 435, 90);
}
How can I make my slider discrete using Processing? Here is my code. I need to make it discrete with values from 0-10. I already put some line indicators, what I only need is to make it discrete. Can you give me an idea of how to do it?
So far, all we have made right now are continuous sliders, and the thumb travels very smoothly. How can we add steps to the same slider to make a discrete slider? Here is an example of the same slider but with 10 steps instead of returning every value in between.
int x=75;
void setup() {
size(600,400);
}
void draw() {
background(100);
fill (200);
rect (75, 25, 400, 50);
stroke(0);
if(mousePressed) {
if (mouseX >75 && mouseX <= 475)
{x=mouseX;}
}
fill(127,0,0);
rect (x, 20, 9, 60);
fill (255);
// Left Button
fill (200);
rect (10, 25, 50, 50);
{
if (mousePressed == true) {
if (mouseX <= 50 && (mouseY >= 40 && mouseY <= 60)) {
fill(255);
if (x>100){
x-=20;
} else {
x=75;
}
} else {
fill(0);
}
}
if (mousePressed == false) {
fill (0);
}
triangle (50, 60, 50, 40, 15, 50);
}
// Right button
fill (200);
rect (490, 25, 50, 50);
{
if (mousePressed == true) {
if (mouseX >= 500 && (mouseY >= 40 && mouseY <= 60)) {
fill(255);
if (x<470){
x+=20;
}
else {
x=470;
}
} else {
fill(0);
}
}
if (mousePressed == false) {
fill (0);
}
triangle (500, 60, 500, 40, 535, 50);
}
println(x);
line (115, 60, 115, 90);
line (155, 60, 155, 90);
line (195, 60, 195, 90);
line (235, 60, 235, 90);
line (275, 60, 275, 90);
line (315, 60, 315, 90);
line (355, 60, 355, 90);
line (395, 60, 395, 90);
line (435, 60, 435, 90);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决您的问题的方法不同:
最简单的实现是将矩形绘制到正确的位置,但像您已经一样存储X值。
标签在滑块中的位置是:
然后只需在正确的位置绘制RECT即可;
第二个选项将存储
CurrentStep
,而不是您已经存储的X
。您的按钮将必须增加或减少CurrentStep
而不是X
。然后,您还必须按照我已经显示的,必须计算correctedPos
。There are different approaches to your problem:
The easiest implementation would be drawing the rectangle to the correct position but storing the x value as you already do.
The position of your label in the slider is:
Then just draw the rect at the correct position;
The second option would be storing the
currentStep
and not thex
that you already store. Your buttons will have to increment or decreasecurrentStep
instead ofx
. Then you will also have to calculate thecorrectedPos
as I have already shown.