-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsketch.js
195 lines (152 loc) · 4.21 KB
/
sketch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
let qtree;
let count = 0;
let variable = '1';
let file_variable='1';
let total_count = 0;
let vvariable='1';
let max_points = 0;
function setup() {
localStorage.clear();
createCanvas(400, 400);
background(255);
let boundary = new Rectangle(200, 200, 200, 200);
qtree = new QuadTree(boundary, 4);
for(variable=0; variable<500; variable++ )
{
let x = (Math.random()*1000)%400;
let y = (Math.random()*1000)%400;
let name;
//forest
//college
//park
//hospital
let rand_var = Math.floor ((Math.random()*10)%4);
if( rand_var == 0)
{
name = 'forest'
}
else if(rand_var == 1)
{
name = 'college';
}
else if(rand_var == 2)
{
name = 'park';
}
else{
name = 'hospital';
}
localStorage.setItem('x'+ variable , x);
localStorage.setItem('y'+variable , y);
localStorage.setItem('z'+variable , name);
let p = new Point(x, y,name);
qtree.insert(p);
//console.log('bgcolor'+variable);
// var x = localStorage.getItem('x'+variable);
// var y = localStorage.getItem('y'+variable);
// alert(x);
// alert(y);
//alert(name);
}
//uncomment down sinppet for retriving stored data :)
//retreiving from storage and printing
for(variable=0; variable<500; variable++ )
{
var x = localStorage.getItem('x'+variable);
var y = localStorage.getItem('y'+variable);
var name = localStorage.getItem('z'+variable);
let p = new Point(x, y,name);
qtree.insert(p);
//console.log('bgcolor'+variable);
//alert(x);
//alert(y);
//alert(name);
}
}
function hello()
{
//alert("fdf");
}
function readfile()
{
for(let i = 1; i<=count/2; i++ )
{
var x = localStorage.getItem('a'+vvariable);
var y = localStorage.getItem('b'+vvariable);
var name = localStorage.getItem('c'+vvariable);
vvariable++;
console.log(x,y,name,i);
}
}
function draw() {
// localStorage.clear();
if(mouseIsPressed)
{
// let p = new Point(mouseX, mouseY);
//city=prompt('Enter the city name');
hello();
let x = randomGaussian(mouseX);
let y = randomGaussian(mouseY);
let pname=document.getElementById("pl").value;
let p = new Point(x, y,pname);
qtree.insert(p);
console.log(p);
// p.name=pname;
console.log("mouse clicked");
max_points++;
console.log("max points",max_points);
}
background(0);
qtree.show();
stroke(0, 255, 0);
rectMode(CENTER);
// let range = new Rectangle(90, 80 , 25, 25);
/*let points = qtree.query(range);
total_count = 0;
for (let p of points) {
count++;
// if(p.name==document.getElementById("pl").value )
//console.log(p.name);
//console.log(p.x , p.y);
localStorage.setItem('a'+ file_variable , p.x);
localStorage.setItem('b'+file_variable , p.y);
localStorage.setItem('c'+file_variable , p.name);
file_variable++;
strokeWeight(4);
point(p.x, p.y);
}
console.log("No of points in this range ",count);
readfile();
count = 0;*/
//rect(range.x, range.y, range.w * 2, range.h * 2);
if(!mouseIsPressed)
{
let range = new Rectangle(mouseX, mouseY , 25, 25);
if (mouseX < width && mouseY < height) {
rect(range.x, range.y, range.w * 2, range.h * 2);
let points = qtree.query(range);
//console.log(total_count);
total_count = 0;
for (let p of points) {
count++;
localStorage.setItem('a'+ file_variable , p.x);
localStorage.setItem('b'+file_variable , p.y);
localStorage.setItem('c'+file_variable , p.name);
file_variable++;
/* if(p.name==document.getElementById("pl").value )
{
console.log(p.name);*/
strokeWeight(4);
point(p.x, p.y);
//}
}
//console.log(count);
console.log("No of points in this range ",count/2);
readfile();
count = 0;
}
//console.log("No of points in this range ",count);
//count = 0;
}
//console.log(total_count);
}