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
310
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
360
データ分析者にとってのDjango: StreamlitやDashとの比較
ksnt
1
2k
データ分析で切り拓け! エンジニアとしてのデータ分析職キャリア戦略
ksnt
0
1.1k
勉強会で発表してみよう!
ksnt
0
350
Kaggleに置かれているデータを 可視化する
ksnt
0
440
CourseraのDigital Transformationというコースを受けてみた
ksnt
2
730
Pythonで挑む計算社会科学
ksnt
0
1.6k
データ分析と競技プログラミングに使えるPython標準ライブラリ入門
ksnt
1
710
DashユーザーがStreamlitを使ってアプリケーションをつくってみた
ksnt
0
2.3k
Featured
See All Featured
Designing Powerful Visuals for Engaging Learning
tmiket
1
540
From π to Pie charts
rasagy
0
360
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
280
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
510
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
Designing for humans not robots
tammielis
254
26k
How to make the Groovebox
asonas
2
2.4k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
330
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
67
58k
Faster Mobile Websites
deanohume
310
32k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
56
3.5k
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