@@ -20,10 +20,10 @@ function setup() {
2020
2121function draw ( ) {
2222 background ( 0 ) ;
23- show ( qtree ) ;
2423
25- // let range = new Rectangle(mouseX, mouseY, 25, 25);
2624 let range = new Circle ( mouseX , mouseY , 64 ) ;
25+ show ( qtree , range ) ;
26+ stroke ( "pink" ) ;
2727 ellipse ( range . x , range . y , range . r * 2 ) ;
2828
2929 let points = qtree . query ( range ) ;
@@ -32,31 +32,37 @@ function draw() {
3232 strokeWeight ( 4 ) ;
3333 point ( p . x , p . y ) ;
3434
35- let neighbors = qtree . closest ( new Point ( p . x , p . y ) , 8 , 128 ) ;
36- stroke ( 0 , 255 , 0 , 50 ) ;
37- strokeWeight ( 1 ) ;
38- for ( let n of neighbors ) {
39- line ( p . x , p . y , n . x , n . y ) ;
35+ if ( mouseIsPressed ) {
36+ let neighbors = qtree . closest ( new Point ( p . x , p . y ) , 8 ) ;
37+ stroke ( 0 , 255 , 0 , 50 ) ;
38+ strokeWeight ( 1 ) ;
39+ for ( let n of neighbors ) {
40+ line ( p . x , p . y , n . x , n . y ) ;
41+ }
4042 }
4143 }
4244}
4345
44- function show ( qtree ) {
45- stroke ( 255 ) ;
46+ function show ( qtree , range ) {
4647 noFill ( ) ;
4748 strokeWeight ( 1 ) ;
4849 rectMode ( CENTER ) ;
50+ stroke ( 255 , 41 ) ;
51+ if ( range . intersects ( qtree . boundary ) ) {
52+ stroke ( 255 ) ;
53+ }
4954 rect ( qtree . boundary . x , qtree . boundary . y , qtree . boundary . w * 2 , qtree . boundary . h * 2 ) ;
5055
56+ stroke ( 255 ) ;
57+ strokeWeight ( 2 ) ;
5158 for ( let p of qtree . points ) {
52- strokeWeight ( 2 ) ;
5359 point ( p . x , p . y ) ;
5460 }
5561
5662 if ( qtree . divided ) {
57- show ( qtree . northeast ) ;
58- show ( qtree . northwest ) ;
59- show ( qtree . southeast ) ;
60- show ( qtree . southwest ) ;
63+ show ( qtree . northeast , range ) ;
64+ show ( qtree . northwest , range ) ;
65+ show ( qtree . southeast , range ) ;
66+ show ( qtree . southwest , range ) ;
6167 }
6268}
0 commit comments