Browse Source

testing pygame (basic initialization)

rorist 6 months ago
parent
commit
1cb159c676
2 changed files with 72 additions and 44 deletions
  1. 0 1
      requirements.txt
  2. 72 43
      slides.ipynb

+ 0 - 1
requirements.txt

@@ -1,2 +1 @@
 jupyter
-vpython

+ 72 - 43
slides.ipynb

@@ -1,52 +1,80 @@
 {
  "cells": [
   {
-   "cell_type": "code",
-   "execution_count": 13,
-   "metadata": {},
-   "outputs": [
-    {
-     "data": {
-      "text/html": [
-       "<div id=\"glowscript\" class=\"glowscript\"></div>"
-      ],
-      "text/plain": [
-       "<IPython.core.display.HTML object>"
-      ]
-     },
-     "metadata": {},
-     "output_type": "display_data"
-    },
-    {
-     "data": {
-      "application/javascript": [
-       "if (typeof Jupyter !== \"undefined\") { window.__context = { glowscript_container: $(\"#glowscript\").removeAttr(\"id\")};}else{ element.textContent = ' ';}"
-      ],
-      "text/plain": [
-       "<IPython.core.display.Javascript object>"
-      ]
-     },
-     "metadata": {},
-     "output_type": "display_data"
+   "cell_type": "markdown",
+   "metadata": {
+    "slideshow": {
+     "slide_type": "slide"
     }
-   ],
+   },
    "source": [
-    "# https://www.glowscript.org/docs/VPythonDocs/VPython_Intro.pdf\n",
-    "from vpython import *\n",
-    "scene = canvas()\n",
+    "# Drone Physics 101\n",
     "\n",
-    "ball = sphere(pos=vector(-5,0,0), radius=0.5, color=color.cyan)\n",
-    "wallR = box(pos=vector(6,0,0), size=vector(0.2,12,12), color=color.green)\n",
-    "wallL = box(pos=vector(-10,0,0), size=vector(0.2,12,12), color=color.green)\n",
-    "ball.velocity = vector(25,0,0)\n",
-    "deltat = 0.005\n",
-    "t = 0 \n",
-    "while t < 3:\n",
-    "    if ball.pos.x > wallR.pos.x or ball.pos.x < wallL.pos.x:\n",
-    "        ball.velocity.x = -ball.velocity.x \n",
-    "    ball.pos = ball.pos + ball.velocity * deltat\n",
-    "    t = t + deltat \n",
-    "    rate(100) "
+    "Blah blah blah"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 36,
+   "metadata": {
+    "slideshow": {
+     "slide_type": "skip"
+    }
+   },
+   "outputs": [],
+   "source": [
+    "import pygame\n",
+    "def init():\n",
+    "    global running\n",
+    "    running = True\n",
+    "    pygame.init()\n",
+    "    pygame.display.set_caption('Drone Physics 101')\n",
+    "    screen = pygame.display.set_mode((640, 640))"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 41,
+   "metadata": {
+    "slideshow": {
+     "slide_type": "skip"
+    }
+   },
+   "outputs": [],
+   "source": [
+    "def render(func):\n",
+    "    global running\n",
+    "    init()\n",
+    "    while running:\n",
+    "        func()\n",
+    "        pygame.display.flip()\n",
+    "        for event in pygame.event.get():\n",
+    "            if event.type == pygame.KEYDOWN:\n",
+    "                if event.key == pygame.K_q:\n",
+    "                    running = False\n",
+    "    pygame.quit()"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 42,
+   "metadata": {
+    "slideshow": {
+     "slide_type": "subslide"
+    }
+   },
+   "outputs": [],
+   "source": [
+    "render(lambda: True)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 43,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "render(lambda: True)"
    ]
   },
   {
@@ -58,6 +86,7 @@
   }
  ],
  "metadata": {
+  "celltoolbar": "Slideshow",
   "kernelspec": {
    "display_name": "Python 3",
    "language": "python",