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
turtleであそぼう!
Search
ksnt
September 18, 2020
320
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
turtleであそぼう!
はんなりPython #32
ksnt
September 18, 2020
More Decks by ksnt
See All by ksnt
AutoGenを触ってみた
ksnt
0
380
データ分析者にとってのDjango: StreamlitやDashとの比較
ksnt
1
2.1k
データ分析で切り拓け! エンジニアとしてのデータ分析職キャリア戦略
ksnt
0
1.1k
勉強会で発表してみよう!
ksnt
0
350
Kaggleに置かれているデータを 可視化する
ksnt
0
440
CourseraのDigital Transformationというコースを受けてみた
ksnt
2
740
Pythonで挑む計算社会科学
ksnt
0
1.6k
データ分析と競技プログラミングに使えるPython標準ライブラリ入門
ksnt
1
720
DashユーザーがStreamlitを使ってアプリケーションをつくってみた
ksnt
0
2.3k
Featured
See All Featured
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
270
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
860
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
440
How to Think Like a Performance Engineer
csswizardry
28
2.9k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Building Adaptive Systems
keathley
44
3.3k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.8k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
740
How to make the Groovebox
asonas
2
2.5k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
2
2.2k
Leo the Paperboy
mayatellez
10
2.4k
Transcript
turtleであそぼう! ksnt
turtleって何?何? ・Python標準ライブラリに入ライブラリに入っているモに入っているモジ入っているモジュって何?いるモジュールモジュール ・計算機科学者のシーモア・パのシーモア・パパシーモア・パパートが生みの親が生みの親生みの親みのシーモア・パパ親 ・お絵かきが得意絵かきが得意かきが生みの親得意
Hello world with turtle from turtle import * color('blue', 'yellow')
begin_fill() while True: forward(200) left(170) if abs(pos()) < 1: break end_fill() done()
今回はこのはこのシーモア・パパturtleで ゲームをつくってみたをつくって何?みた
なに入っているモジはともあれ デモ
turtleを使ってゲームを作って何?ゲームをつくってみたを作るるモジュール(1) # Set up screen wn = turtle.Screen() wn.bgcolor("black") wn.bgpic("kbgame-bg.gif")
wn.tracer(7) # Draw border mypen = turtle.Turtle() mypen.color(“black") mypen.penup() mypen.setposition(-300, -300) mypen.pendown() mypen.pensize(3) for side in range(4): mypen.forward(600) mypen.left(90) mypen.hideturtle() # スクリに入っているモーンのセットアップのシーモア・パパセットが生みの親アップ スクリに入っているモーンのセットアップのシーモア・パパ生みの親成 背景色を設定を設定 背景のシーモア・パパ画像を設定を設定 スクリに入っているモーンのセットアップアップデートが生みの親が生みの親遂行される回数の調されるモジュール回はこの数の調整のシーモア・パパ調整 # 境界を描くを描くく タートが生みの親ルのシーモア・パパ生みの親成 タートが生みの親ルのシーモア・パパ色を設定を設定 ペンのセットアップを上げるげるモジュール ペンのセットアップのシーモア・パパポジションのセットアップをセットが生みの親 ペンのセットアップを下ろすろす ペンのセットアップのシーモア・パパサイズを設定を設定 ペンのセットアップで四角形を書くを書くく タートが生みの親ルを隠すす border.py
turtleを使ってゲームを作って何?ゲームをつくってみたを作るるモジュール(2) # Create player turtle player = turtle.Turtle() player.color("blue") player.shape("triangle")
player.penup() player.speed(0) # Create obstacles maxObsts = 20 obsts = [] for count in range(maxObsts): obsts.append(turtle.Turtle()) obsts[count].color("yellow") obsts[count].shape("square") obsts[count].penup() obsts[count].speed(0) obsts[count].setposition(random.randint(- 300, 300), random.randint(-300, 300)) # プレイヤーをつくるモジュール タートが生みの親ルのシーモア・パパ生みの親成 タートが生みの親ルのシーモア・パパ色を設定を設定 タートが生みの親ルのシーモア・パパ形を書くを設定 ペンのセットアップを上げるげるモジュール タートが生みの親ルのシーモア・パパ初期速度を設定を設定 # 障害物をつくるをつくるモジュール 障害物をつくるのシーモア・パパ数の調整を設定 黄色を設定のシーモア・パパ障害物をつくるをmaxObsts個つくるつくるモジュール 障害物をつくるをランのセットアップダムをつくってみたに入っているモジ配置するするモジュール
turtleを使ってゲームを作って何?ゲームをつくってみたを作るるモジュール(3) # Create the score variable score = 0 #
Create goals maxGoals = 10 goals = [] for count in range(maxGoals): goals.append(turtle.Turtle()) goals[count].color("red") goals[count].shape("circle") goals[count].penup() goals[count].speed(0) goals[count].setposition(random.r andint(-280, 280), random.randint(-280, 280)) # スコア変数の調整をつくるモジュール 0点からスタートからスタートスタートが生みの親 # ゴールをつくるモジュール ゴールのシーモア・パパ数の調整を設定 ゴールをmaxGoals個つくるつくるモジュール ゴールをランのセットアップダムをつくってみたに入っているモジ配置するするモジュール
turtleを使ってゲームを作って何?ゲームをつくってみたを作るるモジュール(4) # Define function def turnleft(): player.left(30) def turnright(): player.right(30)
def increasespeed(): global speed speed += 1 def decresespeed(): global speed if speed > 0: speed -= 1 elif speed == 0: pass else: speed = 0 def isCollision(t1, t2): d = math.sqrt(math.pow(t1.xcor()- t2.xcor(), 2) + math.pow(t1.ycor()- t2.ycor(), 2)) if d < 20: return True else: return False
turtleを使ってゲームを作って何?ゲームをつくってみたを作るるモジュール(5) # Set keyboard bindings turtle.listen() turtle.onkey(turnleft, "Left") turtle.onkey(turnright, "Right")
turtle.onkey(increasespeed, "Up") turtle.onkey(decresespeed, "Down") # キーボード バインのセットアップディンのセットアップグの設定のシーモア・パパ設定
turtleを使ってゲームを作って何?ゲームをつくってみたを作るるモジュール(6) start = time.time() while True: player.forward(speed) now = time.time()
# Draw the elapsed time on th screen mypen.undo() mypen.penup() mypen.hideturtle() mypen.setposition(0, 310) mypen.write(now - start, False, align="left", font=("Ubuntu", 14, "normal")) # スクリに入っているモーンのセットアップ上げるに入っているモジ時間経過を描くを描くく
turtleを使ってゲームを作って何?ゲームをつくってみたを作るるモジュール(7) # Draw the score on the screen … #
Boundary Checking if player.xcor() > 300 or player.xcor() < -300: player.right(180) os.system("mplayer bounce.mp3&") if player.ycor() > 300 or player.ycor() < -300: player.right(180) os.system("mplayer bounce.mp3&") # 境界を描くチェック
turtleを使ってゲームを作って何?ゲームをつくってみたを作るるモジュール(7) # Move the goals for count in range(maxGoals): goals[count].forward(3)
# Boundary Checking ... # Collision checking for player and goals if isCollision(player, goals[count]): goals[count].setposition(random.randint(-280, 280), random.randint(-280, 280)) goals[count].right(random.randint(0, 360)) os.system("mplayer collision.mp3&") score += 1 +1point! Goal turtle
turtleを使ってゲームを作って何?ゲームをつくってみたを作るるモジュール(7) for count in range(maxObsts): # Collision checking for player
and obstacles if isCollision(player, obsts[count]): # os.system("mplayer collision.mp3&") score -= 1 -1point! Obstacle turtle
再度を設定デモ
Enjoy Python!
Reference • Simple Python Turtle Graphics Game (Part 1 –
Part 9) https://www.youtube.com/watch? v=PTgyzZGknvg