Вы находитесь на странице: 1из 6

INTRODUCCIN En el siguiente trabajo colaborativo pretendemos presentar una serie de concepto y definiciones propios del estudio de los Algoritmos,

su anlisis y diseo. En el mismo podremos encontrar los conceptos de algoritmo y algunos de sus componentes, anlisis y diseo. Tambin veremos los diferentes tipos de formas y tamaos o medidas en que se pueden almacenar y representar los datos y estructuras en un algoritmo o programa. OBJETIVOS Familiarizar al estudiante con los algoritmos bsicos de la Computacin Grfica. Introducir al estudiante en los principales algoritmos utilizados en Computacin Realizacin de ejercicios en JAVA PROBLEMA 1 Realice un programa Java que guarde en un vector las frecuencias encontradas en el anlisis de un determinado fenmeno y permita construir un grfico de torta donde se muestren los porcentajes de cada una de las frecuencias y un histograma de frecuencias (grfico de barras). *************************************************************** **************** import java.io.FileOutputStream; import java.util.Vector; import java.util.StringTokenizer; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.*; /**

* @param row Row. * @param i posicion en la fila. * @param value texto a escribir. * @param style estilo de la celda. */ public static void createCell(Row row, int i, String value, CellStyle style) { Cell cell = row.createCell(i); value = value+" "; cell.setCellValue(value); // si no hay estilo, no se aplica if (style != null) cell.setCellStyle(style); } //------------/** * Crea una hoja Excel con el contenido especificado. * @param v Vector con los datos a escribir en la hoja. * @param namesheet nombre de la hoja. * @param filename path del fichero donde se escribe. */ public static void crearExcel(Vector v, String namesheet, String filename) throws Exception { try { Workbook wb = new HSSFWorkbook(); // Workbook wb = new XSSFWorkbook(); CreationHelper createHelper = wb.getCreationHelper(); Sheet sheet = wb.createSheet(namesheet); int filas = v.size(); for (int i = 0; i < filas; i++) { String fila = (String) v.elementAt(i); StringTokenizer st = new StringTokenizer(fila, ","); Row row = sheet.createRow((short) i); int j = 0; while (st.hasMoreTokens()) { String token = st.nextToken(); // para la cabecera, la primera fila, aplicamos un estilo (negrita y

color de fondo azul) if (i == 0) { CellStyle style = wb.createCellStyle(); style.setFillForegroundColor(IndexedColors.BLUE_GREY.getInde x()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); Font font = wb.createFont(); // font.setFontHeightInPoints((short)10); font.setFontName("Courier New"); // font.setItalic(true); // font.setStrikeout(true); font.setBoldweight(Font.BOLDWEIGHT_BOLD); font.setColor(IndexedColors.WHITE.getIndex()); style.setFont(font); createCell(row, j, token, style); } else createCell(row, j, token, null); j = j + 1; } } // Asignar automaticamente graficos de los datos. for (int i = 0; i < filas; i++) { sheet.autoSizeColumn((short) i); } // FileOutputStream fileOut = new FileOutputStream(filename); wb.write(fileOut); fileOut.close(); } catch (Exception e) { e.printStackTrace();

} } // -----------------/** try { //Datos a escribir Vector v = new Vector(); v.addElement("IDENTIFICADOR ,ID_CODIGO ,ESTADO ,DESCRIPCION"); // Generar el fichero GenerarGraficaExcel.crearExcel(v, "Ejemplo", "/home/Escritorio/graficas.xls"); System.out.println("[ Generado fichero. ]"); } catch (Exception e) { e.printStackTrace(); } } // ---} // end PROBLEMA 2 Realice un programa en Java que permita construir los grficos de las funciones seno y coseno, para diferentes parmetros de amplitud y perodo. public class GraficoSeno extends Applet { int x0,xN,y0,yN; // Declaracin de variables double xmin,xmax,ymin,ymax; int apAncho,apAlto; public void init() { Dimension d = size(); apAncho = d.width;

apAlto = d.height; x0 = y0 = 0; xN = apAncho-1; yN = apAlto-1; xmin = -10.0; xmax = 10.0; ymin = -1.0; ymax = 1.0; } public void paint( Graphics g ) { double x1,y1,x2,y2; int j1,j2; j1 = ValorY( 0 ); for( int i=0; i < apAncho; i++ ) { j2 = ValorY( i+1 ); g.drawLine( i,j1,i+1,j2 ); j1 = j2; } } private int ValorY( int valor ) { double x,y; int retorno; x = (valor * (xmax-xmin) / (apAncho-1)) + xmin; y = Math.sin( x ); retorno = (int)( (y-ymin) * (apAlto-1) / (ymax-ymin) ); retorno = apAlto - retorno; return( retorno ); } }

CONCLUSIN Este Trabajo Colaborativo 2 ha sido elaborado con el objetivo de ampliar el conocimiento sobre algoritmos bsicos, Llenado de reas y Transformaciones. Los ejercicios realizados en el presente trabajo estn basados bsicamente en vector las frecuencias y grficos de las funciones seno y coseno. BIBLIOGRAFA Modulo Computacin Grafica 2009 http://html.rincondelvago.com/algoritmos-computacionales-basicos.html http://ccg.ciens.ucv.ve/~ernesto/nds/CotoND200302.pdf

Вам также может понравиться