-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
98ff4c7
commit 0372757
Showing
3 changed files
with
175 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,22 @@ | ||
# <p align="center">A*</p> | ||
# <p align="center">A* Vizualized</p> | ||
|
||
|
||
<p align="center"> | ||
<img width="500" src="https://i.postimg.cc/5NNbhBbn/CaptureA.png"> | ||
<img width="500" src="https://i.postimg.cc/CxRSLqrc/Capture5.png"> | ||
</p> | ||
|
||
### About | ||
## About | ||
|
||
This is the visualized version of the A* algorithm . | ||
This is the visualized version of the A* algorithm. | ||
Now you can draw the walls to see better how this algorithm works. | ||
|
||
### Credits | ||
* [TheCodingTrain](https://www.youtube.com/user/shiffman) | ||
* [GeeksForGeeks](https://www.geeksforgeeks.org) | ||
## What's new | ||
|
||
* UI | ||
* The walls can be drawn | ||
* Beautifull Code? | ||
|
||
## Credits | ||
|
||
* [TheCodingTrain](https://www.youtube.com/user/shiffman) | ||
* [GeeksForGeeks](https://www.geeksforgeeks.org) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,50 @@ | ||
class Cell{ | ||
public int i, j; | ||
public class Cell{ | ||
public int i, j, radius; | ||
private color cellColor; | ||
public boolean isBlocked; | ||
|
||
public float f = Float.MAX_VALUE, g, h; | ||
public boolean isBlocked = false; | ||
public Cell parent; | ||
|
||
// CELL CONSTRUCTOR | ||
Cell(int i, int j){ | ||
this.i = i; | ||
this.j = j; | ||
this.parent = null; | ||
this.isBlocked = false; | ||
this.cellColor = color(255); | ||
this.radius = 0; | ||
// REMEMBER , IN ORDER FOR THIS TO WORK THE CLASS MUST BE SET PUBLIC | ||
registerMethod("draw", this); | ||
} | ||
// CHANGE THE CELL COLOR WHEN NEEDED | ||
public void cellColor( color col ){ | ||
if( !this.isBlocked ) | ||
this.cellColor = col; | ||
} | ||
|
||
public void show(int r, int g, int b){ | ||
stroke(255); | ||
fill(r, g, b); | ||
if(this.isBlocked) | ||
fill(0, 0, 0); | ||
rect( this.j * scale, this.i * scale, scale, scale ); | ||
void draw(){ | ||
if(frameCount % 1 == 0 && this.radius > 0){ | ||
this.radius--; | ||
} | ||
// RADIUS ANIMATION | ||
if( MousePress && !this.isBlocked && this.isOverCell() ){ | ||
this.cellColor = color(25); | ||
this.radius = 20; | ||
this.isBlocked = true; | ||
} | ||
// DRAWING A CELL | ||
noStroke(); | ||
fill( this.cellColor ); | ||
rect( this.j * scale + 1, this.i * scale + 1, scale - 1, scale - 1, this.radius); | ||
} | ||
|
||
// IF THE MOUSE IS CLICKED AND OVER THE CELL RETURN TRUE | ||
private boolean isOverCell() { | ||
int offsetX = mouseX - this.j * scale; | ||
int offsetY = mouseY - this.i * scale; | ||
|
||
return (offsetX <= scale && offsetX >= 0 && offsetY <= scale && offsetY >= 0); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters