# Change scale based on position y

**URL:** <https://discourse.processing.org/t/change-scale-based-on-position-y/24635>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [October 16, 2020, 5:23am UTC](https://discourse.processing.org/t/change-scale-based-on-position-y/24635 "2020-10-16T05:23:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ljna227](https://avatars.discourse-cdn.com/v4/letter/l/50afbb/32.png) [@ljna227](https://discourse.processing.org/u/ljna227)\
**Post date:** [October 16, 2020, 5:23am UTC](https://discourse.processing.org/t/change-scale-based-on-position-y/24635/1 "2020-10-16T05:23:43Z")

</div>

I managed to make trees pop up in random locations on the screen. But I have to change the scale based on the y position of the trees. As the tree pop up lower in the screen, it should be bigger and fewer compared to the trees that is on the top of the screen where the trees are smaller and more.  
`Preformatted text`  
void setup(){  
size(1600,1000);  
noStroke();  
frameRate(10);  
}  
void draw(){

float x=random(width);  
float y=random(height);  
translate(x,y);  
print(frameCount);  
tree();  
}  
void trunk(){  
fill(#673F34);  
rectMode(CENTER);  
rect(150,550,80,100);  
}  
void tree(){  
body(40,50);  
trunk();  
decoration(25,50, random(10,20), random(10,20));  
}  
void body(int x, int y){  
fill(0,255,0);  
for (int n=0; n\<4;n=n+1){  
triangle(n_x, 500-n_y, 150,400-n_y, 300-n_x, 500-n_y);  
}  
/_  
triangle(0,500,150,400,300,500);  
triangle(x,500-y,150,400-y,300-x,500-y);  
triangle(2_x,500-2_y,150,400-2_y,300-2_x,500-2_y);  
triangle(3_x,500-3_y, 150,400-3_y,300-3_x,500-3_y);  
\*/  
}  
void decoration(int x, int y, float z, float k){

fill(255,0,0);  
for (int n=-1; n\<2; n+=1){  
ellipse(150, 400-n\*y,z,k);  
}  
/\*ellipse(150,400-y,z,k);  
ellipse(150,400,z,k);  
ellipse(150,400+y,z,k);  
_/  
for (int n=-1; n\<2; n+=1){  
ellipse(150-n_x,400,z,k);  
/_ellipse(150-x,400,z,k);  
ellipse(150,400,z,k);  
ellipse(150+x,400,z,k);_/  
}

ellipse(150-2_x,400+y,z,k);  
ellipse(150+2_x,400+y,z,k);  
}

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [October 16, 2020, 10:59am UTC](https://discourse.processing.org/t/change-scale-based-on-position-y/24635/2 "2020-10-16T10:59:47Z")

</div>

Hello,

Welcome.

Please format your code as a courtesy to the community:  
[https://discourse.processing.org/faq#format-your-code](https://discourse.processing.org/faq#format-your-code)

There are errors in your posted code because you did not format it.

`:)`
