コードだけで完結。
成果物
スペースキーを押すと色が変わる。
コード
#!/usr/bin/env python3 # coding: utf8 import pyxel class App: def __init__(self): self.window = Window() pyxel.init(self.window.Width, self.window.Height, caption=self.window.Caption) self.niko = Niko() self.niko.set_center(self.window.Width, self.window.Height) pyxel.run(self.update, self.draw) def update(self): self.niko.update() def draw(self): pyxel.cls(0) self.niko.draw() pyxel.text(0, 0, 'Please SPACE key: ' + str(self.niko.color), 7) class Window: @property def Width(self): return 96 @property def Height(self): return 54 @property def Caption(self): return "Image API" class Niko: def __init__(self): self.__set_image0() def __set_image0(self): self.x = 0 self.y = 0 self.img = 0 self.u = 0 self.v = 0 self.w = 16 self.h = 16 self.colkey = 0 self.color = 7 pyxel.image(0).set(0, 0, [ "0000077777700000", "0007700000077000", "0070000000000700", "0700000000000070", "0700000000000070", "7000070000700007", "7000070000700007", "7000000000000007", "7000000000000007", "7000000000000007", "7000700000070007", "0700070000700070", "0700007777000070", "0070000000000700", "0007700000077000", "0000077777700000", ]) def update(self): if pyxel.btnp(pyxel.KEY_SPACE): self.__change_color() def draw(self): pyxel.pal(7, self.color) pyxel.blt(self.x, self.y, self.img, self.u, self.v, self.w, self.h, self.colkey) pyxel.pal() def __change_color(self): self.color += 1 if 15 <= self.color: self.color = 1 def set_center(self, win_w, win_h): self.x = (win_w / 2) - (self.w / 2) self.y = (win_h / 2) - (self.h / 2) App()
どうやって作ったか](
pyxeleditor
のイメージエディタにて打ち込む.pyxres
ファイルを保存する.pyxres
ファイルをzip展開するimage0
をvim
で開く- vimの矩形選択(
ESC
,Ctrl
+V
)で16*16の範囲をコピー - 整形する
テキストエディタで0
,7
とか手打ちするのは辛いもの。コピペがいいね。
前回まで
- ラズパイ4Bにpyenvをインストールする(python 3.8.2)
- pyxelをインストールする(pyenv python3.8.2)
- pyxeleditorにおけるImageエディタの使い方
- pyxeleditorにおけるTileMapエディタの使い方
- pyxeleditorにおけるSoundエディタの使い方
- pyxeleditorにおけるMusicエディタの使い方
- pyxelのリソースにおける概念・制限まとめ
- pyxeleditorにおけるpyxresファイル形式まとめ
- pyxelのAPI調査
- pyxelで最小コード 窓を出す
- Pyxelで窓の境界線を消す
- 携帯ゲーム機の解像度
- pyxelで矩形を描画する
- pyxelで荒ぶる矩形
- pyxelでキーに応じて動く矩形
- pyxelで画像を描画する
- pyxelで画像をアニメーションする(スプライト。パラパラ漫画)
- pyxelで左右反転した画像を使ってアニメーションする
- pyxelでテキストを表示する
- pyxelで日本語を表示する1(ビットマップ・フォント)
- ビットマップフォント作成(TTF→PNG)
- pyxelでPNG画像をビットマップフォントとして読込・表示する(日本語表示)
- pyxelのAPIで音を鳴らす
- 画像、音声、動画をHTMLで再生する
- pyxelのAPIでSoundをつなげて鳴らす
- pyxelのAPIでMusicに組み立てて鳴らす
対象環境
- Raspbierry pi 4 Model B
- Raspbian buster 10.0 2019-09-26 ※
- bash 5.0.3(1)-release
$ uname -a Linux raspberrypi 4.19.97-v7l+ #1294 SMP Thu Jan 30 13:21:14 GMT 2020 armv7l GNU/Linux