Processing 需要帮助以某种方式反转值吗

Processing 需要帮助以某种方式反转值吗,processing,Processing,我有一个很奇怪的问题。我的代码中的一切都非常好,但我仍然有一个问题 import processing.serial.*; float r_height; float r_width; float hypotnuse; int d = 20; float x ; float y ; float ledGlow; Serial myPort; // Create object from Serial class void setup () { size (510, 510); St

我有一个很奇怪的问题。我的代码中的一切都非常好,但我仍然有一个问题

import processing.serial.*;

float r_height;
float r_width;
float hypotnuse;
int d = 20;
float x ;
float y ;
float ledGlow;
Serial myPort;  // Create object from Serial class

void setup () {

  size (510, 510);
  String portName = Serial.list()[8];
  myPort = new Serial(this, portName, 9600);
  background (0);
  fill(204);

  ellipseMode (CORNER);
  x = 0;
  y = 0;
  ellipse (x, y, d, d);
}

void draw () {

  r_height = mouseY - y;
  r_width =  mouseX - x;
  println ("Height is " + r_height);
  println ("Width is " + r_width);
  hypotnuse = sqrt (( (sq(r_height)) + (sq (r_width)) ) );
  ledGlow = round (hypotnuse/2.84);
  myPort.write(ledGlow);

  println (ledGlow);


  }

我需要从三角形的斜边得到0-255的值。但是当我将其写入串行端口
(myPort.write(ledlew))
时,我需要翻转这些值。所以如果斜边是0,它实际上需要等于255,如果它是1,它需要是254,依此类推。我不知道如何解决这个问题。

你能不能从255减去斜边,得到翻转的斜边值

new_hypotenuse = 255 - hypotenuse ;

你能不能用255减去斜边,得到翻转的斜边值

new_hypotenuse = 255 - hypotenuse ;

如果从0到255,你的意思是0应该切换到255,1应该切换到254吗?哦,我的道歉!是的,就是这样。如果从0到255,你的意思是0应该切换到255,1应该切换到254吗?哦,我的道歉!是的,就是这样。我怎么能忘记这样一个基本的把戏!!!!我会马上接受答案。没关系,我们有时都需要一些帮助:)@JoeT更一般的解决方案是函数。:)谢谢你们两位给我的精彩回答!我怎么能忘记这样一个基本的把戏!!!!我会马上接受答案。没关系,我们有时都需要一些帮助:)@JoeT更一般的解决方案是函数。:)谢谢你们两位给我的精彩回答!