@@ -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,43 @@ 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- noFill ( ) ;
47- strokeWeight ( 1 ) ;
48- rectMode ( CENTER ) ;
49- rect ( qtree . boundary . x , qtree . boundary . y , qtree . boundary . w * 2 , qtree . boundary . h * 2 ) ;
46+ function show ( qtree , range ) {
47+ if ( qtree . divided ) {
48+ show ( qtree . northeast , range ) ;
49+ show ( qtree . northwest , range ) ;
50+ show ( qtree . southeast , range ) ;
51+ show ( qtree . southwest , range ) ;
52+ }
5053
54+ stroke ( 255 ) ;
55+ strokeWeight ( 2 ) ;
5156 for ( let p of qtree . points ) {
52- strokeWeight ( 2 ) ;
5357 point ( p . x , p . y ) ;
5458 }
5559
56- if ( qtree . divided ) {
57- show ( qtree . northeast ) ;
58- show ( qtree . northwest ) ;
59- show ( qtree . southeast ) ;
60- show ( qtree . southwest ) ;
60+ noFill ( ) ;
61+ rectMode ( CENTER ) ;
62+ strokeWeight ( 1 ) ;
63+ stroke ( 255 , 41 ) ;
64+ if ( range . intersects ( qtree . boundary ) ) {
65+ stroke ( 255 ) ;
6166 }
67+
68+ rect (
69+ qtree . boundary . x ,
70+ qtree . boundary . y ,
71+ qtree . boundary . w * 2 ,
72+ qtree . boundary . h * 2
73+ ) ;
6274}
0 commit comments