diff --git a/TUBES-1.ipynb b/TUBES-1.ipynb index 48daa8f..8ce2219 100644 --- a/TUBES-1.ipynb +++ b/TUBES-1.ipynb @@ -5,7 +5,7 @@ "metadata": {}, "source": [ "# TUGAS BESAR 1 \n", - "### Mem" + "### Membuat gambar dengan algortima" ] }, { @@ -17,6 +17,13 @@ "from matplotlib import pyplot as plt" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Fungsi round untuk membulatkan angka " + ] + }, { "cell_type": "code", "execution_count": 2, @@ -27,6 +34,13 @@ " return int(a + 0.5)" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Algoritma DDA (Garis) " + ] + }, { "cell_type": "code", "execution_count": 3, @@ -52,19 +66,60 @@ " return x,y" ] }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'pd' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[0mround_y\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0mround\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[1;32min\u001b[0m \u001b[0my\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 5\u001b[1;33m \u001b[0mdf\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mDataFrame\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m{\u001b[0m\u001b[1;34m'x'\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'y'\u001b[0m\u001b[1;33m:\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 6\u001b[0m \u001b[0mrd\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mDataFrame\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m{\u001b[0m\u001b[1;34m'round(x)'\u001b[0m\u001b[1;33m:\u001b[0m\u001b[0mround_x\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'round(y)'\u001b[0m\u001b[1;33m:\u001b[0m\u001b[0mround_y\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[0mdf\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'round(x),round(y)'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m=\u001b[0m \u001b[1;34m\"{\"\u001b[0m\u001b[1;33m+\u001b[0m\u001b[0mrd\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"round(x)\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mastype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mstr\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m+\u001b[0m\u001b[1;34m\",\"\u001b[0m\u001b[1;33m+\u001b[0m \u001b[0mrd\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"round(y)\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mastype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mstr\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m+\u001b[0m\u001b[1;34m\"}\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mNameError\u001b[0m: name 'pd' is not defined" + ] + } + ], + "source": [ + "x, y = dda(20,10,30,10)\n", + "round_x = [round(x) for x in x]\n", + "round_y = [round(x) for x in y]\n", + "\n", + "df = pd.DataFrame({'x': x, 'y':y})\n", + "rd = pd.DataFrame({'round(x)':round_x, 'round(y)':round_y})\n", + "df['round(x),round(y)']= \"{\"+rd[\"round(x)\"].astype(str) +\",\"+ rd[\"round(y)\"].astype(str)+\"}\"\n", + "df" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Cerobong Asap " + ] + }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [], "source": [ - "\n", "xa, ya = dda(20,10,30,10)\n", "xb, yb = dda(30,10,30,40)\n", "xc, yc = dda(20,10,30,40)\n", "xd, yd = dda(20,40,30,40)" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Plotting Garis " + ] + }, { "cell_type": "code", "execution_count": 23,