# Math with Colors

**URL:** <https://discourse.processing.org/t/math-with-colors/3847>\
**Category:** Coding Questions\
**Created:** [September 26, 2018, 3:27am UTC](https://discourse.processing.org/t/math-with-colors/3847 "2018-09-26T03:27:28Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![Turbo012](https://avatars.discourse-cdn.com/v4/letter/t/e9bcb4/32.png) [@Turbo012](https://discourse.processing.org/u/Turbo012)\
**Post date:** [September 27, 2018, 8:08am UTC](https://discourse.processing.org/t/math-with-colors/3847/15 "2018-09-27T08:08:59Z")

</div>

I believe this is the end result of the color test. It turned out pretty well. Thank you everyone.

```auto
int maxColor = 255;
float hue = maxColor;
float sat = maxColor;
float bright = maxColor;
int scale = 4;
int widthWin = 1280;
int heightWin = 800;
int penColor = 0;
int grad = 1;

void setup() {
  //size(width, height);
  surface.setSize(widthWin, heightWin);
  colorMode(HSB);
  background(192, 64, 0);
}

void draw() {
  stroke(penColor, sat, maxColor);
  line(width/2, height/2, mouseX, mouseY);
  println ("Color: " + (mouseX/float(widthWin))*maxColor + " , " + sat, " , " + (mouseY/float(heightWin))*maxColor);
  penColor += grad;
  if (penColor > 255) {
    penColor = 255;
    grad = -1;
  } else if (penColor < 0) {
    penColor = 0;
    grad = 1;
  }
}

void mousePressed() {
  if (mouseButton == CENTER) {
  background(192, 64, 0);
  }
}

void mouseDragged() {
  if (mouseButton == LEFT) {
    sat--;
    if (sat < 0) sat = 0;
  } else if (mouseButton == RIGHT) {
    sat++;
    if (sat > 255) sat = 255;
  }
}

```

---

_[View the full topic](https://discourse.processing.org/t/math-with-colors/3847)._
