p5 with Polar Coordinates - 如何在不反转方向的情况下向内螺旋

p5 with Polar Coordinates- how to spiral inwards without reversing direction

let circ1;
let circ2;

function setup() {
  createCanvas(400, 400);
  circ1 = new Circle(width/2, height/2, 200)
  // circ2 = new Circle(100, 100, 0)
}

function draw() {
  background(220);
  circ1.update();
  circ1.show();
  // circ2.update();
  // circ2.show();
}

function Circle(w,h,dim){
  this.scalar = 0;
  this.dim = dim;
  this.theta = 0;
  this.pos = createVector(w,h)
  this.booler = false;
  
  this.update = function(){
    this.pos.x = this.dim + sin(this.theta) * this.scalar
    this.pos.y = this.dim + cos(this.theta) * this.scalar
      
    push();
    fill(255,0,0);
    circle(this.theta,this.scalar,10)
    pop();
    line(this.theta,this.scalar,this.dim,this.dim)
    circle(this.dim,this.dim, 10)

    if(this.theta > 50){
      this.booler = true;
    }
    if (this.theta < 1){
      this.booler = false;
    }
    
    let d = dist(this.pos.x,this.pos.y,this.dim,this.dim)
    let force = map(d, 0,100, 0.1,0.01)
    
    if(this.booler){
      this.center(force);
    } else {
      this.decenter(force);
    }
  }
  
  this.decenter = function(force){
    this.theta += force;
    this.scalar += force;
  }
  
  this.center = function(force){
    this.theta -= force;
    this.scalar -= force;
  }
  
  this.show = function(){
    circle(this.pos.x,this.pos.y,30)  
  }
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
    <script src="https://cdn.jsdelivr.net/npm/p5@1.3.1/lib/p5.js"></script>
</body>
</html>

这是一个非常数学的问题,所以如果它应该放在另一个论坛上,请告诉我。 我的问题在 this sketch。 我想要的是螺旋向内(或向外)移动而不改变方向。

我正在 (posX,posY) 处画一个圆。

posX = screenWidth/2 + sin(theta) * 标量,

posY = screenHeight/2 + cos(theta) * 标量,

我通过减小 theta 和标量的值并增加相反的值来创建顺时针(向内)。但这只是螺旋的“绕”和“倒”,而不是收缩和增长。

为避免反转方向,即使在减少 scalar:

时也总是增加 theta
  this.decenter = function(force){
    this.theta += force;
    this.scalar += force;
  }
  
  this.center = function(force){
    // If you start decreasing theta you will be reversing the direction of rotation.
    this.theta += force;
    this.scalar -= force;
  }