Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.70 KB | None | 0 0
  1. import java.awt.Color;
  2.  
  3. public class MyDraw {
  4.  
  5. public static final Color black = StdDraw.BLACK;
  6. public static final Color blue = StdDraw.BLUE;
  7. public static final Color darkBlue = blue.darker().darker().darker();
  8. public static final Color mustard = StdDraw.ORANGE.darker();
  9. public static final Color white = StdDraw.WHITE;
  10.  
  11. public static Color get_col(){
  12. int r = (int) (Math.random() * 256.0);
  13. int g = (int) (Math.random() * 256.0);
  14. int b = (int) (Math.random() * 256.0);
  15. return new Color(r,g,b);
  16.  
  17. }
  18.  
  19. private static Color parseColor(String c){
  20. if (c.equals("black")) return black;
  21. else if (c.equals("blue")) return blue;
  22. else if (c.equals("darkBlue")) return darkBlue;
  23. else if (c.equals("mustard")) return mustard;
  24. else if (c.equals("white")) return white;
  25. return StdDraw.GRAY;
  26. }
  27.  
  28. private static double Random(double r){
  29. return Math.round(Math.random()*r*1000.0)/1000.0;
  30. }
  31.  
  32. private static double rotateX (double x, double r, double theta){
  33. return x + r * Math.cos(Math.toRadians(theta));
  34. }
  35.  
  36. private static double rotateY (double y, double r, double theta){
  37. return y + r * Math.sin(Math.toRadians(theta));
  38. }
  39.  
  40. public static void Kaleidoscope(int scale){
  41. StdDraw.setXscale(0 , 100); //sets X scale 0 - 100
  42. StdDraw.setYscale(0 , 100); //sets Y scale 0 - 100
  43. StdDraw.clear(StdDraw.WHITE); //sets background color white
  44. double radius = scale / 100.0;
  45. StdDraw.setPenRadius(radius); //sets pen radius in orded for canvas to fit the desired number of points
  46. StdDraw.setXscale(0 , 100); //sets X scale 0 - 100
  47. StdDraw.setYscale(0 , 100); //sets Y scale 0 - 100
  48. StdDraw.clear(StdDraw.WHITE); //sets background color white
  49. for(double i=50*radius; i<100; i+=radius*100)
  50. for(double j=50*radius; j<100; j+=radius*100) {
  51. Color c = new Color ( (int)(Math.random()*256) , (int)(Math.random()*256) , (int)(Math.random()*256) ); // gives a random RGB value [0-255] to variable c
  52. StdDraw.setPenColor(c); //sets pen color to random color generated above
  53. StdDraw.point(i, j); //draws the point
  54. }
  55.  
  56.  
  57.  
  58. }
  59.  
  60. public static void Kaleidoscope(int diameter, String s){
  61. //
  62. }
  63.  
  64. public static void hexagon (double r, double x, double y, Color c){
  65.  
  66. // .......
  67. }
  68.  
  69. public static void hexagon (double r, double x, double y, Color c1, Color c2){
  70.  
  71. // .......
  72.  
  73. }
  74.  
  75. public static void hexagon (double r, double x, double y, Color c1, Color c2, Color c3){
  76.  
  77. // ........
  78. }
  79.  
  80. public static void hGrid(double r){
  81.  
  82. // ..........
  83.  
  84. }
  85.  
  86.  
  87. public static void hive (double r, double x, double y){
  88.  
  89. // .......
  90.  
  91. }
  92.  
  93. public static void hive (double r){
  94.  
  95. // ......
  96.  
  97. }
  98.  
  99. public static void filledCircle(double x, double y, double r, Color c, char type){
  100. StdDraw.setPenColor(c);
  101. switch(type){
  102. case 'P':
  103. for (int i = 1; i <= (int)(20000 * r); i++){
  104. double theta = Random(360.0);
  105. double rs = Random(r);
  106. double xs = rotateX(x,rs,theta);
  107. double ys = rotateY(y,rs,theta);
  108. StdDraw.point(xs,ys);
  109. }
  110. break;
  111. case 'A':
  112. double theta = 0.0;
  113. while (theta <= 360.0){
  114. double xs = rotateX(x,r,theta);
  115. double ys = rotateY(y,r,theta);
  116. StdDraw.line(x,y,xs,ys);
  117. theta += 0.01;
  118. }
  119. break;
  120. case 'C':
  121. double rs = 0.0;
  122. while (rs <= r){
  123. theta = 0.0;
  124. while (theta <= 360.0){
  125. double xs = rotateX(x,rs,theta);
  126. double ys = rotateY(y,rs,theta);
  127. StdDraw.point(xs,ys);
  128. theta += 0.1;
  129. }
  130. rs += 0.25;
  131. }
  132. break;
  133. case 'S':
  134. double xs = -r;
  135. while (xs <= r){
  136. double ys = -r;
  137. while (ys <= r){
  138. if (xs * xs + ys * ys <= r * r) StdDraw.point(xs+x,ys+y);
  139. ys = ys + 0.1;
  140. }
  141. xs = xs + 0.1;
  142. }
  143. }
  144. }
  145.  
  146.  
  147.  
  148. public static void star (double x, double y, double r, int sides){
  149.  
  150. // ........
  151. }
  152.  
  153.  
  154. public static void sun (double x, double y, double r, int sides){
  155.  
  156.  
  157. // For a 10 mark bonus!!!
  158.  
  159. }
  160.  
  161.  
  162. public static void main(String[] args){
  163. StdDraw.setXscale(0.0,100.0);
  164. StdDraw.setYscale(0.0,100.0);
  165. StdDraw.clear(StdDraw.GRAY);
  166.  
  167. if (args[0].equals("-k")){
  168. if (args.length == 2) Kaleidoscope(Integer.parseInt(args[1]));
  169. else Kaleidoscope(Integer.parseInt(args[1]), args[2]);
  170. }
  171. else if (args[0].equals("-h")){
  172. double r = Double.parseDouble(args[1]);
  173. double x = Double.parseDouble(args[2]);
  174. double y = Double.parseDouble(args[3]);
  175. Color c1 = parseColor(args[4]);
  176. if (args.length == 5) hexagon(r,x,y,c1);
  177. else if (args.length == 6){
  178. Color c2 = parseColor(args[5]);
  179. hexagon(r,x,y,c1,c2);}
  180. else if (args.length == 7){
  181. Color c2 = parseColor(args[5]);
  182. Color c3 = parseColor(args[6]);
  183. hexagon(r,x,y,c1,c2,c3); }
  184. }
  185. else if (args[0].equals("-c")){
  186. double x = Double.parseDouble(args[1]);
  187. double y = Double.parseDouble(args[2]);
  188. double r = Double.parseDouble(args[3]);
  189. Color c = parseColor(args[4]);
  190. long start = System.nanoTime();
  191. filledCircle(x,y,r,c,args[5].charAt(0));
  192. System.out.println("computation time: " + (double)(System.nanoTime()-start)/10E9 + " seconds");
  193. }
  194. else if (args[0].equals("-g")){
  195. double r = Double.parseDouble(args[1]);
  196. hGrid(r);
  197. }
  198. else if (args[0].equals("-H")){
  199. double r = Double.parseDouble(args[1]);
  200. if (args.length == 2) hive(r);
  201. else {
  202. double x = Double.parseDouble(args[2]);
  203. double y = Double.parseDouble(args[3]);
  204. hive(r,x,y);}
  205. }
  206. else if (args[0].equals("-s")){
  207. double x = Double.parseDouble(args[1]);
  208. double y = Double.parseDouble(args[2]);
  209. double r = Double.parseDouble(args[3]);
  210. int s = Integer.parseInt(args[4]);
  211. star(x,y,r,s);
  212. }
  213. else System.out.println("Wrong command arguments");
  214. }
  215.  
  216. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement