Advertisement
Guest User

abstract3

a guest
Oct 22nd, 2014
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Point;
  3.  
  4. import gpdraw.DrawingTool;
  5. import gpdraw.SketchPad;
  6.  
  7.  
  8. public class Abstract2 {
  9. public static void main(String[] args) throws InterruptedException{
  10. SketchPad pad = new SketchPad(500, 500,0);
  11. DrawingTool pen = new DrawingTool(pad);
  12. DrawingTool fill = new DrawingTool(pad);
  13. int rows = 10;
  14. int columns = 10;
  15. int xVal = 50;
  16. int yVal = 50;
  17. Point[] verticies = new Point[rows*columns];
  18. verticies = createVerticies(rows,columns,xVal,yVal,verticies);
  19. pen.setWidth(2);
  20.  
  21. //for(int i = 0; i<500;i++){
  22. drawBackground(pad,rows,columns,xVal,yVal,verticies,pen,fill);
  23. verticies = drawLines(rows, columns, xVal, yVal, verticies, pen,fill);
  24. //Thread.sleep(250);
  25. //pen.setColor(Color.red);
  26. //pen.fillCircle(2000);
  27. //pen.setColor(Color.black);
  28.  
  29. //}
  30.  
  31.  
  32.  
  33.  
  34. }
  35. private static void drawBackground(SketchPad pad, int rows, int columns, int xVal, int yVal, Point[] verticies, DrawingTool pen, DrawingTool fill) {
  36. Color color1 = new Color(127,108,226);
  37. Color color2 = new Color(193,100,2);
  38. Color color3 = new Color(0,92,72);
  39. Color color4 = new Color(179,194,149);
  40. DrawingTool bg = new DrawingTool(pad);
  41. int startX = -250;
  42. int startY = 250;
  43. int x = startX;
  44. int y = startY;
  45. int color = 1;
  46. for(int r = 0; r<rows;r++){
  47. for(int c = 0;c<columns;c++){
  48. Point vert = new Point(x,y);
  49. //Point vert = new Point((int)(x+Math.random()*50),(int)(y+Math.random()*50));
  50. if(color==1){
  51. bg.setColor(color1);
  52. }
  53. else if(color==2){
  54. bg.setColor(color2);
  55. }
  56. else if(color==3){
  57. bg.setColor(color3);
  58. }
  59. else if(color==4){
  60. bg.setColor(color4);
  61. }
  62. bg.up();
  63. bg.move(vert.x,vert.y);
  64. bg.down();
  65. bg.fillCircle(40);
  66. //bg.fillCircle(Math.random()*70);
  67. if(color==4){
  68. color=1;
  69. }
  70. else{
  71. color++;
  72. }
  73.  
  74. x+=xVal;
  75. }
  76. y-=yVal;
  77. x=startX;
  78. }
  79.  
  80. }
  81. private static Point[] drawLines(int rows, int columns, int xVal, int yVal, Point[] verticies, DrawingTool pen, DrawingTool fill){
  82. pen.setColor(Color.black);
  83. for(int i = 0;i<verticies.length;i++){
  84. boolean lastRow = (i/columns+1)==rows;
  85. boolean lastCol = (i+1)%columns==0;
  86. int randX = (int) (Math.random()*3);
  87. int randY = (int) (Math.random()*3);
  88. int addX = 0;
  89. int addY = 0;
  90. Color color1 = new Color(20,100,200);
  91. Color color2 = new Color(200,20,100);
  92. Color color3 = new Color(100,200,20);
  93. int color = 1;
  94. /*
  95. if(randX==0){
  96. addX = 0;
  97. }
  98. else if(randX==1){
  99. addX = 0;
  100. }
  101. else if(randX==2){
  102. addX=-0;
  103. }
  104. if(randY==0){
  105. addY = 0;
  106. }
  107. else if(randY==1){
  108. addY = 0;
  109. }
  110. else if(randY==2){
  111. addY=-0;
  112. }
  113. verticies[i].x=verticies[i].x+addX;
  114. verticies[i].y=verticies[i].y+addY;
  115. */
  116. if(!lastCol){
  117.  
  118. pen.up();
  119. pen.move(verticies[i].x,verticies[i].y);
  120. pen.down();
  121.  
  122.  
  123. pen.move(verticies[i+1].x,verticies[i+1].y);//horizontal
  124.  
  125. }
  126. if(!lastCol && !lastRow){
  127. pen.up();
  128. pen.move(verticies[i].x,verticies[i].y);
  129. pen.down();
  130.  
  131. pen.move(verticies[i+columns+1].x,verticies[i+columns+1].y);//angled
  132.  
  133.  
  134. }
  135.  
  136. if(!lastRow){
  137. pen.up();
  138. pen.move(verticies[i].x,verticies[i].y);
  139. pen.down();
  140.  
  141. pen.move(verticies[i+columns].x,verticies[i+columns].y);//vertical
  142.  
  143.  
  144.  
  145. }
  146.  
  147.  
  148.  
  149. }
  150. return verticies;
  151. }
  152.  
  153.  
  154.  
  155. private static Point[] createVerticies(int rows, int columns, int xVal, int yVal, Point[] verticies) {
  156. int startX = -250;
  157. int startY = 250;
  158. int x = startX;
  159. int y = startY;
  160. for(int r = 0; r<rows;r++){
  161. for(int c = 0;c<columns;c++){
  162. Point vert = new Point((int)(x+Math.random()*50),(int)(y+Math.random()*50));
  163. verticies[c+(r*columns)]=vert;
  164. x+=xVal;
  165. }
  166. y-=yVal;
  167. x=startX;
  168. }
  169.  
  170.  
  171. return verticies;
  172.  
  173.  
  174. }
  175. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement