Created
November 10, 2014 18:40
-
-
Save vencejo/b6d965cfbea9a5433043 to your computer and use it in GitHub Desktop.
Aprendiendo a programar con Python y Minecraft
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metadata": { | |
"kernelspec": { | |
"codemirror_mode": { | |
"name": "python", | |
"singleOperators": {}, | |
"version": 2 | |
}, | |
"display_name": "IPython (Python 2)", | |
"language": "python", | |
"name": "python2" | |
}, | |
"name": "", | |
"signature": "sha256:128d9de97ac17b046cf0f13f8b75fc657e0576f47bd162e30fa4a31836e56e31" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"#Indice\n", | |
"<a name=\"indice\"></a>\n", | |
"\n", | |
"* <a href=\"#importaciones\">Importaciones b\u00e1sicas y conexi\u00f3n</a>\n", | |
"* <a href=\"#practicando\">Practicando las instrucciones b\u00e1sicas</a>\n", | |
" - <a href=\"#variables\">Variables</a>\n", | |
" - <a href=\"#explotando\">Explotando ciclos for</a>\n", | |
" - <a href=\"#sentencia\">Sentencia if en el palacio del diamante maldito</a>\n", | |
"* <a href=\"#intermedio\">Python intermedio: Funciones</a>\n", | |
" - <a href=\"#elbosque\">El bosque de las funciones</a>\n", | |
" - <a href=\"#historia\">Haciendo la tarea de Historia: Las piramides de Egipto</a>\n", | |
" - <a href=\"#biologia\">Haciendo la tarea de Biolog\u00eda: Los Virus atacan</a>\n", | |
"* <a href=\"#avanzado\">Python \"avanzado\": Programacion orientada a objetos</a>\n", | |
" - <a href=\"#matematicas\">Haciendo la tarea de Matem\u00e1ticas: Fractales</a>" | |
] | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 1, | |
"metadata": {}, | |
"source": [ | |
"Importaciones b\u00e1sicas y conexi\u00f3n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"<a href=\"#indice\">Volver al \u00edndice</a>\n", | |
"\n", | |
"<a name=\"importaciones\"></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"#import the minecraft.py module from the minecraft directory\n", | |
"import mcpi.minecraft as minecraft\n", | |
"#import minecraft block module\n", | |
"import mcpi.block as block\n", | |
"import time \n", | |
"\n", | |
"#connect to minecraft\n", | |
"mc = minecraft.Minecraft.create(\"192.168.1.18\")" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 1 | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 1, | |
"metadata": {}, | |
"source": [ | |
"Practicando las instrucciones b\u00e1sicas con algunas construcciones" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"<a href=\"#indice\">Volver al \u00edndice</a>\n", | |
"\n", | |
"<a name=\"practicando\"></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"mc.postToChat(\"hola a todos, bienvenidos al taller de Python con Minecraft\")\n", | |
"time.sleep(4)\n", | |
"mc.postToChat(\"Se aceptan mensajes de los asistentes !!!\")" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 2 | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 3, | |
"metadata": {}, | |
"source": [ | |
"Variables" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"<a href=\"#indice\">Volver al \u00edndice</a>\n", | |
"\n", | |
"<a name=\"variables\"></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"x , y , z = 0 , 100, 0 \n", | |
"\n", | |
"mc.player.setTilePos(x,y,z) # cambia la posicion del jugador a las cordenadas x, y,y z" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 4 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"posicion = mc.player.getTilePos() #Coge la posicion del jugador y la guarda en una variable \n", | |
"\n", | |
"#Pone un bloque de un tipo determinado en una posicion determinada\n", | |
"# los primeros tres parametros son las cordenadas y el cuarto es el tipo de objeto \n", | |
"mc.setBlock(posicion.x + 1,posicion.y,posicion.z ,block.WATER) \n", | |
"\n", | |
"# La lista de bloques disponibles se puede ver activando la siguiente linea\n", | |
"# load ./mcpi/block.py\n" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 11 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"pos = mc.player.getTilePos() #Coge la posicion del jugador y la guarda en la variable pos\n", | |
"\n", | |
"x = pos.x\n", | |
"y = pos.y\n", | |
"z = pos.z\n", | |
" \n", | |
"mc.setBlock(x,y,z+2,35,1)\n", | |
"mc.setBlock(x,y,z+3,35,2)\n", | |
"mc.setBlock(x,y,z+4,35,3)\n", | |
"mc.setBlock(x,y,z+5,35,4)\n", | |
"mc.setBlock(x,y,z+6,35,5)\n", | |
"mc.setBlock(x,y,z+7,35,6)\n", | |
"mc.setBlock(x,y,z+8,35,7)\n", | |
"mc.setBlock(x,y,z+9,35,8)\n", | |
"mc.setBlock(x,y,z+10,35,9)\n", | |
"mc.setBlock(x,y,z+11,35,10)\n", | |
"mc.setBlock(x,y,z+12,35,11)\n", | |
"mc.setBlock(x,y,z+13,35,12)\n", | |
"mc.setBlock(x,y,z+14,35,13)\n", | |
"mc.setBlock(x,y,z+15,35,14)\n", | |
"mc.setBlock(x,y,z+16,35,15)\n", | |
"mc.setBlock(x,y,z+17,35,16)\n", | |
"\n", | |
"# \u00bfVaya rollo de repetici\u00f3n no ?\n" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 6 | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 3, | |
"metadata": {}, | |
"source": [ | |
"Explotando los ciclos for \n", | |
"\n", | |
"\n", | |
"\n", | |
"\n", | |
" \n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"<a href=\"#indice\">Volver al \u00edndice</a>\n", | |
"\n", | |
"<a name=\"explotando\"></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"pos = mc.player.getTilePos() #Coge la posicion del jugador y la guarda en la variable pos\n", | |
"\n", | |
"for i in range(18):\n", | |
" mc.setBlock(pos.x,pos.y,pos.z+i+2,35,i+1)\n", | |
" " | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 10 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"for i in range(18):\n", | |
" mc.setBlock(pos.x,pos.y,pos.z+i+2,35,i+1)\n", | |
" for j in range(18):\n", | |
" mc.setBlock(pos.x,pos.y+j,pos.z+i+2,35,i+1)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 8 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# Algunos metodos del paquete Minecraft ya llevan ciclos dentro\n", | |
"\n", | |
"# Bloque de TNT Armado\n", | |
"mc.setBlocks(pos.x,pos.y,pos.z+2,pos.x+2,pos.y+2,pos.z+2,46,1)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 11 | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 3, | |
"metadata": {}, | |
"source": [ | |
"Sentencia If en el palacio del diamante maldito" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"<a href=\"#indice\">Volver al \u00edndice</a>\n", | |
"\n", | |
"<a name=\"sentencia\"></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"pos = mc.player.getTilePos() #Coge la posicion del jugador y la guarda en la variable pos" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 2 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"#creo el Cubo macizo\n", | |
"\n", | |
"longArista = 15\n", | |
"distPerObj = 5 # Distancia del personaje al objeto creado\n", | |
"\n", | |
"esquinaInferior = (pos.x + distPerObj, pos.y, pos.z + distPerObj ) # Tupla\n", | |
"esquinaSuperior = (pos.x + distPerObj + longArista , pos.y + distPerObj + longArista, pos.z + distPerObj + longArista )\n", | |
"\n", | |
"mc.setBlocks(esquinaInferior,esquinaSuperior,block.STAIRS_COBBLESTONE)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 3 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"#creo un cubo de aire en el interor del anterior\n", | |
"esquinaInferior = (esquinaInferior[0] + 1 , esquinaInferior[1] + 1, esquinaInferior[2] + 1 )\n", | |
"esquinaSuperior = (esquinaSuperior[0] - 2 , esquinaSuperior[1] - 1 , esquinaSuperior[2] -1 )\n", | |
"\n", | |
"mc.setBlocks(esquinaInferior,esquinaSuperior,block.AIR)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 4 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# para hacer la puerta\n", | |
"esquinaInferior = (pos.x + 10 , pos.y, pos.z + 5 )\n", | |
"esquinaSuperior = (pos.x + 17 , pos.y + 7 , pos.z + 5 )\n", | |
"\n", | |
"mc.setBlocks(esquinaInferior,esquinaSuperior,block.AIR)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 5 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"#hacemos la capa de lava\n", | |
"esquinaInferior = (pos.x + distPerObj, pos.y -1 , pos.z + distPerObj )\n", | |
"esquinaSuperior = (pos.x + distPerObj + longArista , pos.y -2 , pos.z + distPerObj + longArista )\n", | |
"\n", | |
"mc.setBlocks(esquinaInferior,esquinaSuperior,block.LAVA_STATIONARY)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 6 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"#hacemos el bloque del diamante \n", | |
"\n", | |
"# pedestal\n", | |
"mc.setBlock(pos.x + 15,pos.y+1 ,pos.z + 15,1) \n", | |
"# diamante\n", | |
"coordsDiamante = (pos.x + 15,pos.y + 2,pos.z + 15) \n", | |
"\n", | |
"mc.setBlock(coordsDiamante,block.DIAMOND_BLOCK)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 7 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# Ciclo infinito que controla si cogemos el diamante, en cuyo caso ...\n", | |
"while True:\n", | |
" tipoDeBloque = mc.getBlock(coordsDiamante)\n", | |
" \n", | |
" if tipoDeBloque == block.AIR:\n", | |
" #hacemos desaparecer el suelo\n", | |
" esquinaInferior = (pos.x + distPerObj, pos.y , pos.z + distPerObj )\n", | |
" esquinaSuperior = (pos.x + distPerObj + longArista , pos.y - 1 , pos.z + distPerObj + longArista )\n", | |
" mc.setBlocks(esquinaInferior,esquinaSuperior,block.AIR) " | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 1, | |
"metadata": {}, | |
"source": [ | |
"Python Intermedio: Funciones" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"<a href=\"#indice\">Volver al \u00edndice</a>\n", | |
"\n", | |
"<a name=\"intermedio\"></a>" | |
] | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 3, | |
"metadata": {}, | |
"source": [ | |
"El bosque de las funciones" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"<a href=\"#indice\">Volver al \u00edndice</a>\n", | |
"\n", | |
"<a name=\"elbosque\"></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# Este es el codigo para plantar un arbol delante del jugador\n", | |
"follaje = 18\n", | |
"tronco = 17\n", | |
"\n", | |
"x , y , z = mc.player.getTilePos() #Coge la posicion del jugador y la guarda en las variables x, y , z\n", | |
"x = x + 5 # Para que el arbol no nazca del cuerpo del propio jugador\n", | |
"\n", | |
"mc.setBlock(x,y,z,tronco)\n", | |
"mc.setBlock(x,y+1,z,tronco)\n", | |
"mc.setBlock(x,y+2,z,tronco)\n", | |
"mc.setBlock(x,y+3,z,tronco)\t\n", | |
"mc.setBlock(x,y+4,z,follaje)\n", | |
"mc.setBlock(x+1,y+4,z+1,follaje)\n", | |
"mc.setBlock(x-1,y+4,z-1,follaje)\n", | |
"mc.setBlock(x+1,y+4,z-1,follaje)\n", | |
"mc.setBlock(x-1,y+4,z+1,follaje)\n", | |
"mc.setBlock(x,y+5,z,follaje)\n", | |
"mc.setBlock(x-1,y+5,z,follaje)\n", | |
"mc.setBlock(x+1,y+5,z,follaje) \n", | |
"mc.setBlock(x,y+5,z,follaje) \n", | |
"mc.setBlock(x,y+6,z,follaje)\n", | |
"mc.setBlock(x-1,y+3,z,follaje)\n", | |
"mc.setBlock(x-2,y+3,z,follaje)\n", | |
"mc.setBlock(x+1,y+3,z,follaje)\n", | |
"mc.setBlock(x+2,y+3,z,follaje)\n", | |
"mc.setBlock(x,y+3,z+1,follaje)\n", | |
"mc.setBlock(x,y+3,z-1,follaje)\n", | |
"mc.setBlock(x,y+3,z+2,follaje)\n", | |
"mc.setBlock(x,y+3,z-2,follaje)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 4 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# \u00bfY si queremos plantar un Bosque ?\n", | |
"def growTree(x,y,z):\n", | |
"\t\"\"\" Esta funcion hace crecer un arbol en las cordenadas x,y,z y si esas cordenadas son aire \n", | |
" las va disminuyendo hasta que encuentra algo distinto al aire o al agua \"\"\"\n", | |
"\tfollaje = 18\n", | |
"\ttronco = 17\n", | |
"\t\n", | |
"\ttipoBloqueBase = mc.getBlock (x,y-1,z)\n", | |
"\t#Va disminuyendo la cordenada \"y\" hasta encontrar algo distinto del agua o el aire\n", | |
"\twhile tipoBloqueBase == 0 or tipoBloqueBase == 8 or tipoBloqueBase == 9 :\n", | |
"\t\ty = y-1\n", | |
"\t\ttipoBloqueBase = mc.getBlock (x,y,z)\n", | |
"\t\t\n", | |
"\tmc.setBlock(x,y,z,tronco)\n", | |
"\tmc.setBlock(x,y+1,z,tronco)\n", | |
"\tmc.setBlock(x,y+2,z,tronco)\n", | |
"\tmc.setBlock(x,y+3,z,tronco)\t\n", | |
"\tmc.setBlock(x,y+4,z,follaje)\n", | |
"\tmc.setBlock(x+1,y+4,z+1,follaje)\n", | |
"\tmc.setBlock(x-1,y+4,z-1,follaje)\n", | |
"\tmc.setBlock(x+1,y+4,z-1,follaje)\n", | |
"\tmc.setBlock(x-1,y+4,z+1,follaje)\n", | |
"\tmc.setBlock(x,y+5,z,follaje)\n", | |
"\tmc.setBlock(x-1,y+5,z,follaje)\n", | |
"\tmc.setBlock(x+1,y+5,z,follaje) \n", | |
"\tmc.setBlock(x,y+5,z,follaje) \n", | |
"\tmc.setBlock(x,y+6,z,follaje)\t\n", | |
"\tmc.setBlock(x-1,y+3,z,follaje)\n", | |
"\tmc.setBlock(x-2,y+3,z,follaje)\n", | |
"\tmc.setBlock(x+1,y+3,z,follaje)\n", | |
"\tmc.setBlock(x+2,y+3,z,follaje)\t\t\t\n", | |
"\tmc.setBlock(x,y+3,z+1,follaje)\t\n", | |
"\tmc.setBlock(x,y+3,z-1,follaje)\t\n", | |
"\tmc.setBlock(x,y+3,z+2,follaje)\n", | |
"\tmc.setBlock(x,y+3,z-2,follaje)\n", | |
"\n", | |
"def bosque(x,y,z,n):\n", | |
" \"\"\"Crea un bosque haciendo crecer n arboles \"\"\"\n", | |
" d = 0\n", | |
" for i in range(n):\n", | |
" growTree(x+d,y,z)\n", | |
" d += 6\n", | |
" \n", | |
"\n", | |
"pos = mc.player.getTilePos() #Coge la posicion del jugador y la guarda en la variable pos\n", | |
"\n", | |
"bosque(pos.x + 3, pos.y, pos.z, 5) #crea un bosque delante del jugador\n" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 16 | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 3, | |
"metadata": {}, | |
"source": [ | |
"Haciendo la tarea de historia: Construimos nuestras propia pir\u00e1mide como las de Egipto" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"<a href=\"#indice\">Volver al \u00edndice</a>\n", | |
"\n", | |
"<a name=\"historia\"></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"import minecraftstuff\n", | |
"\n", | |
"# Utilizaremos la librer\u00eda de dibujo de formas geometricas de Martin O.Hanlon\n", | |
"# http://www.stuffaboutcode.com/2013/11/coding-shapes-in-minecraft.html\n", | |
"mcd = minecraftstuff.MinecraftDrawing(mc)\n", | |
"\n", | |
"playerTilePos = mc.player.getTilePos()\n", | |
"x=playerTilePos.x\n", | |
"y=playerTilePos.y\n", | |
"z=playerTilePos.z\n", | |
"\n", | |
"def dibujaPiramide (pos,altura,anchura,largura,tipoBloque): \n", | |
"\t\n", | |
"\tx=pos.x\n", | |
"\ty=pos.y\n", | |
"\tz=pos.z\n", | |
"\t\t\n", | |
"\t#base\n", | |
"\tmc.setBlocks(x, y, z, x+largura, y, z+anchura, block.WOOD)\n", | |
"\t\n", | |
"\t#puntos de la 1\n", | |
"\tpuntosA = []\n", | |
"\tpuntosA.append(minecraft.Vec3 (x,y,z)) #posicion inicial del jugador y vertice de la piramide\n", | |
"\tpuntosA.append(minecraft.Vec3(x+largura/2,y+altura,z+anchura/2))\n", | |
"\tpuntosA.append(minecraft.Vec3(x,y,z+anchura))\n", | |
"\t#Dibuja los puntos y los une\n", | |
"\tmcd.drawFace(puntosA, True, tipoBloque)\n", | |
"\t\n", | |
"\t#puntos cara 2\n", | |
"\tpuntosB = []\n", | |
"\tpuntosB.append(minecraft.Vec3 (x,y,z))\n", | |
"\tpuntosB.append(minecraft.Vec3(x+largura/2,y+altura,z+anchura/2))\n", | |
"\tpuntosB.append(minecraft.Vec3(x+largura,y,z))\n", | |
"\t\n", | |
"\t#Dibuja los puntos y los une\n", | |
"\tmcd.drawFace(puntosB, True, tipoBloque)\n", | |
"\t\n", | |
"\t#puntos de la 3 (copia de la 1, desplazada)\n", | |
"\tpuntosC = []\n", | |
"\tpuntosC.append(minecraft.Vec3 (x+largura,y,z))\n", | |
"\tpuntosC.append(minecraft.Vec3(x+largura/2,y+altura,z+anchura/2))\n", | |
"\tpuntosC.append(minecraft.Vec3(x+largura,y,z+anchura))\n", | |
"\t#Dibuja los puntos y los une\n", | |
"\tmcd.drawFace(puntosC, True, tipoBloque)\n", | |
"\t\n", | |
"\t#puntos cara 4(copia de la 2 desplazada)\n", | |
"\tpuntosD = []\n", | |
"\tpuntosD.append(minecraft.Vec3 (x,y,z+anchura))\n", | |
"\tpuntosD.append(minecraft.Vec3(x+largura/2,y+altura,z+anchura/2))\n", | |
"\tpuntosD.append(minecraft.Vec3(x+largura,y,z+anchura))\n", | |
"\t\n", | |
"\t#Dibuja los puntos y los une\n", | |
"\tmcd.drawFace(puntosD, True, tipoBloque)\n", | |
"\n", | |
"\n", | |
"altura = 23\n", | |
"anchura = 23\n", | |
"largura = 23 \n", | |
"\n", | |
"# La Piramide propiamente dicha\n", | |
"dibujaPiramide (playerTilePos,altura,anchura,largura,block.GOLD_BLOCK.id) # Probar tambien con block.GLASS\n", | |
"# Pongo antorchas para ver en el interior\n", | |
"mc.setBlocks(x +2, y+1, z + 2, x+largura-2, y+1 , z+anchura-2, block.TORCH)\n", | |
"# Hago la entrada\n", | |
"mc.setBlocks(x , y, z , x+4, y+4 , z+4, block.AIR)\n" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 12 | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 3, | |
"metadata": {}, | |
"source": [ | |
"Haciendo la tarea de Biolog\u00eda: Los Virus atacan la c\u00e9lula" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"<a href=\"#indice\">Volver al \u00edndice</a>\n", | |
"\n", | |
"<a name=\"biologia\"></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# El virus" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 4 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# mira la posicion del jugador y el bloque que hay debajo\n", | |
"playerTilePos = mc.player.getTilePos()\n", | |
"\n", | |
"initCord = (playerTilePos.x +2 , playerTilePos.y + 10, playerTilePos.z + 2)\n", | |
"\n", | |
"invader1 = [ [0,0,1,0,0,0,0,0,1,0,0],\n", | |
"\t\t\t[0,0,0,1,0,0,0,1,0,0,0],\n", | |
"\t\t\t[0,0,1,1,1,1,1,1,1,0,0],\n", | |
"\t\t\t[0,1,1,0,1,1,1,0,1,1,0],\n", | |
"\t\t\t[1,0,1,1,1,1,1,1,1,0,1],\n", | |
"\t\t\t[1,0,1,1,1,1,1,1,1,0,1],\n", | |
"\t\t\t[1,0,1,0,0,0,0,0,1,0,1],\n", | |
"\t\t\t[0,0,0,1,1,0,1,1,0,0,0]]\n", | |
"\n", | |
"invader2\t= [[1,0,1,0,0,0,0,0,1,0,1],\n", | |
"\t\t\t\t[1,0,0,1,0,0,0,1,0,0,1],\n", | |
"\t\t\t\t[1,0,1,1,1,1,1,1,1,0,1],\n", | |
"\t\t\t\t[0,1,1,0,1,1,1,0,1,1,0],\n", | |
"\t\t\t\t[0,0,1,1,1,1,1,1,1,0,0],\n", | |
"\t\t\t\t[0,0,1,1,1,1,1,1,1,0,0],\n", | |
"\t\t\t\t[0,0,1,0,0,0,0,0,1,0,0],\n", | |
"\t\t\t\t[0,0,1,0,0,0,0,0,1,0,0]]\n", | |
"\t\t\t\t\t\t\t\t\t\n", | |
"numFilas = len(invader1)\n", | |
"numColums = len(invader1[0])\n", | |
"\n", | |
"\n", | |
"\t\t\t\t\n", | |
"def dibujaInvader (x, y, z, tipoBloque, dibujo):\n", | |
"\t\t\t\n", | |
"\tfor fila in range(numFilas):\n", | |
"\t\tfor columna in range (numColums):\n", | |
"\t\t\tif dibujo[fila][columna] == 1:\n", | |
"\t\t\t\tmc.setBlock(x+columna,y-fila,z, tipoBloque)\t\n", | |
"\t\t\telse:\n", | |
"\t\t\t\tmc.setBlock(x+columna,y-fila,z, block.AIR)\n", | |
"\t\t\t\t\n", | |
"def borraInvader (x, y, z):\n", | |
"\t\t\t\n", | |
"\tfor fila in range(numFilas):\n", | |
"\t\tfor columna in range (numColums):\n", | |
"\t\t\tmc.setBlock(x+columna,y-fila,z, block.AIR)\n", | |
"\n", | |
"def moverInvaderZ(velocidad,pausa):\n", | |
"\tpasos = 0\n", | |
"\t\n", | |
"\twhile True :\t\t\t\n", | |
"\t\tdibujaInvader(playerTilePos.x , playerTilePos.y+5, playerTilePos.z -20 +pasos, block.OBSIDIAN, invader1)\t\t\t\n", | |
"\t\ttime.sleep(pausa)\n", | |
"\t\tborraInvader (playerTilePos.x , playerTilePos.y+5, playerTilePos.z -20 +pasos)\n", | |
"\t\ttime.sleep(pausa)\n", | |
"\t\tdibujaInvader (playerTilePos.x , playerTilePos.y+5, playerTilePos.z -20 +pasos, block.OBSIDIAN, invader2)\t\n", | |
"\t\ttime.sleep(pausa)\n", | |
"\t\tborraInvader (playerTilePos.x , playerTilePos.y+5, playerTilePos.z -20 +pasos)\n", | |
"\t\tpasos += velocidad\n", | |
"\t\n", | |
"moverInvaderZ(3, 0.2)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# La Celula(s)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"import minecraftstuff\n", | |
"\n", | |
"playerTilePos = mc.player.getTilePos()\n", | |
"\n", | |
"x=playerTilePos.x\n", | |
"y=playerTilePos.y\n", | |
"z=playerTilePos.y\n", | |
"\n", | |
"#create drawing object\n", | |
"mcDrawing = minecraftstuff.MinecraftDrawing(mc)\n", | |
"\n", | |
"radioMembrana = 15\n", | |
"radioNucleo = 7\n", | |
"#sphere\n", | |
"mcDrawing.drawSphere(x,y,z,radioMembrana,block.GLASS_PANE.id)\n", | |
"mcDrawing.drawSphere(x,y,z,radioMembrana - 1,block.AIR.id)\n", | |
"mcDrawing.drawSphere(x,y,z,radioNucleo,block.GLASS_PANE.id)\n", | |
"mcDrawing.drawSphere(x,y,z,radioNucleo - 1,block.WATER.id)\n", | |
"mcDrawing.drawSphere(x,y,z,radioNucleo - 3,block.STONE.id)\n", | |
"mcDrawing.drawSphere(x,y,z,radioNucleo - 5,block.LAVA.id)\n", | |
"\n", | |
"# Moverse por el mundo y crear varias c\u00e9lulas solapadas ejecutando este codigo\n", | |
" \n" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 5 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": true, | |
"input": [ | |
"#La Invasi\u00f3n\n", | |
"\n", | |
"from IPython.display import YouTubeVideo\n", | |
"\n", | |
"YouTubeVideo('4mFZ5r48I30')" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"html": [ | |
"\n", | |
" <iframe\n", | |
" width=\"400\"\n", | |
" height=300\"\n", | |
" src=\"https://www.youtube.com/embed/4mFZ5r48I30\"\n", | |
" frameborder=\"0\"\n", | |
" allowfullscreen\n", | |
" ></iframe>\n", | |
" " | |
], | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 8, | |
"text": [ | |
"<IPython.lib.display.YouTubeVideo at 0xb4cf3bac>" | |
] | |
} | |
], | |
"prompt_number": 8 | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 1, | |
"metadata": {}, | |
"source": [ | |
"Python \"Avanzado\" : Programaci\u00f3n orientada a objetos" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"<a href=\"#indice\">Volver al \u00edndice</a>\n", | |
"\n", | |
"<a name=\"avanzado\"></a>" | |
] | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 3, | |
"metadata": {}, | |
"source": [ | |
" Haciendo la tarea de Matem\u00e1ticas, creando tus propios mundos fractales" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"<a href=\"#indice\">Volver al \u00edndice</a>\n", | |
"\n", | |
"<a name=\"matematicas\"></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": true, | |
"input": [ | |
"from IPython.display import FileLink, FileLinks\n", | |
"FileLink('Creando tus propios mundos fractales.ipynb')" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"html": [ | |
"<a href='Creando tus propios mundos fractales.ipynb' target='_blank'>Creando tus propios mundos fractales.ipynb</a><br>" | |
], | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 16, | |
"text": [ | |
"/media/dj/Nuevo vol/Informacion Importante (Replicada en web)/Estudios en Curso/Python/ipython/Charla Python en la educacion/Creando tus propios mundos fractales.ipynb" | |
] | |
} | |
], | |
"prompt_number": 16 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment