Presentation is loading. Please wait.

Presentation is loading. Please wait.

Import graphics.*; public class Grafprueba { public static void main(String[] args) { Bgi g = new Bgi("Gráficas al estilo BGI"); g.setbkcolor(Bgi.BLACK);

Similar presentations


Presentation on theme: "Import graphics.*; public class Grafprueba { public static void main(String[] args) { Bgi g = new Bgi("Gráficas al estilo BGI"); g.setbkcolor(Bgi.BLACK);"— Presentation transcript:

1 import graphics.*; public class Grafprueba { public static void main(String[] args) { Bgi g = new Bgi("Gráficas al estilo BGI"); g.setbkcolor(Bgi.BLACK); // constante estática y publica g.setcolor(Bgi.LIGHTRED); g.rectangle(100, 100, 400, 400); g.setcolor(Bgi.WHITE); g.line(0, 0, g.getmaxx(), g.getmaxy()); g.getch(); g.setcolor(Bgi.RED); g.moveto(g.getmaxx(), g.getmaxy()); // coloca el punto de inicio del trazo sin graficas g.lineto(g.getmaxx(), g.getmaxy() / 2); // traza la línea a partir de un punto anterior g.lineto(g.getmaxx() / 2, g.getmaxy() / 2); g.lineto(g.getmaxx() / 2, 0); g.setcolor(Bgi.LIGHTGREEN); g.circle(g.getmaxx() / 2, g.getmaxy() / 2, g.getmaxy() / 2); g.setcolor(Bgi.YELLOW); g.outtextxy(g.getmaxx() / 2 + 50, 150, "Hola Mundo gráfico"); g.getch(); g.settextstyle(0, Bgi.HORIZ_DIR, 50); g.outtextxy(100, 80, "Hola Mundo gráfico"); g.settextstyle(0, Bgi.VERT_DIR, 10); g.outtextxy(g.getmaxx() / 2 - 50, g.getmaxy() / 2, "Hola Mundo gráfico"); g.getch(); System.exit(0); }

2 0, 0 getmaxx() getmaxy() Sistema de coordenadas físicas Los métodos getmaxx() y getmaxy() retornan la máxima abcisa y ordenada del sistema de coordenadas físicas, respectivamente. Estas coordenadas son relativas a la ventana de gráficas

3 Graficas en coordenadas lógicas (xmin l, ymin l ) (0, 0) (getmaxx(),) getmaxy() (xmax l, ymax l ) Sistema de coordenadas lógicasSistema de coordenadas físicas x l, y l x f, y f xf = (int)(- xmin l * fescx + x l * fescx) yf = (int)(g.getmaxy() + ymin l * fescy - y l * fescy) fescx = g.getmaxx() / (xmax l - xmin l ) fescy = g.getmaxy() / (ymax l - ymin l )

4 import graphics.*; class Migraf { public static void main(String s[]) { Bgi g = new Bgi(250, 250, "Oscilación amortiguada"); float xminl = 0.f; float yminl = -1.f; float xmaxl = 5.f * (float)Math.PI; float ymaxl = 1.f; float fescx = g.getmaxx()/(xmaxl - xminl); // factores de esacala float fescy = g.getmaxy()/(ymaxl - yminl); int xf = 0, yf = g.getmaxy()/2; g.moveto(xf, yf); for (float x = 0; x < 5 * Math.PI; x += 0.1f) { float y = (float) (Math.sin(x)* Math.exp(-.2*x)); System.out.println(x + ", " + y); // conversión a coordenadas físicas xf = (int)(- xminl * fescx + x * fescx); yf = (int)(g.getmaxy() + yminl * fescy - y * fescy); g.lineto(xf, yf); } g.getch(); }

5 import graphics.Bgi; public class Graficas extends Bgi // heredar todo lo no privado de la clase Bgi { private double fescx, fescy, x0, y0; //Constructores: public Graficas() { super(); // llamada al constructor de la clase Bgi, es decir la super clase } public Graficas(String Titulo) { super(Titulo); } public void escala(double xLmin, double yLmin, double xLmax, double yLmax) { fescx = getmaxx() / (xLmax - xLmin); fescy = getmaxy() / (yLmax - yLMin); x0 = -xL1 * fescx; y0 = getmaxy() + yLmin * fescy; } public void linea(double x1, double y1, double x2, double y2) { int xf1, xf2, yf1, yf2; xf1 = (int)(x0 + x1 * fescx); yf1 = (int)(y0 - y1 * fescy); xf2 = (int)(x0 + x2 * fescx); yf2 = (int)(y0 - y2 * fescy); line(xf1, yf1, xf2, yf2); } }

6 class Main { public static void main(String s[]) { Graficas g = new Graficas(); // llamada al primer constructor g.escala(0., -1., 3 * Math.PI, 1.) g.mueve_a(0., 0.); // equivalente a moveto en coordenadas logicas for (double x = 0; x < 3 * Math.PI; x += 0.1f) { double y = Math.sin(x) * Math.exp(-.2 * x); g.linea_a(x, y); // equivalente a lineto en coordenadas logicas } } }


Download ppt "Import graphics.*; public class Grafprueba { public static void main(String[] args) { Bgi g = new Bgi("Gráficas al estilo BGI"); g.setbkcolor(Bgi.BLACK);"

Similar presentations


Ads by Google