YUVで色を作るソフト Software to make colors with YUV
YUVの数字を変えるとどうなるか、チンプンカンプンのKOHAママのために、KOHA兄が5分??で作ったソフトを紹介します。
What will happen if you change the number of YUV, for KOHA mom , KOHA made with 5 minutes. I will introduce the software .
Download zip file here ↓
ソースコードは、こちら↓Source code is here
color rgb(float y, float cr, float cb) { float[] o = {0, 0, 0}; o[0] = y+(cr*1.402); o[1] = y-(cr*0.714)-(cb*0.344); o[2] = y+(cb*1.772); /* R = Y+1.402Cr G = Y-0.714Cr-0.344Cb B = Y+1.772Cb */ return color(o[0], o[1], o[2]); } float y = 0.5; float u; float v; void setup() { size(800, 400); noStroke(); background(0, 255, 0); PFont font = loadFont("font.vlw"); textFont (font); // 選択したフォントを指定する } int mode = 0; void draw() { background(rgb((y*512)-128, (v*255)-128, (u*255)-128)); if (keyPressed) { if (key == 'y') { mode = 0; } if (key == 'u') { mode = 1; } if (key == 'v') { mode = 2; } } fill(0); String t = ""; if (keyPressed) { if (keyCode == UP) { if (mode == 0) { y += 0.01; } if (mode == 1) { u += 0.01; } if (mode == 2) { v += 0.01; } } if (keyCode == DOWN) { if (mode == 0) { y -= 0.01; } if (mode == 1) { u -= 0.01; } if (mode == 2) { v -= 0.01; } } } if (mode == 0) { t = "y"; } if (mode == 1) { t = "u"; } if (mode == 2) { t = "v"; } text("mode:"+t, 0, 48); text("y:"+nf(y,1,3), 0, 48*2); text("u:"+nf(u,1,3), 0, 48*3); text("v:"+nf(v,1,3), 0, 48*4); if(y < 0)y = 0; if(y > 1)y = 1; if(u < 0)u = 0; if(u > 1)u = 1; if(v < 0)v = 0; if(v > 1)v = 1; }
え?もうこんなに書いたの?
とにかく、あっという間に打ち込み完了。
そもそも、YUVとは、何なのか?は、ウィキペディアを見てください。
“Huh? Did you write it so much?”
Anyway, it was completed quickly.
In the first place, what is YUV? Please look at Wikipedia.
ウィキペディアより⇩
https://ja.wikipedia.org/wiki/YUV
From Wikipedia ⇩
動画で、Yの数字を1に近づけると白に、0に近づけると黒になります。
0.5は、灰色です。
で、Yが0.5・・・つまり程よい中間の明るさだった場合、
Uを上のカラー図のX軸と考えます。Uを下げると緑っぽくなり、Uを上げれば青っぽくなる。
Vは、Y軸と考えます。Vを下げればやはり緑っぽくなり、上げれば赤っぽくなります。
このY(明るさ)、U(X軸)、V(Y軸)の組み合わせで、画面の色が表示できるらしいです。
In a movie, when Y number approaches 1, it becomes white, when it approaches 0, it turns black.
0.5 is gray.
, Y is 0.5 … … that is, when the brightness is moderately intermediate,
Consider U as the X axis of the color diagram above. Lowering U will make it greenish, and raising U will make it blue.
V is considered to be the Y axis. After all, if you lower V, it becomes greenish, and if you raise it it will be reddish.
The combination of Y (brightness), U (X axis) and V (Y axis) seems to be able to display the color of the screen.
Pictorial drawing of KOHA
動画です。⇩ on YouTube
少しだけ、意味がわかったKOHAママです。
Only a little, KOHA mom knows the meaning.