需要帮助以某种方式扭转价值观

时间:2013-10-22 02:39:08

标签: 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);
  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 (ledGlow))时,我需要翻转这些值。因此,如果斜边是0,它实际上需要等于255,如果它是1,它需要是254,依此类推。我不知道如何处理这个问题。

1 个答案:

答案 0 :(得分:1)

你能否在那时从255减去斜边,以获得翻转的斜边值?

new_hypotenuse = 255 - hypotenuse ;
相关问题