# I need help with my code(scale problem)

**URL:** <https://discourse.processing.org/t/i-need-help-with-my-code-scale-problem/25388>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [November 13, 2020, 8:00am UTC](https://discourse.processing.org/t/i-need-help-with-my-code-scale-problem/25388 "2020-11-13T08:00:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fungineer1](https://avatars.discourse-cdn.com/v4/letter/f/ee7513/32.png) [@Fungineer1](https://discourse.processing.org/u/Fungineer1)\
**Post date:** [November 13, 2020, 8:00am UTC](https://discourse.processing.org/t/i-need-help-with-my-code-scale-problem/25388/1 "2020-11-13T08:00:31Z")

</div>

> please format code with \</\> button \* [homework policy](https://discourse.processing.org/faq/#homework) \* [asking questions](https://discourse.processing.org/t/2147)

So I was working on my code, which is to draw three bees, and each time they bounce on to wall or hive, they would bounce back(aka change their direction), while I have done that without any problem, I was trying to apply scale function, where they would increase the size depend on number generated randomly from 2-4. And I used scale() function, but the problem is that it also changed the beginning location of bee, and for some reason, they don’t bounce back. I have been working on it for good few hours, and still can’t figure out why can anyone help me with this problem?

Here is the code I used:  
void setup() {  
size(800, 800);  
beeX1 = width/2; beeY1=height/2;  
beeX2 = width/2; beeY2=height/2;  
beeX3 = width/2; beeY3=height/2;  
combX = width_2/3; combY = height_2/3;  
}  
float beeX1, beeY1;  
float beeX2, beeY2;  
float beeX3, beeY3;  
int beeDX1=1, beeDY1=1;  
int beeDX2=-1, beeDY2=1;  
int beeDX3=1, beeDY3=-1;  
int count=0;  
float combX, combY;  
boolean bCrash1=false, bCrash2=false, bCrash3=false;  
int r1=int(random(2,5));  
int r2=1;//int(random(2,4));  
int r3=1;//int(random(2,4));  
void draw() {  
background(200, 250, 50);

drawHoneycomb(combX, combY, count);

beeX1+=2_beeDX1;  
if(beeX1+20\>width || beeX1-20\<0) {beeDX1 = -beeDX1; bCrash1=false;}  
beeY1+=3_beeDY1;  
if(beeY1+20\>height || beeY1-20\<0) {beeDY1 = -beeDY1; bCrash1=false;}  
drawBee(beeX1, beeY1,r1);

beeX2+=2_beeDX2;  
if(beeX2+20\>width || beeX2-20\<0) beeDX2 = -beeDX2;  
beeY2+=1_beeDY2;  
if(beeY2+20\>height || beeY2-20\<0) beeDY2 = -beeDY2;  
drawBee(beeX2, beeY2,r2);

beeX3+=3_beeDX3;  
if(beeX3+20\>width || beeX3-20\<0) beeDX3 = -beeDX3;  
beeY3+=2_beeDY3;  
if(beeY3+20\>height || beeY3-20\<0) beeDY3 = -beeDY3;  
drawBee(beeX3, beeY3,r3);

if(beeY1+20 \> combY-40 && beeY1-20 \< combY+40 && beeX1+20 \> combX-40 && beeX1-20 \< combX+40 ) {  
beeDX1 = -beeDX1;  
beeDY1 = -beeDY1;  
count++;  
}  
if(beeY2+20 \> combY-40 && beeY2-20 \< combY+40 && beeX2+20 \> combX-40 && beeX2-20 \< combX+40 ) {  
beeDX2 = -beeDX2;  
beeDY2 = -beeDY2;  
count++;  
}  
if(beeY3+20 \> combY-40 && beeY3-20 \< combY+40 && beeX3+20 \> combX-40 && beeX3-20 \< combX+40 ) {  
beeDX3 = -beeDX3;  
beeDY3 = -beeDY3;  
count++;  
}

}

void drawBee(float bx, float by, int scale) {  
pushMatrix();  
scale(scale);  
fill(255, 255, 0);  
ellipse(bx, by-15, 12, 6);  
fill(0);  
ellipse(bx, by-10, 8, 4);  
fill(255, 255, 0);  
ellipse(bx, by+3, 16, 22);  
triangle(bx-2, by+14, bx+2, by+14, bx, by+20);  
fill(0);  
ellipse(bx-4, by-16, 4, 4);  
ellipse(bx+4, by-16, 4, 4);  
arc(bx-6, by-18, 8, 4, radians(270), radians(360));  
arc(bx+6, by-18, 8, 4, radians(180), radians(270));  
fill(0);  
rect(bx-6, by-4, 12, 2);  
rect(bx-8, by+2, 16, 2);  
rect(bx-6, by+8, 12, 2);  
fill(150,200, 255);  
ellipse(bx-12, by-4, 16, 8);  
ellipse(bx-12, by+3, 16, 10);  
ellipse(bx+12, by-4, 16, 8);  
ellipse(bx+12, by+3, 16, 10);  
popMatrix();  
}

void drawHoneycomb(float hx, float hy, int count) {  
int maxX=3, maxY=6;  
for(float j=0; j\<maxY; j++) {  
for(float i=0; i\<maxX; i++) {  
// 역삼각형  
fill(255, 255, 255-count_50);  
triangle(hx-maxX/2_20+i_20-(j+1)%2_10, hy-maxY/2_20+j_20, hx-maxX/2_20+i_20+10-(j+1)%2_10, hy-maxY/2_20+j_20+20, hx-maxX/2_20+i_20+20-(j+1)%2_10, hy-maxY/2_20+j_20);  
}  
if(j \< maxY/2) maxX++;  
else maxX–;  
for(float i=0; i\<maxX; i++) {  
// 정삼각형  
fill(255, 255, 255-count_5);  
triangle(hx-maxX/2_20+i_20-j%2_10, hy-maxY/2_20+j_20+20, hx-maxX/2_20+i_20+10-j%2_10, hy-maxY/2_20+j_20, hx-maxX/2_20+i_20+20-j%2_10, hy-maxY/2_20+j_20+20);  
}  
}

}`Preformatted text`

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [November 14, 2020, 8:06am UTC](https://discourse.processing.org/t/i-need-help-with-my-code-scale-problem/25388/2 "2020-11-14T08:06:04Z")

</div>

> [@Fungineer1](#):
>
> please format code with \</\> button \* [homework policy](https://discourse.processing.org/faq/#homework) \* [asking questions](https://discourse.processing.org/t/2147)

Hi @Fungineer1 Welcome to the forum.  
Please edit your post above by clicking on the pencil.  
Then select all your code and click on the \</\> button in the editing box.  
To scale the bee you’ll first have to [make a shape of the whole bee](https://processing.org/reference/PShape_addChild_.html), and then apply the scale() function on that shape in draw().
