Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- public class MyDraw {
- public static final Color black = StdDraw.BLACK;
- public static final Color blue = StdDraw.BLUE;
- public static final Color darkBlue = blue.darker().darker().darker();
- public static final Color mustard = StdDraw.ORANGE.darker();
- public static final Color white = StdDraw.WHITE;
- public static Color get_col(){
- int r = (int) (Math.random() * 256.0);
- int g = (int) (Math.random() * 256.0);
- int b = (int) (Math.random() * 256.0);
- return new Color(r,g,b);
- }
- private static Color parseColor(String c){
- if (c.equals("black")) return black;
- else if (c.equals("blue")) return blue;
- else if (c.equals("darkBlue")) return darkBlue;
- else if (c.equals("mustard")) return mustard;
- else if (c.equals("white")) return white;
- return StdDraw.GRAY;
- }
- private static double Random(double r){
- return Math.round(Math.random()*r*1000.0)/1000.0;
- }
- private static double rotateX (double x, double r, double theta){
- return x + r * Math.cos(Math.toRadians(theta));
- }
- private static double rotateY (double y, double r, double theta){
- return y + r * Math.sin(Math.toRadians(theta));
- }
- public static void Kaleidoscope(int scale){
- StdDraw.setXscale(0 , 100); //sets X scale 0 - 100
- StdDraw.setYscale(0 , 100); //sets Y scale 0 - 100
- StdDraw.clear(StdDraw.WHITE); //sets background color white
- double radius = scale / 100.0;
- StdDraw.setPenRadius(radius); //sets pen radius in orded for canvas to fit the desired number of points
- StdDraw.setXscale(0 , 100); //sets X scale 0 - 100
- StdDraw.setYscale(0 , 100); //sets Y scale 0 - 100
- StdDraw.clear(StdDraw.WHITE); //sets background color white
- for(double i=50*radius; i<100; i+=radius*100)
- for(double j=50*radius; j<100; j+=radius*100) {
- 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
- StdDraw.setPenColor(c); //sets pen color to random color generated above
- StdDraw.point(i, j); //draws the point
- }
- }
- public static void Kaleidoscope(int diameter, String s){
- //
- }
- public static void hexagon (double r, double x, double y, Color c){
- // .......
- }
- public static void hexagon (double r, double x, double y, Color c1, Color c2){
- // .......
- }
- public static void hexagon (double r, double x, double y, Color c1, Color c2, Color c3){
- // ........
- }
- public static void hGrid(double r){
- // ..........
- }
- public static void hive (double r, double x, double y){
- // .......
- }
- public static void hive (double r){
- // ......
- }
- public static void filledCircle(double x, double y, double r, Color c, char type){
- StdDraw.setPenColor(c);
- switch(type){
- case 'P':
- for (int i = 1; i <= (int)(20000 * r); i++){
- double theta = Random(360.0);
- double rs = Random(r);
- double xs = rotateX(x,rs,theta);
- double ys = rotateY(y,rs,theta);
- StdDraw.point(xs,ys);
- }
- break;
- case 'A':
- double theta = 0.0;
- while (theta <= 360.0){
- double xs = rotateX(x,r,theta);
- double ys = rotateY(y,r,theta);
- StdDraw.line(x,y,xs,ys);
- theta += 0.01;
- }
- break;
- case 'C':
- double rs = 0.0;
- while (rs <= r){
- theta = 0.0;
- while (theta <= 360.0){
- double xs = rotateX(x,rs,theta);
- double ys = rotateY(y,rs,theta);
- StdDraw.point(xs,ys);
- theta += 0.1;
- }
- rs += 0.25;
- }
- break;
- case 'S':
- double xs = -r;
- while (xs <= r){
- double ys = -r;
- while (ys <= r){
- if (xs * xs + ys * ys <= r * r) StdDraw.point(xs+x,ys+y);
- ys = ys + 0.1;
- }
- xs = xs + 0.1;
- }
- }
- }
- public static void star (double x, double y, double r, int sides){
- // ........
- }
- public static void sun (double x, double y, double r, int sides){
- // For a 10 mark bonus!!!
- }
- public static void main(String[] args){
- StdDraw.setXscale(0.0,100.0);
- StdDraw.setYscale(0.0,100.0);
- StdDraw.clear(StdDraw.GRAY);
- if (args[0].equals("-k")){
- if (args.length == 2) Kaleidoscope(Integer.parseInt(args[1]));
- else Kaleidoscope(Integer.parseInt(args[1]), args[2]);
- }
- else if (args[0].equals("-h")){
- double r = Double.parseDouble(args[1]);
- double x = Double.parseDouble(args[2]);
- double y = Double.parseDouble(args[3]);
- Color c1 = parseColor(args[4]);
- if (args.length == 5) hexagon(r,x,y,c1);
- else if (args.length == 6){
- Color c2 = parseColor(args[5]);
- hexagon(r,x,y,c1,c2);}
- else if (args.length == 7){
- Color c2 = parseColor(args[5]);
- Color c3 = parseColor(args[6]);
- hexagon(r,x,y,c1,c2,c3); }
- }
- else if (args[0].equals("-c")){
- double x = Double.parseDouble(args[1]);
- double y = Double.parseDouble(args[2]);
- double r = Double.parseDouble(args[3]);
- Color c = parseColor(args[4]);
- long start = System.nanoTime();
- filledCircle(x,y,r,c,args[5].charAt(0));
- System.out.println("computation time: " + (double)(System.nanoTime()-start)/10E9 + " seconds");
- }
- else if (args[0].equals("-g")){
- double r = Double.parseDouble(args[1]);
- hGrid(r);
- }
- else if (args[0].equals("-H")){
- double r = Double.parseDouble(args[1]);
- if (args.length == 2) hive(r);
- else {
- double x = Double.parseDouble(args[2]);
- double y = Double.parseDouble(args[3]);
- hive(r,x,y);}
- }
- else if (args[0].equals("-s")){
- double x = Double.parseDouble(args[1]);
- double y = Double.parseDouble(args[2]);
- double r = Double.parseDouble(args[3]);
- int s = Integer.parseInt(args[4]);
- star(x,y,r,s);
- }
- else System.out.println("Wrong command arguments");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement