Coding: Don't make mistakes when resizing objects! Kodai: Nedarykite klaidų, kai dydžio objektus! Preserve the initial ratio correctly! Išsaugoti pirminį santykis teisingai!
Posted on 17. Posted on 17. Jun, 2009 by Dragos in Coding Birželis, 2009 Dragos ir kodavimo
I was tempted many times to do quick adjustments to my code, without taking into consideration some basic mathematical principles. Aš daug kartų bandyti daryti greitai pakoreguoti savo kodu, neatsižvelgiant į kai kuriuos pagrindinius matematinius principus. For examples if a box is first of all 100px tall and 60px wide, and then I notice that this box does not fit the place where it was intended to be placed, what I did was to subtract 10 px from the width of the box, for it to fit some area, and at the same time I subtracted 10 px from the height also, thinking that doing so I kept the ratio of the initial sizes of the box. Pavyzdžius, jei langelis yra visų pirma 100px aukščio ir pločio 60px, ir tada aš pastebiu, kad šiame langelyje netelpa ten, kur jis turėjo būti įforminta, ką aš padariau buvo atimti 10 px iš laukelio plotį, kad jis atitiktų tam rajone, ir tuo pačiu metu aš atimama iš 10 px aukščio, galvoju, kad tai aš nuolat pradinio dydžio langelis santykis. In fact this is not true! Iš tiesų tai nėra tiesa!
Here's why: Štai kodėl:
The ratio of the initial box is 100px/60px=1.66 Pradinį dėžutė santykis 100px/60px = 1,66
In the second case the ratio is: (100px-10px)/(60px-10px)=1.8 Antruoju atveju šis santykis yra: (100px-10px) / (60px-10px) = 1,8
So, if you used to apply the same technique as I did to quickly resize objects, forget about it, as it's wrong! Taigi, jei naudojamas taikyti tą patį metodą, kaip aš greitai dydį objektų, pamiršti apie tai, kaip blogai! Instead use the old method from school to determine a variable from two fractions, preserving the ratios. Vietoje to naudokite seną metodą iš mokyklos, siekiant nustatyti kintamąjį iš dviejų dalių, išlaikant santykį. Back to the example above, in order to find out the new height value of the box I'd use this formula: 100px/60px=(100px-10px)/x, so x=60px*90px/100px=54px (instead of the incorrect value of 50px). Atgal į aukščiau pateiktą pavyzdį, siekiant išsiaiškinti naujus aukščio vertės langelyje Norėčiau naudoti šią formulę: 100px/60px = (100px-10px) / x, tai x = 60px * 90px/100px = 54px (vietoj neteisinga vertė 50 taškų). That's it! That's it!
No related posts. Nėra susijusių pranešimų.












































