搜索器或价值栏未折断?

问题描述 投票:0回答:1

我目前正在为学校做一个项目,遇到了一个问题。我目前正在为该项目使用Processing.exe。滑块似乎无法折断。我尝试遵循类似的问题及其答案,但我似乎仍然无法使其发挥作用。当我单击放置箭头的框时,滑块会捕捉到该值,但如果我按箭头本身,它不会捕捉到。当它卡住时,滑块似乎也没有与导轨正确对齐。我做错了什么?

很乱,但这是代码:

int x=75;
int lsW=17;
int lsH=50;
float bx =17;
float by = 25;
int boxSize = 50;
float xOffset = 0.0; 
float yOffset = 0.0;
float sbx = 483;
float sby = 25;
int sboxSize = 50;
float sxOffset = 0.0; 
float syOffset = 0.0;  

void setup() {
      size(550,300);
    }
void mousePressed() {
    if (mouseX > bx-boxSize && mouseX < bx+boxSize && 
        mouseY > by-boxSize && mouseY < by+boxSize) {  
        if (x > 75) {
            x = ((x+39 - 75) / 40) * 40 + 75;
            x -= 40;
        }
    }
    if (mouseX > sbx-sboxSize && mouseX < sbx+sboxSize && 
        mouseY > sby-sboxSize && mouseY < sby+sboxSize) {
        if (x < 475) {
            x = ((x - 75) / 40) * 40 + 75;
            x += 40;
        }
    }
}    
    void draw() {
      background(50);
      strokeWeight(0);
      fill (200);
      rect (75, 25, 400, 50);
      stroke(0);
  float value = map(x, 75, 475, 0, 100);      
      if(mousePressed) {
      if (mouseX >75 && mouseX <= 475)
        {x=mouseX;}
        }
      fill(0,255,255);
      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, 70, 50, 30, 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, 70, 500, 30, 535, 50);
    }
      println(x);
      {
        strokeWeight(2);
        stroke(255, 0 , 0);
      line (115, 60, 115, 85);
      line (155, 60, 155, 85);
      line (195, 60, 195, 85);
      line (235, 60, 235, 85);
      line (275, 60, 275, 85);
      line (315, 60, 315, 85);
      line (355, 60, 355, 85);
      line (395, 60, 395, 85);
      line (435, 60, 435, 85);
      }
    }
slider processing
1个回答
0
投票

以下演示应正确校准;当条形图位于刻度线中央时,值应增加 10。当长按向左箭头时,它应显示值 0;当长按右箭头时,它应显示值 100。为了简化,刻度线代码已更改为“for”循环。

int x = 75;
int lsW = 17;
int lsH = 50;
float bx = 17;
float by = 25;
int boxSize = 50;
float sbx = 483;
float sby = 25;
int sboxSize = 50;
float sxOffset = 0.0;
float syOffset = 0.0;

void setup() {
  size(550, 300);
}

void draw() {
  background(50);
  // Box
  stroke(0);
  fill (200);
  rect (75, 25, 400, 50);
  float value = map(x, 75, 475, 0, 100);
  if (mousePressed) {
    if (mouseX >75 && mouseX <= 475) {
      x = mouseX;
    }
  }
  // Bar
  fill(0, 255, 255);
  rect (x-5, 20, 10, 60); // To center bar
  fill (255);
  // Left Arrow
  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, 70, 50, 30, 15, 50);
  // Right Arrow
  fill (200);
  rect (490, 25, 50, 50);
  if (mousePressed == true) {
    if (mouseX >= 500 && (mouseY >= 40 && mouseY <= 60)) {
      fill(255);
      if (x<475) {
        x+=20;
      } else {
        x=475;
      }
    } else {
      fill(0);
    }
  }
  if (mousePressed == false) {
    fill (0);
  }
  triangle (500, 70, 500, 30, 535, 50);
  println("x = ",x + " : " + "value = ",value); 
  // tick marks
  strokeWeight(2);
  stroke(255, 0, 0);
  for(int x= 1; x < 10; x++){
    line(75 + 40*x, 60, 75 + 40*x, 85);
  }
 
}

void mousePressed() {
  if (mouseX > bx-boxSize && mouseX < bx+boxSize && mouseY > by-boxSize && mouseY < by+boxSize) {
    if (x > 75) {
      x = ((x+39 - 75) / 40) * 40 + 75;
      x -= 40;
    }
  }
  if (mouseX > sbx-sboxSize && mouseX < sbx+sboxSize && mouseY > sby-sboxSize && mouseY < sby+sboxSize) {
    if (x < 475) {
      x = ((x - 75) / 40) * 40 + 75;
      x += 40;
    }
  }
}


© www.soinside.com 2019 - 2024. All rights reserved.