Deforming a shape with increasing values toward the X axis

Hi all.

I am working on this sketch where I am trying to simulate the inner circles of the tree trunk with a proximity sensor connected to Arduino whose values determine the width of these circles.

I wanted to ask if there is a way to make some points of the shape change as it increases on the X-axis.

So that it is not just a simple "scale* as in the code example below but that there is a parameter that progressively alters the shape the more you go toward the horizontal direction.

Thank you for your response!

import processing.serial.*;

int lf = 10;    // Linefeed in ASCII
String myString = null;
Serial myPort;  // The serial port

int startTime; 

void setup(){
  size(1000,1000);
  background(0);
  stroke(255, 10);
  noFill();
  noLoop();
  
  startTime = millis(); 

  myPort = new Serial(this, "COM4", 9600);
  myString = myPort.readStringUntil(lf);
  myString = null;
}

void draw(){
  while (myPort.available() > 0) 
  {
    myString = myPort.readStringUntil(lf);
    if (myString != null) 
    {
      println(myString);
    
      float centerX = 0;
      float centerY = 0;

      for (int i = 1; i <= 10; i++) {
        pushMatrix();
        scale(float(myString)/20);
        beginShape();
        curveVertex(centerX, centerY);
        curveVertex(centerX, centerY - 50);
        curveVertex(centerX - 30, centerY - 50);
        curveVertex(centerX - 50, centerY);
        curveVertex(centerX - 50, centerY + 50);
        curveVertex(centerX, centerY + 50);
        curveVertex(centerX + 50, centerY + 50);
        curveVertex(centerX + 50, centerY);
        curveVertex(centerX + 25, centerY - 25);
        curveVertex(centerX, centerY);
        endShape(CLOSE); 
        popMatrix();
      }

      if (millis() - startTime > 30000) { 
        background(0); 
        startTime = millis(); 
      }
    }
  }
}

void keyPressed() {
  loop();
}

Hi @michele_rinaldi, I copied your sketch, and because I don’t know what numbers are coming from your Arduino, I started with 1.0 then * 1.1 for each loop. It made quite a pleasing pattern.

image
Are you able to say in more detail what you want?
If you could post a version of your sketch with the input numbers as a file or preset array, and no serial, this would let anyone run it.

2 Likes

Hello @michele_rinaldi,

Like this?

:)

We can also say scale(x,y); so that we change both axis separately using 2 parameters

1 Like