miércoles, 22 de noviembre de 2017
programa que mueve dos lineas:
Autores:
Aylin Salazar Alvares
Guillermo Sanchez Castillo
Jose Roberto Jimenez Flores
Alberto Sanchez Fonseca
Jose Luis Vanoye Bocanegra
(mueve la linea con la tecla I (izquierda), D (derecha)
.model small ;Se define el modelo de la memoria.
;===========================================================================
; DECLARACION DEL SEGMENTO DE PILA
;===========================================================================
.stack 100 ;Se define el tama?o de la pila
;===========================================================================
; DECLARACION DEL SEGMENTO DE DATOS
;===========================================================================
.data ;define variables
y1 dw 180 ;Coordenadas l?nea 1, Variable de tipo write
x01 dw 320 ;Coordenadas l?nea 1, Variable de tipo write
y01 dw ? ;Coordenadas linea 1, Variable de tipo write
x02 dw 350 ;Coordenadas linea 2, Variable de tipo write
y02 dw ? ;Coordenadas linea 2, Variable de tipo write
color1 db 0ch ;Color de linea 1, Variable de tipo byte
color2 db 0ah ;Color de linea 2, Variable de tipo byte
negro db 00h ;Color de fondo
;===========================================================================
; DECLARACION DEL SEGMENTO DE CODIGO
;===========================================================================
.code ;Codigo
.startup ;Inicio
mov ax,@data ;Direccionamiento segmento de datos
mov ds,ax ;Se guarda lo que esta en ax en el segmento datos
push ds ;Coloca el contenido en la pila
pop es ;Llama el contenido de la pila
mov ax,0600h ;Direccionamiento segmento de datos
mov bh,00h ;BH:Registro de base
mov cx,0000h ;Registro en el mensaje
mov dx,314fh ;Registro de base
int 10h ;Interrupcion del BIOS
mov ah,0h ;Mostrar el numero digitado.
mov al,12h
int 10h
call dpixel
;===========================================================================
; DECLARACION DEL PROCEDIMIENTO KEY
;===========================================================================
key:
mov ah,08h ;AH:Acumulador
int 21h ;Interrupcion del DOS
cmp al,27 ;CMP:Comparacion entre dos operandos, funciona como una resta con la diferencia de que no afecta el destino unicamente los indicadores.
je salir ;Je:Salta si es igual a el procedimiento salir.
cmp al,100 ;'d' minuscula
je der ;Salta a derecha
cmp al,105 ;'i' minuscula
je izq ;Salta a izquierda
jmp key ;Salta al procedimiento key
;===========================================================================
; DECLARACION DEL PROCEDIMIENTO DERECHA
;===========================================================================
der:
call derecha ;Manda a llamar el procedimiento derecha
jmp key ;Salta al procedimiento key
;===========================================================================
; DECLARACION DEL PROCEDIMIENTO IZQUIERDA
;===========================================================================
izq:
call izquierda ;Manda a llamar el procedimiento izquierda.
jmp key ;Salta al procedimiento key
;===========================================================================
; DECLARACION DEL PROCEDIMIENTO SALIR
;===========================================================================
salir:
call termina ;Manda a llamar el procedimiento terminar.
;===========================================================================
borrow proc ;Pide las coordenadas en y.
mov ax,y1 ;Se guarda lo que esta en ax en la coordenada y1.
mov y01,ax ;Se guarda lo que esta en ax en la coordenada y01.
mov y02,ax ;Se guarda lo que esta en ax en la coordenada y02.
pix1:
mov ah,0ch ;Mostrar el numero digitado.
mov al,negro ;Linea de separacion color negra.
mov cx,x01 ;Registro en el mensaje en la coordenada de la primera linea x01
mov dx,y01 ;Registro de la base en la coordenada de la primera linea y01
int 10h ;Interrupcion del BIOS.
cmp dx,280 ;Coordenadas de movimiento ya sea derecha o izquierda.
je pix2 ;Salta a pedir las coordenadas de linea 2.
inc y01
jmp pix1
pix2:
mov ah,0ch
mov al,negro
mov cx,x02
mov dx,y02
int 10h ;Interrupcion del BIOS
cmp dx,280
je s1
inc y02
jmp pix2
s1:
ret
borrow endp ;Fin del procedimiento borrow.
;===========================================================================
dpixel proc
mov ax,y1
mov y01,ax
mov y02,ax
pixel1:
mov ah,0ch
mov al,color1
mov cx,x01
mov dx,y01
int 10h ;Interrupcion del BIOS
cmp dx,280
je pixel2
inc y01
jmp pixel1
pixel2:
mov ah,0ch
mov al,color2
mov cx,x02
mov dx,y02
int 10h ;Interrupcion del BIOS
cmp dx,280
je sales
inc y02
jmp pixel2
sales:
ret
dpixel endp
;===========================================================================
derecha proc
call borrow
mov ax,y1
mov y01,ax
mov y02,ax
inc x01
inc x02
cmp x02,639
je l1
jmp brinco1
l1:
mov ah,0ch
mov al,color2
mov cx,639
mov dx,y01
int 10h ;Interrupcion del BIOS
cmp dx,280
je l2
inc y01
jmp l1
l2:
mov ah,0ch
mov al,color1
mov cx,0000
mov dx,y02
int 10h
cmp dx,280
je s2
inc y02
jmp l2
brinco1:
call dpixel
s2:
ret
derecha endp
;===========================================================================
izquierda proc
call borrow
mov ax,y1
mov y01,ax
mov y02,ax
dec x01
dec x02
cmp x01,0000
je l3
jmp brinco2
l3:
mov ah,0ch
mov al,color2
mov cx,000
mov dx,y01
int 10h
cmp dx,280
je l4
inc y01
jmp l3
l4:
mov ah,0ch
mov al,color1
mov cx,639
mov dx,y02
int 10h ;Interrupcion del BIOS
cmp dx,280
je s3
inc y02
jmp l4
brinco2:
call dpixel
s3:
ret
izquierda endp
;===========================================================================
termina proc
mov ah,00h ;le regresa el control a MS-DOS
mov al,03h
int 10h ;Interrupcion del BIOS
.exit ;fin de procedimiento
termina endp
end ;fin del programa
martes, 7 de noviembre de 2017
Vértices cubo 3D python
Participacion de Eduardo Aquino:
http://eduardommm.blogspot.mx/
Cubo 3D
http://eduardommm.blogspot.mx/
Cubo 3D
import pygame from pygame.locals import * from OpenGL.GL import * from OpenGL.GLU import * verticies = ( (1, -1, -1),#0 (1, 1, -1),#1 (-1, 1, -1), (-1, -1, -1), (1, -1, 1), (1, 1, 1), (-1, -1, 1), (-1, 1, 1), ) edges = ( (0,1), (0,3), (0,4), (2,1), (2,3), (2,7), (6,3), (6,4), (6,7), (5,1), (5,4), (5,7) ) def Cube(): glBegin(GL_LINES) for edge in edges: for vertex in edge: glVertex3fv(verticies[vertex]) glEnd() def main(): pygame.init() display = (800,600) pygame.display.set_mode(display, DOUBLEBUF|OPENGL) gluPerspective(45, (display[0]/display[1]), 0.1, 50.0) glTranslatef(0.0,0.0, -5) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() glRotatef(1, 3, 1, 1) glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) Cube() pygame.display.flip() pygame.time.wait(10) main()
_______________________________________________
Triangulo 3D
import pygame from pygame.locals import * from OpenGL.GL import * from OpenGL.GLU import * verticies = ( (1, -1, -1), (1, 1, -1), (-1, 1, -1), (-1, -1, -1), (0,0,1) ) edges = ( (4,0), (4,1), (4,2), (4,3), (0,1), (0,3), (2,1), (2,3) ) def Cube(): glBegin(GL_LINES) for edge in edges: for vertex in edge: glVertex3fv(verticies[vertex]) glEnd() def main(): pygame.init() display = (800,600) pygame.display.set_mode(display, DOUBLEBUF|OPENGL) gluPerspective(45, (display[0]/display[1]), 0.1, 50.0) glTranslatef(0.0,0.0, -5) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() glRotatef(1, 3, 1, 1) glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) Cube() pygame.display.flip() pygame.time.wait(10) main()___________________________________________________CUBO COLOR 3Dimport sys, math, pygame from operator import itemgetter class Point3D: def __init__(self, x=0, y=0, z=0): self.x, self.y, self.z = float(x), float(y), float(z) def rotateX(self, angle): """ Rotates the point around the X axis by the given angle in degrees. """ rad = angle * math.pi / 180 cosa = math.cos(rad) sina = math.sin(rad) y = self.y * cosa - self.z * sina z = self.y * sina + self.z * cosa return Point3D(self.x, y, z) def rotateY(self, angle): """ Rotates the point around the Y axis by the given angle in degrees. """ rad = angle * math.pi / 180 cosa = math.cos(rad) sina = math.sin(rad) z = self.z * cosa - self.x * sina x = self.z * sina + self.x * cosa return Point3D(x, self.y, z) def rotateZ(self, angle): """ Rotates the point around the Z axis by the given angle in degrees. """ rad = angle * math.pi / 180 cosa = math.cos(rad) sina = math.sin(rad) x = self.x * cosa - self.y * sina y = self.x * sina + self.y * cosa return Point3D(x, y, self.z) def project(self, win_width, win_height, fov, viewer_distance): """ Transforms this 3D point to 2D using a perspective projection. """ factor = fov / (viewer_distance + self.z) x = self.x * factor + win_width / 2 y = -self.y * factor + win_height / 2 return Point3D(x, y, self.z) class Simulation: def __init__(self, win_width=640, win_height=480): pygame.init() self.screen = pygame.display.set_mode((win_width, win_height)) pygame.display.set_caption("Figura de cubo 3D en python") self.clock = pygame.time.Clock() self.vertices = [ Point3D(-1, 1, -1), Point3D(1, 1, -1), Point3D(1, -1, -1), Point3D(-1, -1, -1), Point3D(-1, 1, 1), Point3D(1, 1, 1), Point3D(1, -1, 1), Point3D(-1, -1, 1) ] # Define the vertices that compose each of the 6 faces. These numbers are # indices to the vertices list defined above. self.faces = [(0, 1, 2, 3), (1, 5, 6, 2), (5, 4, 7, 6), (4, 0, 3, 7), (0, 4, 5, 1), (3, 2, 6, 7)] # Define colors for each face self.colors = [(255, 0, 255), (255, 0, 0), (0, 255, 0), (0, 0, 255), (0, 255, 255), (255, 255, 0)] self.angle = 0 def run(self): """ Main Loop """ while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() self.clock.tick(50) self.screen.fill((0, 32, 0)) # It will hold transformed vertices. t = [] for v in self.vertices: # Rotate the point around X axis, then around Y axis, and finally around Z axis. r = v.rotateX(self.angle).rotateY(self.angle).rotateZ(self.angle) # Transform the point from 3D to 2D p = r.project(self.screen.get_width(), self.screen.get_height(), 256, 4) # Put the point in the list of transformed vertices t.append(p) # Calculate the average Z values of each face. avg_z = [] i = 0 for f in self.faces: z = (t[f[0]].z + t[f[1]].z + t[f[2]].z + t[f[3]].z) / 4.0 avg_z.append([i, z]) i = i + 1 # Draw the faces using the Painter's algorithm: # Distant faces are drawn before the closer ones. for tmp in sorted(avg_z, key=itemgetter(1), reverse=True): face_index = tmp[0] f = self.faces[face_index] pointlist = [(t[f[0]].x, t[f[0]].y), (t[f[1]].x, t[f[1]].y), (t[f[1]].x, t[f[1]].y), (t[f[2]].x, t[f[2]].y), (t[f[2]].x, t[f[2]].y), (t[f[3]].x, t[f[3]].y), (t[f[3]].x, t[f[3]].y), (t[f[0]].x, t[f[0]].y)] pygame.draw.polygon(self.screen, self.colors[face_index], pointlist) self.angle += 1 pygame.display.flip() if __name__ == "__main__": Simulation().run()___________________________________________________Grafico de barras en 3Dfrom mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt fig = plt.figure() ax1 = fig.add_subplot(111, projection='3d') xpos = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] ypos = [2,3,4,5,1,6,2,1,7,2,3,5,1,3,2] num_elements = len(xpos) zpos = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] dx = 1dy =1dz = [20,2,3,4,5,6,7,8,9,10,11,12,13,14,15] ax1.bar3d(xpos, ypos, zpos, dx, dy, dz, color='red') plt.show()
Suscribirse a:
Entradas (Atom)