How to rotate pixels based on other light values?

Hi everybody, I am new to coding.

Given this code example, how can I rotate pixels based on other light values?
Do I need to define 3 different brightness values?

In this code example, there is this brightness(_c) inside the rotate function.
I would like to rotate pixels based on “darkness(_c)” and “midness(_c)”.

Even if “darkness(_c)” and “midness(_c)” were already defined, as brightness is, I don´t think I would use it in this way:

rotate((2 * PI * brightness(_c) / 255.0));
rotate((2 * PI * darkness(_c) / 255.0));
rotate((2 * PI * midness(_c) / 255.0));

So, I don’t know how to create this but my idea would be something like this:

While the light value of the pixels is > or = a, rotate all a
While the light value of the pixels is > or = b, rotate all b
While the light value of the pixels is > or = c, rotate all c

ps: I am using (_c) because if I use © <----- I get this symbol

Here is the code:



// Size of each cell in the grid
int cellSize = 20;
// Number of columns and rows in our system
int cols, rows;
// Variable for capture device
Capture video;

void setup() {
  size(640, 480);
  cols = width / cellSize;
  rows = height / cellSize;
  colorMode(RGB, 255, 255, 255, 100);

  // This the default video input, see the GettingStartedCapture 
  // example if it creates an error
  video = new Capture(this, width, height);

  // Start capturing the images from the camera
   void draw() { 
     if (video.available()) {;

    // Begin loop for columns
    for (int i = 0; i < cols; i++) {
      // Begin loop for rows
      for (int j = 0; j < rows; j++) {
        // Where are we, pixel-wise?
        int x = i*cellSize;
        int y = j*cellSize;
        int loc = (video.width - x - 1) + y*video.width; // Reversing x to mirror the image
        float r = red(video.pixels[loc]);
        float g = green(video.pixels[loc]);
        float b = blue(video.pixels[loc]);
        // Make a new color with an alpha component
        color c = color(r, g, b, 75);
        // Code for drawing a single rect
        // Using translate in order for rotation to work properly
        translate(x+cellSize/2, y+cellSize/2);
        // Rotation formula based on brightness
        rotate((2 * PI * brightness(c) / 255.0));
        // Rects are larger than the cell for some overlap
        rect(0, 0, cellSize+6, cellSize+6);

Hi! looks like an interesting approach. Could you explain what a, b, c in your text mean, so we know the idea a bit better? If it’s hard to explain you can also draw and embed the image/photo of it :slight_smile:

Hi micuat, thank you for your reply.

A would mean Brightness(); B would mean “MediumLight()”; and C would mean “Darkness()”; which I need to define somehow. Instead of having rotations on only the brightest pixels, I would like to rotate all values of light.

If I do this -----> rotate((2 * PI * © / 255.0)); ----> without the brightness parameter,
I can rotate all the pixels but not in the way I would like.
I’ve attached an example for your reference. I would like to replicate the rotation that happens in the brightest areas (A) in B and C.

Screen Shot 2021-03-07 at 2.15.57 AM

Thanks for the image. That is a good reference because it makes me wonder what you mean by “rotation”. rotate is a function to literally rotate the shape, like putting a pin on a shape and the canvas. But if you are also referring to the swirl effect, you cannot achieve it only with rotate. For example

1 Like

Thank you for your time :slight_smile:

For now, I can´t foresee the problem of the swirling effect, but I appreciate the reference.
I guess I need to simplify the problem first, otherwise can´t handle it.

Just related to light values:
How to create a parameter to work like this: “darkness(_c)”, how to get those pixels? and how to use their values after?

I´ve been trying by means of code what would mean a,b,c as your suggestion.
I guess I need to constrain those 3 values below in order to have a value between (0-85); (85-170); (170-255);???

float value1 = brightness(c)-85;
float value2 = brightness(c)-170;
float value3 = brightness(c)-255;

if (((c) == value1) || ((c) != value2) || ((c) != value3) ) {
  rotate((2 * PI * value1 / 255.0));

if (((c) == value2) || ((c) != value1) || ((c) != value3) ) {
  rotate((2 * PI * value2 / 255.0));

if (((c) == value3) || ((c) != value1) || ((c) != value2) ) {
  rotate((2 * PI * value3 / 255.0));

This might sound comic, but already seeing some changes… but I know by the prints that the values are not correct (they are not between the values I need).

Thank you once again.