Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.JFrame;
- import java.awt.Graphics;
- import javax.swing.*;
- import java.awt.Color;
- import java.awt.event.*;
- import javax.swing.*;
- public class CirculoBrsenham extends Frame {
- public static void main(String[] args) {
- new CirculoBrsenham();
- }
- CirculoBrsenham() {
- super("Algoritmo de Punto Medio");
- addWindowListener(new WindowAdapter() {
- @Override
- public void windowClosing(WindowEvent e) {
- System.exit(0);
- }
- });
- setSize(500, 500);
- JButton startButton = new JButton("Start");
- // startButton.addActionListener((this) );
- add(startButton);
- add("Center", new CvBresenham());
- setBackground(Color.WHITE);
- setVisible(true);
- }
- public void actionPerformed(ActionEvent a) {
- for(int i = 0; true; i++){
- System.out.println(i);
- }
- }
- public void paint(Graphics g)
- {
- super.paint(g);
- int ancho = 500, alto = 500;
- for(int i = 1; i <= 10; i++){
- g.drawLine(30, i * alto, getSize().width - 100, i * alto);
- g.drawLine(i * ancho, 30, i * ancho, getSize().height - 100);
- }
- }
- }
- class CvBresenham extends Canvas {
- float rWidth = 10.5F, rHeight = 10.5F, pixelSize;
- int centerX, centerY, dGrid = 15, maxX, maxY;
- void pausaplz() {
- try {
- Thread.sleep(500);
- } catch (Exception e) {
- }
- }
- void pausaplz2() {
- try {
- Thread.sleep(100000000);
- } catch (Exception e) {
- }
- }
- void putPixel(Graphics g, int x, int y) {
- int x1 = x * dGrid, y1 = y * dGrid, h = dGrid / 2;
- g.drawOval(x1 - h, y1 - h, dGrid, dGrid);
- }
- void drawCircle(Graphics g, int xC, int yC, int r) {
- int x = 0;
- int y = r;
- int u = 1;
- int v = 2 * r - 1;
- int E = 0;
- while (x < y) {
- System.out.print("x="); System.out.println(x);
- System.out.print("y="); System.out.println(y);
- System.out.print("v="); System.out.println(v);
- System.out.print("E="); System.out.println(E);
- System.out.print("u="); System.out.println(u);
- System.out.println( );
- pausaplz();
- putPixel(g, xC + x, yC + y); //Primer Octante(NNE)
- pausaplz();
- putPixel(g, xC + y, yC - x); // Segundo Octante(ESE)
- pausaplz();
- putPixel(g, xC - x, yC - y); // Tercer Octante(SSW)
- pausaplz();
- putPixel(g, xC - y, yC + x); // Cuarto Octante(WNW)
- x++;
- E += u;
- u += 2;
- if (v < 2 * E) {
- y--;
- E -= v;
- v -= 2;
- }
- if (x > y) {
- break;
- }
- pausaplz();
- putPixel(g, xC + y, yC + x); // Quinto Octante(ENE)
- pausaplz();
- putPixel(g, xC + x, yC - y); // Sexto Octante(SSE)
- pausaplz();
- putPixel(g, xC - y, yC - x); // Setimo Octante(WSW)
- pausaplz();
- putPixel(g, xC - x, yC + y); // Octavo Ocatnte(NNW)
- }
- }
- private void drawCircle2(Graphics g, final int centerX, final int centerY, final int radius) {
- int r = 1;
- int d = (5 - r * 4) / 4;
- int x = 0;
- int y = radius;
- do {
- pausaplz();
- putPixel(g, centerX + x, centerY + y);
- pausaplz();
- putPixel(g, centerX + x, centerY - y);
- pausaplz();
- putPixel(g, centerX - x, centerY + y);
- pausaplz();
- putPixel(g, centerX - x, centerY - y);
- pausaplz();
- putPixel(g, centerX + y, centerY + x);
- pausaplz();
- putPixel(g, centerX + y, centerY - x);
- pausaplz();
- putPixel(g, centerX - y, centerY + x);
- pausaplz();
- putPixel(g, centerX - y, centerY - x);
- if (d < 0) {
- d += 2 * x + 1;
- } else {
- d += 2 * (x - y) + 1;
- y--;
- }
- x++;
- } while (x <= y);
- }
- @Override
- public void paint(Graphics g) {
- drawCircle(g, 15, 10, 8);//Ubicacion de posicion de la Circunferencia
- pausaplz2();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement