Advertisement
Guest User

Untitled

a guest
Oct 1st, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.JFrame;
  4. import java.awt.Graphics;
  5. import javax.swing.*;
  6. import java.awt.Color;
  7.  
  8. import java.awt.event.*;
  9. import javax.swing.*;
  10.  
  11.  
  12.  
  13. public class CirculoBrsenham extends Frame {
  14.  
  15. public static void main(String[] args) {
  16. new CirculoBrsenham();
  17. }
  18.  
  19. CirculoBrsenham() {
  20. super("Algoritmo de Punto Medio");
  21. addWindowListener(new WindowAdapter() {
  22. @Override
  23. public void windowClosing(WindowEvent e) {
  24. System.exit(0);
  25. }
  26. });
  27. setSize(500, 500);
  28. JButton startButton = new JButton("Start");
  29. // startButton.addActionListener((this) );
  30. add(startButton);
  31.  
  32. add("Center", new CvBresenham());
  33. setBackground(Color.WHITE);
  34. setVisible(true);
  35.  
  36.  
  37. }
  38.  
  39. public void actionPerformed(ActionEvent a) {
  40. for(int i = 0; true; i++){
  41. System.out.println(i);
  42. }
  43. }
  44.  
  45. public void paint(Graphics g)
  46. {
  47. super.paint(g);
  48. int ancho = 500, alto = 500;
  49. for(int i = 1; i <= 10; i++){
  50. g.drawLine(30, i * alto, getSize().width - 100, i * alto);
  51. g.drawLine(i * ancho, 30, i * ancho, getSize().height - 100);
  52. }
  53. }
  54. }
  55.  
  56. class CvBresenham extends Canvas {
  57.  
  58. float rWidth = 10.5F, rHeight = 10.5F, pixelSize;
  59. int centerX, centerY, dGrid = 15, maxX, maxY;
  60.  
  61. void pausaplz() {
  62. try {
  63. Thread.sleep(500);
  64. } catch (Exception e) {
  65. }
  66. }
  67. void pausaplz2() {
  68. try {
  69. Thread.sleep(100000000);
  70. } catch (Exception e) {
  71. }
  72. }
  73.  
  74. void putPixel(Graphics g, int x, int y) {
  75. int x1 = x * dGrid, y1 = y * dGrid, h = dGrid / 2;
  76. g.drawOval(x1 - h, y1 - h, dGrid, dGrid);
  77. }
  78.  
  79. void drawCircle(Graphics g, int xC, int yC, int r) {
  80. int x = 0;
  81. int y = r;
  82. int u = 1;
  83. int v = 2 * r - 1;
  84. int E = 0;
  85. while (x < y) {
  86. System.out.print("x="); System.out.println(x);
  87. System.out.print("y="); System.out.println(y);
  88. System.out.print("v="); System.out.println(v);
  89. System.out.print("E="); System.out.println(E);
  90. System.out.print("u="); System.out.println(u);
  91. System.out.println( );
  92. pausaplz();
  93. putPixel(g, xC + x, yC + y); //Primer Octante(NNE)
  94. pausaplz();
  95. putPixel(g, xC + y, yC - x); // Segundo Octante(ESE)
  96. pausaplz();
  97. putPixel(g, xC - x, yC - y); // Tercer Octante(SSW)
  98. pausaplz();
  99. putPixel(g, xC - y, yC + x); // Cuarto Octante(WNW)
  100. x++;
  101. E += u;
  102. u += 2;
  103. if (v < 2 * E) {
  104. y--;
  105. E -= v;
  106. v -= 2;
  107. }
  108. if (x > y) {
  109. break;
  110. }
  111. pausaplz();
  112. putPixel(g, xC + y, yC + x); // Quinto Octante(ENE)
  113. pausaplz();
  114. putPixel(g, xC + x, yC - y); // Sexto Octante(SSE)
  115. pausaplz();
  116. putPixel(g, xC - y, yC - x); // Setimo Octante(WSW)
  117. pausaplz();
  118. putPixel(g, xC - x, yC + y); // Octavo Ocatnte(NNW)
  119. }
  120.  
  121.  
  122. }
  123.  
  124. private void drawCircle2(Graphics g, final int centerX, final int centerY, final int radius) {
  125. int r = 1;
  126. int d = (5 - r * 4) / 4;
  127. int x = 0;
  128. int y = radius;
  129.  
  130. do {
  131. pausaplz();
  132. putPixel(g, centerX + x, centerY + y);
  133. pausaplz();
  134. putPixel(g, centerX + x, centerY - y);
  135. pausaplz();
  136. putPixel(g, centerX - x, centerY + y);
  137. pausaplz();
  138. putPixel(g, centerX - x, centerY - y);
  139. pausaplz();
  140. putPixel(g, centerX + y, centerY + x);
  141. pausaplz();
  142. putPixel(g, centerX + y, centerY - x);
  143. pausaplz();
  144. putPixel(g, centerX - y, centerY + x);
  145. pausaplz();
  146. putPixel(g, centerX - y, centerY - x);
  147. if (d < 0) {
  148. d += 2 * x + 1;
  149. } else {
  150. d += 2 * (x - y) + 1;
  151. y--;
  152. }
  153. x++;
  154. } while (x <= y);
  155.  
  156. }
  157.  
  158.  
  159.  
  160. @Override
  161. public void paint(Graphics g) {
  162.  
  163.  
  164. drawCircle(g, 15, 10, 8);//Ubicacion de posicion de la Circunferencia
  165. pausaplz2();
  166.  
  167.  
  168.  
  169. }
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement