1- import java .awt .*;
2- import java .awt .event .*;
3- import java .awt .Color ;
4- import java .io .*;
51import java .util .ArrayList ;
6- import javax . swing .* ;
2+ import java . io . File ;
73
84
95/*
@@ -33,40 +29,27 @@ are slightly mutated versions of themselves(colorwise). This process goes on
3329The main class to setup java GUI
3430*/
3531public class LowPoly {
36- JFrame frame ;
37- AiProgram canvas ;
3832 public static void main (String [] args ) {
3933 String folderName = "Lofi" ;
4034 if (args .length > 0 )
4135 folderName = args [0 ];
42- LowPoly kt = new LowPoly ();
43- kt .Run (folderName );
44- }
45-
46- public void Run (String name ) {
47- frame = new JFrame ("LowPoly" );
48- frame .setSize (1050 , 1050 );
49- frame .setDefaultCloseOperation (JFrame .EXIT_ON_CLOSE );
50- frame .setResizable (true );
51- canvas = new AiProgram (name );
52- frame .getContentPane ().add (canvas );
53-
54- frame .setVisible (true );
36+ new AiProgram (folderName );
5537 }
5638}
5739
5840/*
5941The the class the runs the program
6042*/
61- class AiProgram extends JPanel {
43+ class AiProgram {
6244
6345 Pixel [][] currentImage ;
6446 Pixel [][] wallLines ;
6547 Pixel [][] colorImage ;
6648 boolean [][] doneOnes ;
6749
50+ boolean doneP1 ;
51+
6852 ArrayList < Line > lines ;
69- private Timer balltimer ;
7053
7154 private int counter ;
7255
@@ -99,11 +82,59 @@ public AiProgram(String folderName) {
9982 wallLines = new Pixel [colorImage .length ][colorImage [0 ].length ];
10083 doneOnes = new boolean [colorImage .length ][colorImage [0 ].length ];
10184 testAmt = 30 ;
102- lines = new ArrayList < Line > ();
85+ lines = new ArrayList <Line > ();
10386 edgeDetection ();
104- BallMover ballmover = new BallMover ();
105- balltimer = new Timer (3000 , ballmover ); //
106- balltimer .start ();
87+ wallLines = cloneArray (currentImage );
88+ currentImage = new Pixel [colorImage .length ][colorImage [0 ].length ];
89+ for (int row = 0 ; row < currentImage .length ; row ++)
90+ {
91+ for (int col = 0 ; col < currentImage [0 ].length ; col ++)
92+ {
93+ if (currentImage [row ][col ] == null && wallLines [row ][col ] == null )
94+ {
95+ currentImage [row ][col ] = colorImage [row ][col ];
96+ boolean changed = true ;
97+ //int coiunter = 0;
98+ while (changed )
99+ {
100+ //System.out.println("Count " + coiunter);
101+ //coiunter++;
102+ changed = false ;
103+ for (int rowS = row ; rowS < currentImage .length ; rowS ++)
104+ for (int colS = 0 ; colS < currentImage [0 ].length ; colS ++)
105+ {
106+ if (currentImage [rowS ][colS ] != null && !doneOnes [rowS ][colS ] && wallLines [rowS ][colS ] == null )
107+ {
108+ if (canFillPixl (rowS -1 , colS ))
109+ currentImage [rowS -1 ][colS ] = currentImage [row ][col ];
110+ if (canFillPixl (rowS +1 , colS ))
111+ currentImage [rowS +1 ][colS ] = currentImage [row ][col ];
112+ if (canFillPixl (rowS , colS -1 ))
113+ currentImage [rowS ][colS -1 ] = currentImage [row ][col ];
114+ if (canFillPixl (rowS , colS +1 ))
115+ currentImage [rowS ][colS +1 ] = currentImage [row ][col ];
116+ doneOnes [rowS ][colS ] = true ;
117+ changed = true ;
118+ }
119+ }
120+ //System.out.println(count() + "ZCX");
121+
122+ }
123+ //System.out.println("tested");
124+ System .out .println (("Number Of Empty Pixels " +(int )(100 *(1.0 -((count ())/((double )((currentImage .length * currentImage [0 ].length )))))) + "%\t \t " + counter + "\t \t " + count ()));
125+ }
126+ }
127+ //System.out.println("New Row");
128+ //System.out.println("Number Of Empty PixelsASDASDASD "+(int)(100*(1.0-((count())/((double)((currentImage.length * currentImage[0].length)))))) + "%\t\t" + counter + "\t\t" + count());
129+ //if(row % 1000 == 0)
130+ }
131+ for (int row = 0 ; row < currentImage .length ; row ++)
132+ for (int col = 0 ; col < currentImage [0 ].length ; col ++)
133+ if (currentImage [row ][col ] == null )
134+ currentImage [row ][col ] = colorImage [row ][col ];
135+ Image newPicture = new Image (currentImage );
136+ newPicture .exportImage (exportPath +"OutputImg" );
137+ System .exit (0 );
107138 }
108139 public void edgeDetection () {
109140 System .out .println ("TEST: " + currentImage .length + ", " + currentImage [0 ].length );
@@ -449,15 +480,14 @@ public void edgeDetection() {
449480 while (x2 < lines .get (i ).x1 ) {
450481 //System.out.println((int)x2 + ", " + (int)y2);
451482 if (inBounds (currentImage .length - (int ) y2 , (int ) x2 ))
452- currentImage [currentImage .length - (int ) y2 ][(int ) x2 ] = new Pixel (0 , 0 , 0 ); //currentImage.length-
483+ currentImage [currentImage .length - (int ) y2 ][(int ) x2 ] = colorImage [ currentImage . length - ( int ) lines . get ( i ). centerY ][( int ) lines . get ( i ). centerX ]; // new Pixel(0, 0, 0); //currentImage.length-
453484 x2 += 0.0003 ;
454485 y2 += 0.0003 * lines .get (i ).slope ;
455486 }
456487 }
457488 }
489+
458490 private boolean allDone () {
459- //for(int i = 0; i < lines.size(); i++)
460- //System.out.println(lines.get(i).finished1 + ", " + lines.get(i).finished2);
461491 for (int i = 0 ; i < lines .size (); i ++)
462492 if (!lines .get (i ).finished1 || !lines .get (i ).finished2 )
463493 return false ;
@@ -474,92 +504,15 @@ public int randomWithRange(int min, int max) {
474504 /*
475505 The "update function"
476506 */
477- class BallMover implements ActionListener {
478- public void actionPerformed (ActionEvent e ) {
479- if (count () <= 300 )
480- {
481- for (int row = 0 ; row < currentImage .length ; row ++)
482- for (int col = 0 ; col < currentImage [0 ].length ; col ++)
483- if (currentImage [row ][col ] == null )
484- currentImage [row ][col ] = new Pixel ();
485- Image newPicture = new Image (currentImage );
486- newPicture .exportImage (exportPath +"OutputImg" );
487- System .exit (0 );
488- }
489- for (int repeat = 0 ; repeat < 100 ; repeat ++)
490- {
491- counter ++;
492- for (int randTest = 0 ; randTest < (currentImage .length * currentImage [0 ].length ) / 1.5 ; randTest ++) {
493- int row = randomWithRange (0 , currentImage .length - 1 );
494- int col = randomWithRange (0 , currentImage [0 ].length - 1 );
495- //System.out.println(doneOnes[row][col]);
496- if (currentImage [row ][col ] != null ) {
497- int numBabies = ((80 - currentImage [row ][col ].comparePixel (colorImage [row ][col ])) / 10 ) + (counter / 100 );
498- if (numBabies < 0 )
499- numBabies = 0 ;
500- int babyCounter = 0 ;
501- for (int i = 1 ; i <= numBabies ; i ++) {
502- int babyRange = 1 ;
503- int checkCol = randomWithRange (-1 * babyRange + col , babyRange + col );//currentAlive[checkRow][checkCol] == null
504- int checkRow = randomWithRange (-1 * babyRange + row , babyRange + row );//&& checkCol != col && checkRow != row &&
505- if (inBounds (checkRow , checkCol ) && currentImage [checkRow ][checkCol ] == null ) {
506- babyCounter ++;
507- currentImage [checkRow ][checkCol ] = geiWoBaby (currentImage [row ][col ], babyCounter );
508- }
509- }
510- }
511- }
512- //wallLines
513- //System.out.println(counter);
514- System .out .println ("Number Of Empty Pixels " +(int )(100 *(1.0 -((count ())/((double )((currentImage .length * currentImage [0 ].length )))))) + "%" );
515- //repaint();
516- }
517- /*
518- for (int row = 0; row < doneOnes.length; row++) {
519- for (int col = 0; col < doneOnes[0].length; col++) {
520- if(!doneOnes[row][col] && currentImage[row][col] != null)
521- {
522- boolean temp = false;
523- for(int rowT = row - 1; rowT <= row + 1 && !temp; rowT++)
524- {
525- for(int colT = col - 1; colT <= col + 1 && !temp; colT++)
526- {
527- if(inBounds(rowT, colT) && currentImage[rowT][colT] == null)
528- {
529- temp = true;
530- }
531- }
532- }
533- if(temp)
534- {
535- doneOnes[row][col] = true;
536- }
537- }
538- }
539- }*/
540- repaint ();
541- }
507+ public boolean canFillPixl (int row , int col )
508+ {
509+ return (inBounds (row , col ) && currentImage [row ][col ] == null );
542510 }
543-
544511 public Pixel geiWoBaby (Pixel parent , int mutationAmount ) {
545- mutationAmount = (int ) Math .pow (2 , mutationAmount );
512+ //mutationAmount = (int) Math.pow(2, mutationAmount);
513+ mutationAmount = 0 ;
546514 return new Pixel (parent .r + randomWithRange (-1 * mutationAmount , mutationAmount ), parent .g + randomWithRange (-1 * mutationAmount , mutationAmount ), parent .b + randomWithRange (-1 * mutationAmount , mutationAmount ));
547515 }
548- /*
549- This method draws the pixels on screen
550- */
551- public void paintComponent (Graphics g ) {
552- super .paintComponent (g );
553- for (int row = 0 ; row < currentImage .length ; row ++)
554- for (int col = 0 ; col < currentImage [0 ].length ; col ++) {
555- if (currentImage [row ][col ] != null ) {
556- g .setColor (currentImage [row ][col ].getColor ());
557- } else {
558- g .setColor (Color .BLACK );
559- }
560- g .drawLine (col , row , col , row );
561- }
562- }
563516 public int count () {
564517 int counter = 0 ;
565518 for (int row = 0 ; row < currentImage .length ; row ++)
0 commit comments