Graficacin IA 7200 T Primitivas de Dibujo y
Graficación IA 7200 -T Primitivas de Dibujo y Transformaciones Programas en Java Graficación
Contenido • Primitivas de Dibujo – Swing de Java: • draw. Line() • draw. Rect() • draw. String() – Formas Simples: • Rectangle • Ellipse • Aplicaciones de Java – Objetos JFrame – Objetos JPanel Graficación • Trasformaciones de Coordenadas – – Translación Rotación Escalamiento Deformación (Shearing) • Recortes de Coordenadas – Rectilineo – Por forma 2
Aplicaciones Java • Programas completos que • pueden ser ejecutados de forma independiente • Es más difícil escribir programas simples que • Applets Demasiado código alrededor de la aplicación, que los applets proporcionan de manera automática Heredar (Extend) de un Frame o JFrame • Jframe = entidad Swing Graficación 3
Aplicaciones Java • My. Prog 01 – Rectángulo negro en fondo blanco • Estructura: – Un JPanel dentro de un JFrame – Método paint. Component() – Más acerca de Java y Swing en el curso Graficación • El manejador de ventanas lanza una ventana independiente para la aplicación, con sus propias gráficas, botones, etc. • Se puede correr desde una terminal 4
Aplicaciones Java • My. Prog 02 – Misma estructura que My. Prog 01 – Diferentes comandos de graficación • Cada vez que el sistema llama a paint. Component() se imprime: paint. Component: ancho=532 paint. Component: alto=532 • Se puede usar set. Resizeable(true) para que el usuario pueda cambiar el tamaño se la ventana en tiempo de ejecución. Graficación 5
Transformaciones: Translación • translate(x, y); • Puede ser aplicado e objetos de tipo Graphics 2 D Graficación • Desplaza el origen en magnitudes x, y • No distorsiona • Desliza el dibujo en el espacio de Coordenadas Cartesianas 6
Transformaciones: Rotación • rotate(angulo); • Angulo debe estar en radianes • 360°= 2 π radianes • Puede ser aplicado a Graphics y Graphics 2 D Graficación • Rota el dibujo • Un ángulo positivo va del eje +x al eje +y • Recuerden que y “va hacia abajo” 7
Transformaciones: Escalamiento • scale(x, y); • Puede usarse con Graphics y Graphics 2 D Graficación • Estira o encoge el espacio de coordenadas • Ejemplo: – scale( 1. 0, -1. 0); – Hace que la y “vaya hacia arriba” 8
Transformaciones: Deformación (Shearing) • shear(shx, shy); • Distorciona el espacio de dibujo • El primer argumento es la deformación en dirección x, como factor de y • Puede ser usado con • El segundo es la Graphics y Graphics 2 D deformación de y como factor de x Graficación 9
Aplicaciones Java • My. Prog 03 – Mismo código que My. Prog 01 y 02 – Demuestra las Transformaciones Afines – y corre hacia abajo, los ángulos positivos se ven como negativos – Ángulos positivos van de +x a +y (convención) • Más tarde estudiaremos la trigonometría y álgebra lineal de estas transformaciones Graficación 10
Aplicaciones Java • • My. Prog 04 Mismo código que 01 -03 Usa una Constante int SQUARE_SIZE =10 Dibuja un patrón espiral usando transformaciones afines sucesivas • Rota 12 grados, y traslada progresivamente Graficación 11
Aplicaciones Java • My. Prog 05 • Ejemplo de Recorte (Clipping) • Clipping es limitar el área de dibujo - i. e. Recortando partes indeseadas • Podemos usar recortes rectlíneos simples • O mas complejos - v. g. un círculo Graficación 12
Resumen • Podemos escribir aplicaciones de Java que corren en su propia ventana usando JFrames • La biblioteca de Swing tiene muchas primitivas interesantes para dibujo • Hay muchas formas geométricas útiles y rutinas diversas Graficación • Las Transformaciones pueden ser aplicadas al espacio de coordenadas de dibujo • Se puede hacer Clipping para limitar lo que dibujamos • Los programas estudiados usan código estático de dibujo • Escribiremos programas más interesantes que decidan dinámicamente que dibujar (render)… 13
- Slides: 13