Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Point;
- import gpdraw.DrawingTool;
- import gpdraw.SketchPad;
- public class Abstract2 {
- public static void main(String[] args) throws InterruptedException{
- SketchPad pad = new SketchPad(500, 500,0);
- DrawingTool pen = new DrawingTool(pad);
- DrawingTool fill = new DrawingTool(pad);
- int rows = 10;
- int columns = 10;
- int xVal = 50;
- int yVal = 50;
- Point[] verticies = new Point[rows*columns];
- verticies = createVerticies(rows,columns,xVal,yVal,verticies);
- pen.setWidth(2);
- //for(int i = 0; i<500;i++){
- drawBackground(pad,rows,columns,xVal,yVal,verticies,pen,fill);
- verticies = drawLines(rows, columns, xVal, yVal, verticies, pen,fill);
- //Thread.sleep(250);
- //pen.setColor(Color.red);
- //pen.fillCircle(2000);
- //pen.setColor(Color.black);
- //}
- }
- private static void drawBackground(SketchPad pad, int rows, int columns, int xVal, int yVal, Point[] verticies, DrawingTool pen, DrawingTool fill) {
- Color color1 = new Color(127,108,226);
- Color color2 = new Color(193,100,2);
- Color color3 = new Color(0,92,72);
- Color color4 = new Color(179,194,149);
- DrawingTool bg = new DrawingTool(pad);
- int startX = -250;
- int startY = 250;
- int x = startX;
- int y = startY;
- int color = 1;
- for(int r = 0; r<rows;r++){
- for(int c = 0;c<columns;c++){
- Point vert = new Point(x,y);
- //Point vert = new Point((int)(x+Math.random()*50),(int)(y+Math.random()*50));
- if(color==1){
- bg.setColor(color1);
- }
- else if(color==2){
- bg.setColor(color2);
- }
- else if(color==3){
- bg.setColor(color3);
- }
- else if(color==4){
- bg.setColor(color4);
- }
- bg.up();
- bg.move(vert.x,vert.y);
- bg.down();
- bg.fillCircle(40);
- //bg.fillCircle(Math.random()*70);
- if(color==4){
- color=1;
- }
- else{
- color++;
- }
- x+=xVal;
- }
- y-=yVal;
- x=startX;
- }
- }
- private static Point[] drawLines(int rows, int columns, int xVal, int yVal, Point[] verticies, DrawingTool pen, DrawingTool fill){
- pen.setColor(Color.black);
- for(int i = 0;i<verticies.length;i++){
- boolean lastRow = (i/columns+1)==rows;
- boolean lastCol = (i+1)%columns==0;
- int randX = (int) (Math.random()*3);
- int randY = (int) (Math.random()*3);
- int addX = 0;
- int addY = 0;
- Color color1 = new Color(20,100,200);
- Color color2 = new Color(200,20,100);
- Color color3 = new Color(100,200,20);
- int color = 1;
- /*
- if(randX==0){
- addX = 0;
- }
- else if(randX==1){
- addX = 0;
- }
- else if(randX==2){
- addX=-0;
- }
- if(randY==0){
- addY = 0;
- }
- else if(randY==1){
- addY = 0;
- }
- else if(randY==2){
- addY=-0;
- }
- verticies[i].x=verticies[i].x+addX;
- verticies[i].y=verticies[i].y+addY;
- */
- if(!lastCol){
- pen.up();
- pen.move(verticies[i].x,verticies[i].y);
- pen.down();
- pen.move(verticies[i+1].x,verticies[i+1].y);//horizontal
- }
- if(!lastCol && !lastRow){
- pen.up();
- pen.move(verticies[i].x,verticies[i].y);
- pen.down();
- pen.move(verticies[i+columns+1].x,verticies[i+columns+1].y);//angled
- }
- if(!lastRow){
- pen.up();
- pen.move(verticies[i].x,verticies[i].y);
- pen.down();
- pen.move(verticies[i+columns].x,verticies[i+columns].y);//vertical
- }
- }
- return verticies;
- }
- private static Point[] createVerticies(int rows, int columns, int xVal, int yVal, Point[] verticies) {
- int startX = -250;
- int startY = 250;
- int x = startX;
- int y = startY;
- for(int r = 0; r<rows;r++){
- for(int c = 0;c<columns;c++){
- Point vert = new Point((int)(x+Math.random()*50),(int)(y+Math.random()*50));
- verticies[c+(r*columns)]=vert;
- x+=xVal;
- }
- y-=yVal;
- x=startX;
- }
- return verticies;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement