リオのオリンピックの閉会式を見た人も多いと思います。色彩豊かで美しかったですね。メディア学部では、アニメを作るにも、ゲームを作るにも、映像制作にも、そして、広告やデザインにも色の作成は重要です。みなさんは、コンピュータで、好みの色を作れますか?今日は一緒に、「コンピュータ色水あそび」をしてみましょう。
コンピュータの中では、色は赤(R)、緑(G)、青(B)の光の3原色で表されます。それぞれの強さを0から1の間の数値で表し、RGBの値の組で1つの色が決まります。例えば、黒は[0,0,0]、白は[1,1,1]なのです。赤は[1,0,0]で表され、暗い赤は[0.5,0,0]などで表現できます。つまり、この組み合わせを自由に作れるようにすれば、どんな色でも作れるわけです!
Scilabのコンソールから以下を順次打ち込むか、「アプリケーション」メニューのところから呼び出せるエディタSciNotesを起動、プログラムを作成し名前を付けて保存、SciNotesの画面の「実行する」メニューから出力ありで実行してみてください。
//操作画面設定
h = figure( 'position' , [ 100 100 300 100 ] ) ;
set( h , 'figure_name' , 'RGBカラー' ) ;
//色表示窓
hcol = uicontrol( 'style' , 'edit' , 'position' , [ 200 10 80 80 ] ) ;
set( hcol , 'backgroundcolor' , [0,0,0] );
setc = [ ...
'r = get( hsr , ''value'' ) ; g = get( hsg , ''value'' ) ;' ...
'b = get( hsb , ''value'') ; set( hcol , ''backgroundcolor'' ,[ r g b ] );' ...
] ;
//R設定
htr = uicontrol( 'style' , 'text' , 'pos' , [ 10 70 20 20 ] , ...
'string' , 'R' ) ;
sr = ' set( hsr , ''value'' , strtod( get( her , ''string'' ) ) ) ; ' ;
her = uicontrol( 'style' , 'edit' , 'position' , [ 150 70 40 20 ] , ...
'call' , 'execstr(sr);execstr(setc);' ) ;
cr = ' set( her , ''string'' , string( hsr.value ) ) ; '
hsr = uicontrol( 'style' , 'slider' , 'pos' , [ 40 70 100 20 ] , ...
'min' , 0 , 'max' , 1 , 'call' , 'execstr(cr) ; execstr( setc ) ;' ) ;
//G設定
htg = uicontrol( 'style' , 'text' , 'pos' , [ 10 40 20 20 ] , ...
'string' , 'G' ) ;
sg = ' set( hsg , ''value'' , strtod( get( heg , ''string'' ) ) ) ; ' ;
heg = uicontrol( 'style' , 'edit' , 'position' , [ 150 40 40 20 ] , ...
'call' , 'execstr(sg);execstr(setc);' ) ;
cg = ' set( heg , ''string'' , string( hsg.value ) ) ; '
hsg = uicontrol( 'style' , 'slider' , 'pos' , [ 40 40 100 20] , ...
'min' , 0 , 'max' , 1 , 'call' , 'execstr(cg) ; execstr( setc ) ;' ) ;
//B設定
htb = uicontrol( 'style' , 'text' , 'pos' , [ 10 10 20 20 ] , ...
'string' , 'B' ) ;
sb = ' set( hsb , ''value'' , strtod( get( heb , ''string'' ) ) ) ; ' ;
heb = uicontrol( 'style' , 'edit' , 'position' , [ 150 10 40 20 ] , ...
'call' , 'execstr(sb);execstr(setc);' ) ;
cb = ' set( heb , ''string'' , string( hsb.value ) ) ; '
hsb = uicontrol( 'style' , 'slider' , 'pos' , [ 40 10 100 20 ] , ...
'min', 0 , 'max' , 1 , 'call' , 'execstr(cb) ; execstr( setc ) ;' ) ;