Swift Playgroundsでタートル・グラフィックスしよう!

0b8ad408b31cb9d5cff2828086c65d58?s=47 temoki
September 06, 2019

Swift Playgroundsでタートル・グラフィックスしよう!

0b8ad408b31cb9d5cff2828086c65d58?s=128

temoki

September 06, 2019
Tweet

Transcript

  1. 4XJGU1MBZHSPVOETͰ λʔτϧɾάϥϑ ΟοΫε͠Α͏ J04%$

  2. !ࣗݾ঺հ

  3. 5PNPLJ,PCBZBTIJ  J1IPOF(ͷ೔ຊ্཮௚ޙʹ
 ɹɹɹɹ J1IPOFΞϓϦ։ൃΛ࢝ΊΔ  ϑΣϯϦϧגࣜձࣾʹೖࣾ
 ɹɹɹɹ ໊ݹ԰ࢧࣾͰΞϓϦͷڞಉ։ൃʹैࣄ 

    גࣜձࣾελϝϯ ʢ໊ݹ԰ʣ ʹೖࣾ
 ɹɹɹɹ ૑ۀࣄۀ56/"(ͷΞϓϦ։ൃʹैࣄ 5XJUUFS(JU)VC!UFNPLJ
  4. ໊ݹ԰͔Βདྷ·ͨ͠

  5. ໊ݹ԰ۙล͔Β དྷͨਓ͸͍·͔͢ʁ#

  6. IUUQUBLBOPSJEBZPCMPHTIJOPCJKQ&OUSZ <ग़య>Πϯλʔωοτք۾ͷࣄΛௐ΂Δ͓!UBLBOPSJ ೥

  7. IUUQTDUZPIBUFOBCMPHDPNFOUSZOBHPZB@JU@NBQ@ <ग़య>$ZDMF5FDI-PH αΠΫϧςοΫϩά !D@UZP ೥

  8. גࣜձࣾελϝϯ w૑ۀɿ೥݄ w໊ࣾɿ4UBS.FNCFST wਓ਺ɿ໊ʙ wຊࣾɿ໊ݹ԰ ُౡ  wࢧࣾɿ౦ژେࡕ෱Ԭ wࣄۀɿ56/"(

  9. None
  10. None
  11. 4XJGU1MBZHSPVOETͰ λʔτϧɾάϥϑ ΟοΫε͠Α͏ J04%$

  12. λʔτϧɾάϥϑ ΟοΫε

  13. λʔτ ϧɾάϥϑ Ο οΫε wΛૢͬͯ%άϥϑ Ο οΫεΛੜ੒͢Δ wڭҭ༻ϓϩάϥϛϯάݴޠ-PHPͷػೳ w.*5໊༪ڭतγʔϞΞ ɾ

    ύύʔ τ͕։ൃ
  14. Ұൠతͳ%άϥϑ Ο οΫε  ௗͷࢹ఺Ͱඳ͘

  15. None
  16. ӈʹϚεɺ্ʹϚε

  17. addLine(to:(1,3)) (0,0) (1,3)

  18. λʔτϧɾάϥϑ Ο οΫε  ஬ͷࢹ఺Ͱඳ͘

  19. λʔτϧɾάϥϑ Ο οΫε  ُͷࢹ఺Ͱඳ͘

  20. None
  21. ӈʹ˃ ճసɺલʹา

  22. right(20) forward(5)

  23. ਖ਼ࡾ֯ܗΛඳ͘ʹ͸ʁ

  24. Ұൠతͳ%άϥϑ Ο οΫε (0,0) addLine(to:(5,?)) (5,?) addLine(to:(10,0)) (10,0) ਺ֶͷ஌͕ࣝඞཁ ʢ௚ަ࠲ඪܥɾࡾ֯ؔ਺ʣ

  25. λʔτϧɾάϥϑ Ο οΫε forward(10) left(120) forward(10) left(120) forward(10) ࣗવͳ܁Γฦ͠Ͱඳ͘ ճసͷ਺ࣈͷҙຯ͸ʁ

  26. λʔτϧɾάϥϑ Ο οΫε left(100) left(140) left(120) ʮ਺ࣈΛม͑ͯ֬ೝʯ ͷ܁Γฦ͠Ͱֶ΂Δ

  27. λʔτ ϧɾάϥϑ Ο οΫεͷಛ௃ w໋ྩ͸ݱࡏͷঢ়ଶ͔Β૬ରతʹ࡞༻ w໋ྩऀ͸ͱࣗݾͱΛҰମԽͤͯ͞ૢ࡞ w໋ྩͷ݁Ռ͕ଈ࠲ʹࢹ֮తʹಘΒΕΔ wΤϥʔݪҼΛߟ͑ͯϦτϥΠͷ܁Γฦ͠
 σόοά ʹΑΓֶश͢Δ

  28. λʔτ ϧɾάϥϑ Ο οΫεͱ ͷग़ձ͍

  29. ग़ձ͍ wதֶ೥࣌ ೥ ͷίϯϐϡʔλͷतۀ w෋࢜௨ͷ'.3ͱ͍͏.4%04౥ࡌͷ ύʔιφϧίϯϐϡʔλΛ࢖༻ wϩΰϥΠλʔͱ͍͏ιϑτͰλΠϐϯά ͱ-PHPʹΑΔϓϩάϥϛϯάΛֶश

  30. ੒ޭମݧ wλʔτϧɾάϥϑΟοΫεָ͍͠ʂ wເதʹͳͬͯεΩʔδϟϯϓͷήʔϜ Λ࡞ͬͨΒΫϥεϝΠτ͔Β൓ڹ wॳͷϓϩάϥϛϯάͰͷ੒ޭମݧ

  31. λʔτ ϧɾάϥϑ Ο οΫεͷ ࢈Έͷ਌

  32. γʔϞΞɾύύʔτ wࣇಐ৺ཧֶऀϐΞδΣͱ
 ࢠڙͷ஌ೳൃୡΛݚڀ wߏ੒ओٛڭҭΛ໨తͱͨ͠
 ϓϩάϥϛϯάݴޠ-PHPΛ։ൃ wϨΰͱ.*/%4503.Λ։ൃ w45&.ڭҭͷݪ఺ ग़యOFXTNJUFEV

  33. ग़యDZCFSOFUJD[PPDPN

  34. γʔϞΞɾύύʔτͷ Өڹ

  35. ΞϥϯɾέΠ wύύʔτͷݩͰ-PHPΛֶͿ w1"3$ʹͯࢠͲ΋Ͱ΋࢖͑Δ
 ཧ૝୺຤ ʮ%ZOBCPPLʯ Λߏ૝ w࢑ఆ%ZOBCPPLʢ`೥୅ͷࢼ࡞ʣ
 "MUP ϋʔυ ͱ4NBMMUBML

    ιϑτ  wύʔιφϧίϯϐϡʔλͷ෕ ग़యKBXJLJQFEJBPSH
  36. ग़యFOXJLJQFEJBPSH

  37. εςΟʔϒɾδϣϒζ w1"3$Ͱݟͨ"MUPʹিܸΛड͚ ։ൃதͷ-JTBʹ(6*Λ౥ࡌ w-JTBϓϩδΣΫτͷޙ
 .BDJOUPTIΛ։ൃ wͦͷੜ֔ͷऴ൫ʹൃදͨ͠
 ॳ୅J1BE͸%ZOBCPPLʜ ग़యKBXJLJQFEJBPSH

  38. Կͱͳ͘ ๻ͨͪ΁ͷܨ͕ΓΛ ײ͡·͢ΑͶʁ

  39. ϓϩάϥϛϯάݴޠ -PHP

  40. ϓϩάϥϛϯάݴޠ-PHP w೥ʹߏ੒ओֶٛशΛ໨తʹ։ൃ w-JTQʹӨڹΛड͚ͨؔ਺ܕݴޠ wܕએݴෆཁɺ࠶ؼతఆ͕ٛՄೳ

  41. ਖ਼ࡾ֯ܗΛඳ͘ϓϩγʔδϟ to Triangle :x repeat 3 [ forward :x right

    120 ] end
  42. ࣮૷ w"QQMF-PHP "QQMF**༻  w"$4-PHPGPS.BD049 w-PHP8SJUFS8JO IUUQTXXXBMBODTNJUIDPVLMPHP IUUQXXXMPHPDPNKQ

  43. ϓϩάϥϛϯάݴޠ -PHPͷӨڹ

  44. -PHPͷӨڹ w-PHP͸ʹ໋ྩͯ͠ૢ࡞͢Δ wΞϥϯɾέΠ͕ΦϒδΣΫτࢦ޲
 ͱ͍͏ண૝ΛಘΔ͖͔͚ͬ w७ਮΦϒδΣΫτࢦ޲ݴޠ4NBMMUBML

  45. -JTQ -PHP 4NBMMUBML 3VCZ 0CKFDUJWF$ 4XJGU ؔ਺ܕ ಈతੑ ΦϒδΣΫτࢦ޲ ΦϒδΣΫτࢦ޲

    ϝοηʔδૹ৴
  46. ͭ·Γɺ J04ΞϓϦ։ൃऀ͸ γʔϞΞɾύύʔτͷ
 ӨڹΛड͚͍ͯΔͱݴ͑Δ

  47. ͦͯ͠೥ʜ

  48. ೥๻Λಈ͔ͨ͠Ͱ͖͝ͱ w88%$Ͱ4XJGU1MBZHSPVOETൃද w݄೔γʔϞΞɾύύʔτ͕ࢮڈ

  49. 4XJGU1MBZHSPVOETͰ λʔτϧɾάϥϑΟοΫε ͍ͨ͠ʂ

  50. ࢠͲ΋ͨͪʹ ๻ͱಉ͡ମݧΛ ʂ

  51. Ұिؒޙ

  52. 5PSUPJTF(SBQIJDT

  53. None
  54. 5PSUPJTF(SBQIJDT w4XJGU੡λʔτϧɾάϥϑΟοΫεɾΤϯδϯ w໊લ͸ݸਓతʹϦΫΨϝͷํ͕޷Έͳͷ͕ཧ༝ w9DPEF1MBZHSPVOET 4XJGU1MBZHSPVOETͰಈ࡞ wCGImage΁ͷग़ྗػೳ

  55. None
  56. ⭐͍ͩ͘͞ github.com/temoki/TortoiseGraphics

  57. None
  58. None
  59. 5PSUPJTF(SBQIJDTͷ ٕज़తͳ࿩ᶃ ʢάϥϑΟοΫεฤʣ

  60. 'SBNFXPSLT w$PSF(SBQIJDT w$PSF"OJNBUJPO ग़యEFWFMPQFBQQMFDPN

  61. 'SBNFXPSLT w$PSF(SBQIJDT w$PSF"OJNBUJPO ग़యEFWFMPQFBQQMFDPN

  62. $PSF(SBQIJDT w2VBSU[%ͱ΋ݺ͹ΕΔ w௿ϨϕϧͰܰྔͳ%ඳըΤϯδϯ wCGContext CGImage CGPoint ʜ

  63. CGContext w$PSF(SBQIJDTͷग़ྗઌͱͳΔ΋ͷ wಉ໋͡ྩͰ༷ʑͳग़ྗઌʹඳըͰ͖Δ wΞϓϦͷϏϡʔɺϏοτϚοϓը૾ɺ
 1%'υΩϡϝϯτɺϓϦϯλʔ wඳըύϥϝʔλͱɺඳըʹඞཁͳग़ྗઌ
 σόΠεಛ༗ͷ৘ใΛ͍࣋ͬͯΔ

  64. None
  65. None
  66. ࣮૷ͷϙΠϯτ w$PSF(SBQIJDT͸௚ަ࠲ඪܥͰߟ͑Δ wλʔτϧɾάϥϑ ΟοΫε͸ͷࢹ఺Ͱߟ͑Δ wͷݱࡏͷঢ়ଶͱࢦࣔ͞Ε໋ͨྩʹԠͯ͡ɺ
 ௚ަ࠲ඪܥͰͷߦ͖ઌΛΞϑΟϯม׵ͰٻΊΔ

  67. forward P2(x,y) ҠಈޙͷҐஔ Ҡಈڑ཭ distance ݱࡏͷ޲͖ SBE heading P1(x,y) ݱࡏͷҐஔ

  68. forward P1(x,y) ݱࡏͷҐஔ P2(x,y) ҠಈޙͷҐஔ Ҡಈڑ཭ distance ݱࡏͷ޲͖ SBE heading

  69. 'SBNFXPSLT w$PSF(SBQIJDT w$PSF"OJNBUJPO ग़యEFWFMPQFBQQMFDPN

  70. $PSF"OJNBUJPO wάϥϑΟοΫεͱΞχϝʔγϣϯͷΠϯϑϥ wΞϓϦͷϏϡʔΛ؆୯ʹΞχϝʔγϣϯͰ͖Δ w(16Λ࠷େݶʹར༻͢ΔͨΊߴ଎ wCALayer CAAnimation ʜ

  71. CALayer wUIView͸CALayerͷ
 ֊૚Ͱߏ੒͞ΕΔ wUIViewͷඳը΍
 ΞχϝʔγϣϯͷҠৡઌ wCAShapeLayer  CATextLayer ʜ UIView

    CALayer (sub1) CALayer (root) CALayer (sub2)
  72. CAShapeLayer w࠲ඪۭؒʹ࣍#4QMJOFΛඳը͢ΔϨΠϠʔ wඳըύεͱઢ΍ృΓͷύϥϝʔλΛࢦఆ͢Ε͹ ͦͷύεΛඳըͯ͘͠ΕΔ

  73. CAAnimation w$PSF"OJNBUJPOͷ
 ΞχϝʔγϣϯΛ୲͏ wCALayerʹΞλον͢Δ wCABasicAnimation  CAKeyframeAnimation  ʜ CALayer

    .alpha
  74. ࣮૷ͷϙΠϯτ wͷඳ͘ઢͷΞχϝʔγϣϯ
 CAShapeLayer CABasicAnimation wͷҠಈͷΞχϝʔγϣϯ
 CAShapeLayer CAKeyframeAnimation

  75. ͷඳ͘ઢͷΞχϝʔγϣϯ CAShapeLayer CABasicAnimation toValue fromValue CAShapeLayer.path Animation

  76. ͷඳ͘ઢͷΞχϝʔγϣϯ CAShapeLayer CABasicAnimation

  77. ͷҠಈͷΞχϝʔγϣϯ CAShapeLayer CAKeyframeAnimation path Animation CAShapeLayer().position

  78. ͷҠಈͷΞχϝʔγϣϯ CAShapeLayer CAKeyframeAnimation

  79. ࠷ऴతͳΞχϝʔγϣϯ

  80. ϨΠϠʔߏ੒

  81. ϨΠϠʔߏ੒ ඳըࡁΈ ϏοτϚοϓදࣔ ඳըΞχϝʔγϣϯ Ξχϝʔγϣϯ

  82. 5PSUPJTF(SBQIJDTͷ ٕज़తͳ࿩ᶄ ʢ4XJGU1MBZHSPVOET#PPLฤʣ

  83. 4XJGU1MBZHSPVOET wJ1BEͰ4XJGUΛɻίʔσ Οϯάͷ৽ֶ͍͠ͼํɻ w"3,JU "7'PVOEBUJPO $PSF#MVFUPPUI΋ಈ࡞ w"QQMF -&(0౳͕༷ʑͳίϯςϯπΛఏڙ w#PPLͱ͍͏ܗͰ୭Ͱ΋࡞੒ͯ͠഑෍Ͱ͖Δ

  84. 4XJGU1MBZHSPVOET#PPL ࡞੒ɾ഑෍ͷํ๏

  85. J04%$ w!TPOTPO@UXJU͞Μͷ ࡢ೥ͷൃද͕लҳʂ w͜Εͱ"QQMFެࣜͷ
 υΩϡϝϯτΛߦ͖དྷ ͢Δͷ͕Φεεϝʂ ग़యGPSUFFKQJPTEDKBQBO

  86. 4XJGU1MBZHSPVOET#PPL࡞੒ํ๏ w#PPL$IBQUFS1BHFͱ͍͏ߏ੒ w#PPLΛߏ੒͢Δϝλ৘ใɺ4XJGUιʔεɺ
 ֤छϦιʔε౳ͷϑΝΠϧΛ·ͱΊͨ΋ͷ w"QQMF͔Βఏڙ͞Ε͍ͯΔςϯϓϨʔτ
 4XJGU1MBZHSPVOET"VUIPS5FNQMBUFΛ࢖͏ μΠδΣετ൛

  87. 4XJGU1MBZHSPVOET#PPL࡞੒ํ๏ w1MBZHSPVOE1BHF͕࠷খ୯Ґ w$POUFOUTTXJGU ίϯςϯπ  w-JWF7JFXTXJGU දࣔ  w.BOJGFTUQMJTU ϖʔδ৘ใ

    μΠδΣετ൛
  88. Contents.swift LiveView.swift ग़యEFWFMPQFSBQQMFDPN -JWF7JFXͷϓϩΩγΛհͯ͠ PlaygroundValueΛ΍ΓͱΓ

  89. 4XJGU1MBZHSPVOET#PPL഑෍ํ๏ w"JS%SPQͰ#PPLΛJ1BEʹసૹ
 ։ൃதͷσόοάखஈ΋͜Ε͚ͩ w"QQMFެࣜͷ4VCTDSJQUJPOͷ࢓૊Έ μΠδΣετ൛

  90. 4VCTDSJQUJPO wSE1BSUZͷ#PPLΛߪಡ͢Δ࢓૊Έ w4XJGU1MBZHSPVOET ೥ Ͱ௥Ճ͞Εͨ w഑৴ऀ͸#PPLߪಡ༻ͷ'FFE +40/ϑΝΠϧ ͱ
 #PPLΛ΢Σϒ্ʹ഑ஔ wϢʔβʔ͸J1BEͷ4BGBSJͰͦͷϦϯΫΛ౿Ί͹


    4XJGU1MBZHSPVOETʹ#PPL͕௥Ճ͞ΕΔ
  91. None
  92. 5PSUPJTF(SBQIJDTͷ ੒Ռ

  93. ͦͷ̍

  94. None
  95. ͦͷ̎

  96. J04%$ ͰొஃͰ͖ͨ

  97. ͦͷ̏

  98. ʮतۀͰ࢖͍͍ͨʯ ͱ ͭͷֶߍ͔Βͷ࿈བྷ

  99. ग़యXXXMDTPODB

  100. ֶߍͷतۀͰͷ׆༻ࣄྫ w-BLFpFME$PMMFHF4DIPPM wΧφμΦϯλϦΦभͷશྈ੍ࢲཱߴߍ w໿ਓͷֶੜ͕ࡏ੶

  101. ίϯϐϡʔλɾαΠΤϯεೖ໳ w·ͣ͸4DSBUDI΍(1ͷΑ͏ͳϒϩοΫɾϕʔεͷ
 ϓϩάϥϛϯά͔Β࢝ΊΔ w࣍ʹ5PSUPJTF(SBQIJDTͰςΩετɾϕʔεͷ
 ϓϩάϥϛϯάʹҠߦ͢Δ w࠷ऴ՝୊͸ੜె͕ಠࣗͷਤܗΛίʔυͰඳ͍ͯ
 ϖϯɾϓϩολʔͰग़ྗ͢Δ

  102. None
  103. None
  104. None
  105. 5PSUPJTF(SBQIJDT ͷࠓޙ

  106. 5PSUPJTF(SBQIJDTͷࠓޙ wϖϯɾϓϩολʔग़ྗͷͨΊʹ
 47(ܗࣜͰͷग़ྗʹରԠ͢Δ wશମͷΫΦϦςΟ޲্ wͦͯ͠࠷ऴతʹ໨ࢦ͢ઌ͸ʜ

  107. None
  108. ͝੩ௌ ͋Γ͕ͱ͏͍͟͝·ͨ͠