0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

アスペクト比 計算

Posted at

アスペクト比に関しての計算

ちょっと特殊な編集があるので、思い出しながらメモしておきます。

まずはアスペクト比の計算方法

var width = 120;
var height = 112;

//最大公約数を求める
function gcd(x, y){
  if(y === 0) return x
  return gcd(y, x % y)
 }

var num = gcd (width,height);
$.writeln("最大公約数:"+num)
$.writeln("アスペクト比:"+width/num+":"+height/num)
//結果
最大公約数:8
アスペクト比:15:14

アスペクト比で計算する方法

幅のみ決まっている場合

//15:14の比率として
var width = 120;
var hiritsu1 = 15;
var hiritsu2 = 14;

$.writeln("高さ:"+(width*hiritsu2)/hiritsu1)
//結果
高さ:112

高さのみ決まっている場合

//15:14の比率として
var height = 112;
var hiritsu1 = 15;
var hiritsu2 = 14;

$.writeln("幅:"+(height*hiritsu1)/hiritsu2)
//結果
幅:120
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?