Browse Source

Add more intro stuff, add UI for the pygame part

rorist 8 months ago
parent
commit
edef1aaeaa
3 changed files with 89 additions and 11 deletions
  1. BIN
      images/horses-in-skyrim-physics-who-is-that.jpg
  2. BIN
      images/quadcopter-streamlines.png
  3. 89 11
      slides.ipynb

BIN
images/horses-in-skyrim-physics-who-is-that.jpg


BIN
images/quadcopter-streamlines.png


+ 89 - 11
slides.ipynb

@@ -37,6 +37,56 @@
    "cell_type": "markdown",
    "metadata": {
     "slideshow": {
+     "slide_type": "subslide"
+    }
+   },
+   "source": [
+    "# Introduction\n",
+    "\n",
+    "I wanted to show nice graphs and simulations, but it's not my domain and the talk is supposed to be a 101\n",
+    "\n",
+    "![](./images/quadcopter-streamlines.png)"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {
+    "slideshow": {
+     "slide_type": "subslide"
+    }
+   },
+   "source": [
+    "# Introduction\n",
+    "\n",
+    "- But the subject is still interesting, how can we have an introduction without digging too much ?\n",
+    "- Video games are a great example, implementing real physics is usually a bad idea, it doesn't feel good or is not fun for the gamer\n",
+    "- Then we implement an alternative physics which have similar behavior\n",
+    "- It's interesting to study those, usually much simplier and still gives a good idea of the real deal\n",
+    "\n",
+    "![](./images/horses-in-skyrim-physics-who-is-that.jpg)"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {
+    "slideshow": {
+     "slide_type": "notes"
+    }
+   },
+   "source": [
+    "## misconception\n",
+    "\n",
+    "- bernoulli effect is not THE explaination (faster = lower pressure, increase in the speed of a fluid occurs simultaneously with a decrease in pressure)\n",
+    "- It's a combination of effects\n",
+    " - air compression at the tip of the wing\n",
+    " - accelerate the air on one side (kind of bernouilli)\n",
+    " - air is accelerated downward so the wing is pushed up -> conservation of mass, momentum and energy"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {
+    "slideshow": {
      "slide_type": "skip"
     }
    },
@@ -46,7 +96,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 6,
+   "execution_count": 5,
    "metadata": {
     "slideshow": {
      "slide_type": "subslide"
@@ -62,6 +112,7 @@
     "screen = None\n",
     "drone = None\n",
     "ground = None\n",
+    "ui = None\n",
     "all = pygame.sprite.RenderUpdates()\n",
     "clock = pygame.time.Clock()\n",
     "\n",
@@ -76,15 +127,29 @@
     "    def reset(self):\n",
     "        self.velocity = (0, 0)\n",
     "        self.acceleration = (0, 1)\n",
-    "        self.rect = pos\n",
+    "        self.rect = pos.copy()\n",
     "        \n",
     "class Drone(DroneBase):\n",
-    "    pass"
+    "    pass\n",
+    "\n",
+    "class UI(pygame.sprite.Sprite):\n",
+    "    \n",
+    "    def __init__(self):\n",
+    "        self.containers = all\n",
+    "        pygame.sprite.Sprite.__init__(self, self.containers)\n",
+    "        self.font = pygame.font.Font(None, 24)\n",
+    "        self.image = pygame.Surface((640, 20))\n",
+    "        self.rect = pygame.Rect(0, 0, 640, 20)\n",
+    "        \n",
+    "    def update(self):\n",
+    "        self.image.fill(pygame.Color('gray'))\n",
+    "        self.image.blit(self.font.render(\"drone: vel={}, acc={}\".format(drone.velocity, drone.acceleration), True, (0, 0, 0)), (320, 1))\n",
+    "        self.image.blit(self.font.render(\"r=reset, q=quit\", True, (0, 0, 0)), (5, 1))"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 7,
+   "execution_count": 6,
    "metadata": {
     "slideshow": {
      "slide_type": "subslide"
@@ -93,22 +158,24 @@
    "outputs": [],
    "source": [
     "def init():\n",
-    "    global running, screen\n",
+    "    global running, screen, ui\n",
     "    running = True\n",
     "    \n",
     "    # Initialize pygame\n",
     "    pygame.init()\n",
     "    pygame.display.set_caption('Drone Physics 101')\n",
     "    screen = pygame.display.set_mode((x, y))\n",
+    "    ui = UI()\n",
     "    \n",
     "    # Init sprite\n",
     "    all.empty()\n",
-    "    all.add(drone)"
+    "    all.add(drone)\n",
+    "    all.add(ui)"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 8,
+   "execution_count": 7,
    "metadata": {
     "slideshow": {
      "slide_type": "subslide"
@@ -131,6 +198,7 @@
     "            func()\n",
     "            \n",
     "        # Drawing everything\n",
+    "        ui.update()\n",
     "        all.draw(screen)\n",
     "        pygame.display.flip()\n",
     "        \n",
@@ -171,8 +239,12 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 9,
-   "metadata": {},
+   "execution_count": 6,
+   "metadata": {
+    "slideshow": {
+     "slide_type": "subslide"
+    }
+   },
    "outputs": [],
    "source": [
     "drone = Drone()\n",
@@ -192,7 +264,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 12,
+   "execution_count": 9,
    "metadata": {
     "slideshow": {
      "slide_type": "subslide"
@@ -211,6 +283,8 @@
     "        self.velocity = (x, y)\n",
     "        if not self.rect.colliderect(ground):\n",
     "            self.rect.move_ip(x, y)\n",
+    "        else:\n",
+    "            self.velocity = (0, 0)\n",
     "        \n",
     "drone = Drone()\n",
     "render(drone.move)"
@@ -218,7 +292,11 @@
   },
   {
    "cell_type": "markdown",
-   "metadata": {},
+   "metadata": {
+    "slideshow": {
+     "slide_type": "notes"
+    }
+   },
    "source": [
     "* La physique\n",
     "    * Se battre contre la gravité (brick, ne peux pas planer)\n",