Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
すごい広島 With Python 発表資料_2020_0129
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
J-Ogu
January 29, 2020
410
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
すごい広島 With Python 発表資料_2020_0129
J-Ogu
January 29, 2020
More Decks by J-Ogu
See All by J-Ogu
ビジネスPythonを学ぶ会_2020_11_09_Ogu
ogu
0
450
JBUG広島&JBUG岡山 #共同開催 2020_06_21 LT資料
ogu
1
500
PyconJP2018 09_18 小栗潤一 Pythonで「お絵描きパズル」を解いてみた
ogu
0
3.1k
Pycon JP 2018 python_お絵描きパズルのロジックまとめ.pdf
ogu
1
1k
Featured
See All Featured
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
550
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
610
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
370
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
120
120k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
530
Context Engineering - Making Every Token Count
addyosmani
9
1.2k
Designing Powerful Visuals for Engaging Learning
tmiket
1
600
Rebuilding a faster, lazier Slack
samanthasiow
85
9.7k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
290
Claude Code のすすめ
schroneko
67
230k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
480
Transcript
Pythonを使った リアルタイム描画について すごい広島 with Python 第34回 2020_01_29 小栗 潤一
Pythonのリアルタイム描画の方法 ・jupyter notebookでIPython.displayを使う ・matplotlibのplt.pause(.01)で描画する ・OpenCVのcv2.imshowで描画する
Pythonのリアルタイム描画の方法 ・jupyter notebookでIPython.displayを使う ・matplotlibのplt.pause(.01)で描画する ・OpenCVのcv2.imshowで描画する 今日なぜこの話を? ・Pythonでお絵かきパズルを解いてみたのリファクタリング開始 ・ コード量が多すぎてjupyterではリファクタリングしにくい ・Git管理もしたい。
・ コンソール上でpython3 oekaki.py で実行したい。 ・ リアルタイム描画の機能は維持したい。 (開発しやすい) ・ 調べたらいろいろな方法があったのでまとめて発表しよう。
方法① jupyter notebook
jupyter notebookでIPython.displayを使う from PIL import Image, ImageDraw, ImageFont from IPython.display
import display, clear_output def byouga_syori(w_list, h_list, byouga ): img = Image.new('RGB', (10, 10), (128,128,128) ) ### <描画用のデータを作成する処理> ### clear_output(wait=True) display(img) ・jupyter上でmatplotlibの描画には %matplotlib inline が必要 ・IPython.displayを使うと %matplotlib inline がいらない Demo できる
方法② matplotlib
matplotlibのplt.pause(.01)で描画する import matplotlib.pyplot as plt def pause_plot(): fig, ax =
plt.subplots(1, 1) x = np.arange(-np.pi, np.pi, 0.1) y = np.sin(x) lines, = ax.plot(x, y) while True: x += 0.1 y = np.sin(x) lines.set_data(x, y) ax.set_xlim((x.min(), x.max())) plt.pause(.01) ・jupyter上では %matplotlib inline が必要 https://qiita.com/hausen6/items/b1b54f7325745ae43e47 コード流用元 Demo できる
方法③ OpenCV
OpenCVのcv2.imshowで描画する from PIL import Image, ImageDraw, ImageFont import cv2 import
numpy as np def byouga_syori(w_list, h_list, byouga ): img = Image.new('RGB', (10, 10), (128,128,128) ) ### <描画用のデータを作成する処理> ### OpenCV_data=np.asarray(img) cv2.imshow("Loaded image",OpenCV_data) cv2.waitKey(1) cv2.moveWindow('Loaded image', 30, 10) cv2.waitKey(1) ➡︎ cv2.waitKey(0) ↑この引数はミリ秒:100くらいにするとお絵かきロジックにはちょうどいい ・描画位置を変更したい場合は ・リアルタイム描画を止めたい (何かキーを押すまで停止) Demo できる
いろいろな方法が あるので試して みてください。 やっぱりPythonは楽しい