Created
July 31, 2019 18:30
-
-
Save volfegan/f1f3676dfc0e6ccc2c4593e7d74691dd to your computer and use it in GitHub Desktop.
QuadTree_Collisions debugging starter code
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
// Daniel Shiffman | |
// http://codingtra.in | |
// http://patreon.com/codingtrain | |
//Videos | |
//Part 1: | |
//https://www.youtube.com/watch?v=OJxEcs0w_kE | |
//Part 2: | |
//https://www.youtube.com/watch?v=QQx_NmCIuCY | |
//This code is part 2 video of the challenge. | |
//DEBUGGING FOR CC_098.3_QuadTree_Collisions | |
//https://github.com/CodingTrain/website/tree/master/CodingChallenges/CC_098.3_QuadTree_Collisions/Processing | |
Quadtree qtree; | |
public void setup () { | |
size(400, 600); | |
background(0); | |
Rectangle boundry =new Rectangle (width/2, height/2, width/2, height/2); | |
qtree = new Quadtree (boundry, 8); | |
int maxPoints = 10000; | |
for (int i = 0; i < maxPoints; i++) { | |
float x = (width/4) +randomGaussian(width /4, width / 8); | |
float y = (height/4) + randomGaussian(height / 4, height / 8); | |
Point p = new Point (x, y); | |
qtree.insert(p); | |
} | |
ArrayList <Point> points = new ArrayList <Point> (); | |
Rectangle range =new Rectangle (width/2, height/2, width*2, height*2); | |
qtree.query(range, points); | |
println("Points created = "+maxPoints); | |
println("Points found = "+points.size()); | |
} | |
public void draw () { | |
background(0); | |
qtree.show(); | |
ArrayList <Point> points = new ArrayList <Point> (); | |
stroke(0, 255, 0); | |
rectMode(CENTER); | |
//using mouse | |
//Rectangle range =new Rectangle (mouseX, mouseY, 25, 25); | |
//scaning all screen for qtree points | |
Rectangle range =new Rectangle (width/2, height/2, width*2, height*2); | |
strokeWeight(1); | |
rect((float)range.x, (float) range.y, (float) range.width * 2, (float)range.height * 2); | |
qtree.query(range, points); | |
for (Point p : points) { | |
strokeWeight(4); | |
point((float)p.x, (float)p.y); | |
} | |
} | |
public float randomGaussian(float min, float max) { | |
return min + randomGaussian() * (max - min); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment