When using 'point' in processing, I have some issues

Hi all,

I currently have a 3d scanner implemented within the software. However, when I use stroke() with colour mode HSB to set the colour of a single point, it changes all the colours of all of my points. How do I change the colour of each individual point if I wanted to?

As for my current apllication I want there to be a colour range so that far away points are in one colour and close points are in another colour etc. So how can I plot each point individually to have there own unique colour?

My Current Code
A = (((SensorDistance) - (0))/(400 - (0)))*(255 - 0) + (0);
stroke(A, 255, 255);
point(v.x * scale + xOffset, -v.z * scale + yOffset, -v.y * scale);

It does work, as longer distances do change colours in the correct range but it changes the colours for all the points together which isn’t what I want it to do, I hope this is an easy fix.

Thanks in advance

1 Like

if SensorDistance is constant, A is constant and colors for all points at v same
if you want to influence color depending on
A AND v
might use
https://processing.org/reference/PVector_mag_.html

float vmag = map(v.mag(),min?,max?,0,1);
A = (((SensorDistance*vmag) - (0))/(400 - (0)))*(255 - 0) + (0);
stroke(A, 255, 255);
point(v.x * scale + xOffset, -v.z * scale + yOffset, -v.y * scale);
2 Likes

The sensor distance comes from a LIDAR sensor I am using as constanly has a different value.
I can plot the points in my 3D point cloud with no issues, but it’s just a different colour for each one of the newly plotted points is difficult, whenever the sensor distance value changes, all of the points change and are the same colour.

void draw() 
{
  String inputFromSensor = serial.readStringUntil(10);
  if (inputFromSensor != null)
  {
    String[] SerialData = split(inputFromSensor, '\t');
    if (SerialData.length == 5)
    {
      vectors.add(new PVector(float(SerialData[0]), float(SerialData[1]), float(SerialData[2])));
      SensorDistance = float(SerialData[3]);
      PointNumber = int(SerialData[4]);
    }
  }
  background(0);
  translate(width/2, height/2, -100);
  rotateY(yPlain);
  rotateZ(zPlain);
  rotateX(xPlain);
  int size = vectors.size();
  for (int index = 0; index < size; index++)
  {
    PVector v = vectors.get(index);
    if (index == size - 1)
    {
      stroke(0, 0, 255);
      line(xOffset, yOffset, 0, v.x * scale + xOffset, -v.z * scale + yOffset, -v.y * scale);
    }

    A = (((SensorDistance) - (0))/(400 - (0)))*(255 - 0) + (0);
    stroke(A, 255, 255);
    point(v.x * scale + xOffset, -v.z * scale + yOffset, -v.y * scale);
     
  }
  yPlain += yPlainIncrement;
  zPlain += zPlainIncrement;
  xPlain += xPlainIncrement;
  xOffset += xOffsetIncrement;
  yOffset += yOffsetIncrement;
  scale += scaleIncrement;
}
1 Like

you have a ?historical? list of v s
and the length of that ?growing? list size
but only the last SensorDistance ? why you not record that too?

so on what information you want change the color of the points of the v[i].xyz

above i was thinking it could only be the vector length v.mag
but not makes sense, what else? old to new? match size to 0 … 255.


other problem of HSB is that 0 and 255 both are RED

1 Like

I’ve figured it out now, using the map feature you suggested made the performance better.

I believe the error was down to my SensorDistance not correctly updating.
I am now using the HSB to 300 for a greater range as 300 is around pink, so the range is fine and the project seems to work as desired.

Thank you for the help, it was extremely helpful.

1 Like