![見出し画像](https://assets.st-note.com/production/uploads/images/129000254/rectangle_large_type_2_d6e4ccaa196f6545c77bf23f4e089080.jpeg?width=1200)
非プログラマのRen'Pyノート:画像の色や明るさを変更できるMatrixcolor関連スクリプトサンプル
Ren'Py(以下renpy)使いのみなさーん! 背景をちょっと暗めに表示したいなあ〜、よし、半透明にすれば後ろの黒が透けていい感じに暗くなるんじゃない? と思ったら、ガチ半透明になっちゃって困ったことはありませんか? 私はあります!
renpyでは、いわゆる「アルファチャンネル」のようなものが使えるっぽいと最近わかってきました。
しかし、マニュアルを読んでも難しくてよく分からない私のために、使えそうな箇所だけ抜き出した「Matrixcolor」関連のスクリプトを見本とともにまとめて記しておきます。
![](https://assets.st-note.com/img/1706387978107-V77eE8ADxr.png?width=1200)
![](https://assets.st-note.com/img/1706387946499-QP3ZrDNt2w.png?width=1200)
show時に直書き、複数掛け合わせもできる
show eileen happy at center:
matrixcolor TintMatrix("#ffffff") * SaturationMatrix(1.0)
linear 2.0 matrixcolor TintMatrix("#ccccff") * SaturationMatrix(0.0)
linear 2.0 matrixcolor TintMatrix("#ffffff") * SaturationMatrix(1.0)
これが一番わかりやすい基本かも。マニュアルにあるものをそのまま引用しました。「*」で掛け合わせもできる。
文字にも使えます。
show text "{color=#fff}{size=248}TEXT HERE{/color}{/size}":
linear 0.5 matrixcolor TintMatrix("#0505fe")
linear 0.5 matrixcolor TintMatrix("#ff00e6")
linear 0.5 matrixcolor TintMatrix("#01ff3c")
linear 0.5 matrixcolor TintMatrix("#ff9d00")
repeat
pause
ゲーミング文字も簡単に作れる #renpy #renpy小技 pic.twitter.com/xJXrIUWdDn
— kawanaka (@intheriverJP) February 1, 2024
imageの設定? に使う
image phone_frame_dark:
"phone_frame_lock.png"
matrixcolor BrightnessMatrix (0.0)
linear 1.5 matrixcolor BrightnessMatrix (-0.3)
label start:
show phone_frame_dark
個別に画像の色変更を指定するもの。これは暗くなります。BrightnessMatrix (-0.3) の-をとると明るくなります。
transformしたものを at で各画像に指定する
transform kaiso:
matrixcolor TintMatrix("#ab893e")
transform kurai:
matrixcolor BrightnessMatrix (-0.3)
transform saido:
matrixcolor SaturationMatrix (0.3)
label start:
scene bg_attic with dissolve
"通常"
scene bg_attic at kaiso with dissolve
"セピア"
scene bg_attic at kurai with dissolve
"暗くする"
scene bg_attic at saido with dissolve
"彩度変更"
show imageにもsceneにも使えます。Tintは、"#〜" の色を変更すればそのように画像も変わります。
![](https://assets.st-note.com/img/1706763667410-2Rn6fKz1dk.png?width=1200)
![](https://assets.st-note.com/img/1706763686164-IS6rRlAJRl.png?width=1200)
![](https://assets.st-note.com/img/1706763694030-asf8awvcAK.png?width=1200)
![](https://assets.st-note.com/img/1706763707874-JXKfAvj4fc.png?width=1200)
自分の感覚ですが、Brightはちょっと焼き込みっぽくなるのと、彩度変更はまだ数をどうすればどうなるのか掴めてないです。
それぞれの効果がおもってるのと違うなあ〜という方はマトリックスを掛け合わせるか、マニュアルの「マトリックスを使用した色の変更」を使えば完全オリジナルで作ることもできるようです(後述)が、私には無理っぽいです!
ボタンのオンマウスとかにも使える
transform btn_matrix:
on hover:
matrixcolor BrightnessMatrix (0.3)
on idle:
matrixcolor BrightnessMatrix (0.0)
screen btn_sample():
vbox:
xalign 0.5
yalign 0.3
imagebutton:
at btn_matrix
idle "btn_start_idle.png"
action [Jump("test")]
label start:
show screen btn_sample
"ボタンサンプル"
return
![](https://assets.st-note.com/img/1706943310114-rYepfNNAGj.png?width=1200)
動作確認したサンプル置いときます。テキストボタンとかにも使えるはず……です。
選択肢ボタンにも使えるよ。以下、上記と同じtransformをchoice screen内に atでつける方法です。
screen choice(items):
style_prefix "choice"
vbox:
for i in items:
textbutton i.caption action i.action at btn_matrix
![](https://assets.st-note.com/img/1706943298284-iQgTzM3IZ3.png?width=1200)
im.Matrix使うと怒られる
![](https://assets.st-note.com/img/1706387316917-31p4OacmnC.png?width=1200)
マニュアルには書かれている? のに使おうとすると"im.MatrixColor": This function is obsolete or outdated."と出てしまいます。自分は試していませんが、古いだけではなく「正確に動かない」と書かれていた海外の質問を見かけたように記憶していますので非推奨みたいです。
サブクラスとはつまり何なのだ?
ここまででご紹介した色の変更方法は「サブクラス」です。用語の意味は分かりませんが、「汎用性が高そうなのでrenpy側で用意された所定のスクリプト」っぽいです。多分以下の、
はちゃめちゃに難しくて数字が多いやつは詳しい方なら使いこなせそうですけど、自分が見た範囲、「明るさ・くらさ」「コントラスト」「セピア」「白黒にする」「任意の色に染める」などができるので既存のサブクラスが使えれば自分には十分という認識です。なので、「マトリックスを使用した色の変更」は覚えず、サブクラスだけで取り回しています。
この記事が気に入ったらサポートをしてみませんか?