Vistas de página en total

domingo, 6 de abril de 2014

EJEMPLO CON RECTANGULOS Y RECTANGULOS LLENOS

     Este es un ejemplo del estilo de los anteriores, para probar y mostrar el uso de la función rectangle y fillrectangle.

      Para poder usar las dos en un solo porgrama ejemplo he utilizado el teclado para distinguir uno de otro al dibujar. Si se pulsa el teclado se dibujará un fill rectangle. Si no se dibujará un rectangle.

    La selección de los vertices se hace igual en en los caso anteriores, eligiendo dos puntos con el ratón.
    Igualmente incremeto el color con cada recuadro, para que quede más vistoso.


 El ejemplo compilado lo podeis descargar aquí

EJ_REC.ASM
; Copyright (C) 2013  José Ángel Moneo Fernández

;    This program is free software: you can redistribute it and/or modify
;    it under the terms of the GNU General Public License as published by
;    the Free Software Foundation, either version 3 of the License, or
;   (at your option) any later version.

;    This program is distributed in the hope that it will be useful,
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;    GNU General Public License for more details.

;    You should have received a copy of the GNU General Public License
;    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
include main.mac
include stdio.mac
include mouse.mac
include graphics.mac

.model compact,pascal
.stack 200

.data
x0 dw 0
y0 dw 0
x1 dw 0
y1 dw 0

color dw 1

.code

principal proc far
        main
        modovideo 12h   ;inicia graficos
        resmouse         ;reinicia ratón
        mouse on         ; activa rarón
     
punto1:
        getmouse        ;espera  ESTÉ SIN PULSAR
        cmp ax,0
        jne punto1
pulsar1:       
        getmouse         ;verifica espera pulsación raton
        cmp ax,2      ;salir?
        jne sig1
        jmp fuera
sig1:       
        cmp ax,1      ;boton izquierdo?
        jne pulsar1
        getmousex
        mov x0,ax
        getmousey
        mov y0,ax
punto2:
        getmouse        ;espera soltar
        cmp ax,0
        jne punto2
pulsar2:      
        getmouse         ;verifica espera pulsación raton
        cmp ax,2      ;salir?
        je fuera
        cmp ax,1      ;boton izquierdo?
        jne pulsar2
        getmousex
        mov x1,ax
        getmousey
        mov y1,ax
       
       
        mov ax,color
        inc ax
        and ax,0fh
        mov color,ax      
   
       
        mouse off
     
        kbhit    ;comprueba si se ha pulsado el teclado
        jz rectangulo
        mov ah,0ch      ; vacio el bufer de teclado
        int 21h
     
        ;si es así dibuja rectangulos llenos
        fillrectangle  x0,y0,x1,y1,color
         mouse on
        jmp punto1
rectangulo:  
              
        rectangle x0,y0,x1,y1,color
        mouse on
        jmp punto1
fuera:
        modovideo t80col
        resmouse
        mouse off 
        exit  0
principal endp

end




viernes, 4 de abril de 2014

FILL RECTANGLE

Función para realizar RECTANGULOS RELLENOS apoyandolnos en la función LINEA.

Macro DE LLAMADA para ampliar en GRAPHICS.MAC

GRAPHICS.MAC
;Dibuja un rectangulo lleno
fillrectangle macro x0,y0,x1,y1,color
ifndef _fillrectangle
        extrn _fillrectangle:near
endif
        mov ax,x0
        push ax
        mov ax,y0
        push ax
        mov ax,x1
        push ax
        mov ax,y1
        push ax
        mov ax,color
        push ax
        call _fillrectangle
        

 endm  


FRECTAN.ASM
; Copyright (C) 2013  José Ángel Moneo Fernández

;    This program is free software: you can redistribute it and/or modify
;    it under the terms of the GNU General Public License as published by
;    the Free Software Foundation, either version 3 of the License, or
;   (at your option) any later version.

;    This program is distributed in the hope that it will be useful,
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;    GNU General Public License for more details.

;    You should have received a copy of the GNU General Public License
;    along with this program.  If not, see <http://www.gnu.org/licenses/>.
.model compact,pascal

        public _fillrectangle
.data

.code
       ;algoritmo Bresenham
_fillrectangle proc uses ax cx bx ,x0,y0,x1,y1,color
        mov cx,y0
        mov bx,y1
        mov ax,y0       ;COMPRUEBA EL MAYOR PARA ORDENAR EL BUCLE
        cmp ax,y1
        jbe correcto
        ;invertir  las y
        mov cx,y1       
        mov bx,y0
correcto:                        ;BUCLE DE LÍNEAS
        line x0,cx,x1,cx,color
        inc cx
        cmp cx,bx
        jne correcto
        ret
_fillrectangle endp

end

miércoles, 2 de abril de 2014

RECTANGLE


Función para realizar rectangulos apoyandolnos en la función linea.

Macro DE LLAMADA para ampliar en GRAPHICS.MAC

GRAPHICS.MAC
;Dibuja un rectangulo
rectangle macro x0,y0,x1,y1,color
ifndef _rectangle
        extrn _rectangle:near
endif
        mov ax,x0
        push ax
        mov ax,y0
        push ax
        mov ax,x1
        push ax
        mov ax,y1
        push ax
        mov ax,color
        push ax
        call _rectangle
       
 endm 




RECTAN.ASM
; Copyright (C) 2013  José Ángel Moneo Fernández

;    This program is free software: you can redistribute it and/or modify
;    it under the terms of the GNU General Public License as published by
;    the Free Software Foundation, either version 3 of the License, or
;   (at your option) any later version.

;    This program is distributed in the hope that it will be useful,
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;    GNU General Public License for more details.

;    You should have received a copy of the GNU General Public License
;    along with this program.  If not, see <http://www.gnu.org/licenses/>.
include graphics.mac


.model compact,pascal

        public _rectangle
.data

.code
       ;algoritmo Bresenham
_rectangle proc uses ,x0,y0,x1,y1,color
        line x0,y0,x1,y0,color
        line x0,y1,x1,y1,color
        line x0,y0,x0,y1,color
        line x1,y0,x1,y1,color
        ret
_rectangle endp

end