# Zoom in a specific letter

**URL:** https://discourse.processing.org/t/zoom-in-a-specific-letter/9835
**Category:** Coding Questions
**Created:** [April 1, 2019, 1:12pm UTC](https://discourse.processing.org/t/zoom-in-a-specific-letter/9835 "2019-04-01T13:12:55Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![fwtini](https://avatars.discourse-cdn.com/v4/letter/f/9d8465/32.png) [@fwtini](https://discourse.processing.org/u/fwtini)
#### Post date: [April 1, 2019, 1:12pm UTC](https://discourse.processing.org/t/zoom-in-a-specific-letter/9835/1 "2019-04-01T13:12:55Z")

</div>

Hi Guys I want in the following code to zoom in a specific letter “3” and after to return back. Can I do it?

```auto
int w;
PFont myFont;
float x = 70;
float y = 6;
float theta = 0.0;  
float amplitude = 1000.0; 
float period =1.0;  

float[] yvalues; 

float xpos, ypos;
float xspeed= 0.0;
float yspeed = 0.0;
int xdirection = 10;
int ydirection = 10;
int rad =10;

int x1=100;
int dx=1;

void setup() {
  size(800,400);
  
  myFont = loadFont("Avenir-Medium-48.vlw");
  textFont(myFont);
  
  w = width+15;
 // dw = (TWO_PI / period) * xspacing;
  yvalues = new float[w/2];
  
  
  
  xpos= width/2;
  ypos = height/2;
  
  
  x1=x1+dx;
  if(x>width){
    dx = -1; 
  }
  if(x<0){
    dx = 1;
  }
}

void draw() {
  background(0);
  
xpos = xpos + (xspeed * xdirection);
ypos = ypos + (yspeed * ydirection);
  
calcWave();
renderWave();
  }

void calcWave() {
  
  theta += 1.0;

  float x = theta;
  for (int i = 0; i < yvalues.length; i++) {
    yvalues[i] = sin(x)*amplitude;
    x+=dx;
  }
}

void renderWave() {
  fill(255);
  // A simple way to draw the wave with an ellipse at each location
  for (int x = 0; x < yvalues.length; x++) {
    text("3",x*x+50, 100+yvalues[x], 800,400);
    
    
    
    
    
  if (xpos > width-rad || xpos < rad) {
    xdirection *= -1;
  }
  if (ypos > height-rad || ypos < rad) {
    ydirection *= -1;
     text("3",x*x, 400+yvalues[x], 300,300);
  }
  }
}

```

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [April 1, 2019, 1:31pm UTC](https://discourse.processing.org/t/zoom-in-a-specific-letter/9835/2 "2019-04-01T13:31:43Z")

</div>

? zoom = show bigger ? on what ?

```auto

float tsize = 10;
// ...
  textSize(tsize);

// ..
void keyPressed() {
  if ( key == '+' ) tsize++; 
  if ( key == '-' ) tsize--;   
}

```

---

<div class="post-metadata">

### Author: ![fwtini](https://avatars.discourse-cdn.com/v4/letter/f/9d8465/32.png) [@fwtini](https://discourse.processing.org/u/fwtini)
#### Post date: [April 1, 2019, 3:21pm UTC](https://discourse.processing.org/t/zoom-in-a-specific-letter/9835/3 "2019-04-01T15:21:53Z")

</div>

With no mousepressed. =/ Can I do it?

---

<div class="post-metadata">

### Author: ![humayung](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/humayung/32/6089_2.png) [@humayung](https://discourse.processing.org/u/humayung)
#### Post date: [April 3, 2019, 5:04pm UTC](https://discourse.processing.org/t/zoom-in-a-specific-letter/9835/4 "2019-04-03T17:04:40Z")

</div>

zooming?  
maybe you can use translate() pushMatrix() popMatrix() and scale()  
Good Luck!

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [April 3, 2019, 6:17pm UTC](https://discourse.processing.org/t/zoom-in-a-specific-letter/9835/5 "2019-04-03T18:17:58Z")

</div>

the 3 are moving fast.

How do you want to zoom? Stop the animation and then zoom in ?

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [April 3, 2019, 6:42pm UTC](https://discourse.processing.org/t/zoom-in-a-specific-letter/9835/6 "2019-04-03T18:42:14Z")

</div>

Example

```auto
// vars
PFont myFont;

float s=1; 
float x1, y1;

int phase=0;

int xStart, xStart2;

void setup() {
  size(1500, 500, P2D);
  background(0);

  x1=width/2;
  y1=height/2;

  xStart=width+8;
  xStart2=width+18;

  myFont = createFont("ARIAL", 34);
  textFont(myFont);
  textAlign(CENTER, CENTER);
  textMode(SHAPE);
}

void draw() {
  background(0);

  animateThree();

  text("3", 
    xStart2, y1-33);
  xStart2-=3;
}//draw

// ------------------------------------------------------------------------------

void animateThree() {

  pushMatrix(); 

  if (phase==0) {
    if (xStart>width/2) { 
      text("3", 
        xStart, y1);
      xStart-=3;
    } else
    {
      phase=1;
    }
  }
  // --- 
  else if (phase==1) {
    translate(x1, y1);
    scale (s);
    text("3", 
      0, 0);
    s+=.1;
    if (s>11) 
    {
      phase = 2;
    }
  }//if
  // ---
  else if (phase==2) {
    translate(x1, y1);
    scale (s);
    text("3", 
      0, 0);
    s-=.1;
    if (s<=1) 
    {
      phase = 3;
    }
  }//if
  // ---
  else if (phase==3) {
    if (xStart>-12) { 
      text("3", 
        xStart, y1);
      xStart-=3;
    } else phase=4;
  }//if
  // ---
  else if (phase==4) {
    // end
  }

  popMatrix();
}

void mousePressed() {
  //
}
//

```

---

<div class="post-metadata">

### Author: ![fwtini](https://avatars.discourse-cdn.com/v4/letter/f/9d8465/32.png) [@fwtini](https://discourse.processing.org/u/fwtini)
#### Post date: [April 4, 2019, 12:25pm UTC](https://discourse.processing.org/t/zoom-in-a-specific-letter/9835/7 "2019-04-04T12:25:06Z")

</div>

thaaank you!!!  
😀

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [April 6, 2019, 4:09pm UTC](https://discourse.processing.org/t/zoom-in-a-specific-letter/9835/8 "2019-04-06T16:09:48Z")

</div>

Good example with scale. There are several different approaches to “zoom” onto text:

1. change textSize – text is bigger, so appears closer – [https://processing.org/reference/textSize\_.html](https://processing.org/reference/textSize_.html)
2. change the rendering scale – everything (including text) gets bigger while scaled – [https://processing.org/reference/scale\_.html](https://processing.org/reference/scale_.html)
3. in 3D, move the camera closer to the text plane – [https://processing.org/reference/camera\_.html](https://processing.org/reference/camera_.html)
4. in 3D, use translate to move the text drawing plane closer to the camera – [https://processing.org/reference/translate\_.html](https://processing.org/reference/translate_.html)

Which approach works best depends on what your other goals for the sketch are – are there other objects, are there other camera motions, is it 3D et cetera.
