Anyone can help me with scaling?

Sorry my eng not that good.
So i created pattern with my own function and than used loop (i think u dont understand so just try my code)

float a=0.0;
int x = -20;
int y = -20;
int rad = 50;
int dod = 50;
void setup() {
  size(500, 500);
}
void draw() {
  noFill();

  while (x>520);
  {
    drawPattern(x, y, rad, rad);
    drawPattern(x, 30, rad, rad);
    drawPattern(x, 80, rad, rad);
    drawPattern(x, 130, rad, rad);
    drawPattern(x, 180, rad, rad);
    drawPattern(x, 230, rad, rad);
    drawPattern(x, 280, rad, rad);
    drawPattern(x, 330, rad, rad);
    drawPattern(x, 380, rad, rad);
    drawPattern(x, 430, rad, rad);
    drawPattern(x, 480, rad, rad);
    x=x+50;
  }
}
void drawPattern(int x, int y, int rad, int rad2) {
  strokeWeight(2);
  ellipseMode(CORNER);
  stroke(0, 0, 255);
  ellipse(x, y, rad, rad);
  ellipseMode(CENTER);
  stroke(255, 0, 0);
  rect(x, y, rad, rad);
  stroke(0, 255, 0);
  ellipse(x+50, y+50, rad/2, rad2/2);
}

SOOO now i need to Increase the initial size of the pattern until
the radius will not be 4 times larger than the original

this is an example of how my pettern should move

int x = -20;
int y = -20;
int rad = 50;
float a=0.0;
void setup() {
  size(500, 500);
}
void draw() {
  noFill();
  background(0);
  translate(0, 0);
  scale(sin(a) + 2);
  strokeWeight(2);
  ellipseMode(CORNER);
  stroke(0, 0, 255);
  ellipse(x, y, rad, rad);
  ellipseMode(CENTER);
  stroke(255, 0, 0);
  rect(x, y, rad, rad);
  stroke(0, 255, 0);
  ellipse(x+50, y+50, rad/2, 25);
  a += 0.1;
}

i hope u will help me

1 Like

Hello,

If you want to see what your original code is doing add this to setup():
frameRate(1); // Slows things down for debugging or as needed

And add this to your while() loop:
println(frameCount, x); //Prints to console

Consider:

  • Adding background() to draw()
  • Replacing the while() loop with a for() loop to increment x or a do while() loop
  • Using a nested for() loop for x and y; see references and last example.
  • map() and mouseX() are useful for interaction and I often use this for code development; move the mouse and change a value!
    See examples in references.

References:

You are a beginner so take it one step at a time.

:)

1 Like

Thanks, now i understand how i can make my pattern bigger, but i also need to return it to its original position (rad=50)


int x = -20;
int y = -20;
int rad = 50;
void setup() {
  frameRate(10);
  size(500, 500);
}
void draw() {
  background(200);
  noFill();
  stroke(random(500), random(500), random(500));
  if (rad<200) {
    rad= rad+1;
  }
  for (int x = -20; x<520; x=x+50)
  {
    println(frameCount, x);
    drawPattern(x, y, rad, rad);
    drawPattern(x, 30, rad, rad);
    drawPattern(x, 80, rad, rad);
    drawPattern(x, 130, rad, rad);
    drawPattern(x, 180, rad, rad);
    drawPattern(x, 230, rad, rad);
    drawPattern(x, 280, rad, rad);
    drawPattern(x, 330, rad, rad);
    drawPattern(x, 380, rad, rad);
    drawPattern(x, 430, rad, rad);
    drawPattern(x, 480, rad, rad);
  }
}
void drawPattern(int x, int y, int rad, int rad2) { 
  strokeWeight(2);
  ellipseMode(CORNER);
  ellipse(x, y, rad, rad);
  ellipseMode(CENTER);
  rect(x, y, rad, rad);
  ellipse(x+50, y+50, rad/2, rad2/2);
}

i was trying to do something else with If but it doesn’t help me :cry:

Hello,

Consider an if/else statement:

  if (rad<200) 
    {
    rad = rad+10; //Speed it up a bit
    }
  else
    rad = ?; // What should rad be set to?

Reference:
else \ Language (API) \ Processing 3+

There are other ways to do this also…

:)