-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDrawingStrategy.js
230 lines (223 loc) · 5.95 KB
/
DrawingStrategy.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
class DrawingStrategy {
constructor(type,gui){
switch(type) {
case "A":
this.strategy = new StrategyDrawAllGrid(gui);
break
case "B":
this.strategy = new StrategyDrawGrid(gui);
break
case "C":
this.strategy = new StrategyDrawTile(gui);
break
default:
this.strategy = new StrategyDrawAllGrid(gui);
}
}
setup (){
this.strategy.setup()
}
update (){
this.strategy.update()
}
draw (){
this.strategy.draw()
}
}
DrawingStrategy.set_gui=function (gui) {
var folder_scenes = gui.addFolder("Scenes");
folder_scenes.open();
var key;
DrawingStrategy.strategies = {};
DrawingStrategy.folders = {};
for( key in DrawingStrategy.strategies_object ){
var object = DrawingStrategy.strategies_object[key];
var folder = DrawingStrategy.folders[key] = gui.addFolder(key);
folder.open();
DrawingStrategy.strategies[key]=new DrawingStrategy(key,DrawingStrategy.folders[key]);
folder_scenes.add({key:key,f:function(){
var dom_element = DrawingStrategy.folders[this.key];
clear_canvas();
DrawingStrategy.do_close_all_folders();
dom_element.domElement.style.display='block';
DrawingStrategy.scene = DrawingStrategy.strategies[this.key];
DrawingStrategy.scene.setup();
DrawingStrategy.scene.draw();
}},'f').name(key);
}
}
DrawingStrategy.do_close_all_folders = function (argument) {
var key;
for( key in DrawingStrategy.folders ){
var object = DrawingStrategy.folders[key];
var d = object.domElement.style.display;
console.log("d : ",d);
object.domElement.style.display='none';
}
}
DrawingStrategy.strategies_object = {
A:"(Description here)",
B:"(Description here)",
C:"(Description here)"
}
DrawingStrategy.strategies_list = [{
name:"",
description:"",
slug:""
}];
class StrategyDraw {
constructor(config) {
this.config = config;
this.grids = grid_utils.get_extensions(config);
this.grids.pop();
}
update_draw(){
this.update();
this.draw();
}
}
class StrategyDrawAllGrid extends StrategyDraw{
constructor(gui) {
var dim =200;
var config={
radius:20,
dimension:dim*1.5,
dim
}
super(config)
// console.log('StrategyDrawAllGrid created')
}
setup(gui){
var dim =this.config.dim;
/*
var config={
radius:20,
dimension:dim*1.5
}
*/
// let grids = grid_utils.get_extensions(config);
// grids.pop();
var w = dim;
var h = dim;
var cols = innerWidth/dim|0;
this.grids.forEach(function (argument,i) {
var current_grid = argument;
var x = w*(i%cols)+10;
var y = h*((i/cols)|0)+10;
// console.log(x,y);
// SAVE SAVE SAVE SAVE SAVE SAVE SAVE SAVE SAVE
ccontext.save();
ccontext.beginPath();
ccontext.rect(x, y, w-10, h-10);
ccontext.clip();
// ccontext.closePath();
// debugger;
var grid_data = Grid.grid_data_from_tile(x,y,current_grid);
Grid.draw_grid(ccontext,grid_data);
var polygon_count=0
var config2 = {
palettes:chroma.brewer,
// gui,
grid_data,
canvasCtx:ccontext,
polygon_count
}
// console.log("config2 : ",config2);
var grid_drawing = new GridDrawing(config2);
grid_drawing.do_randomize_strategy();
grid_drawing.draw_current();
ccontext.rect(x, y, w-10, h-10);
ccontext.stroke();
//RESTORE RESTORE RESTORE RESTORE RESTORE RESTORE RESTORE RESTORE RESTORE
ccontext.restore();
})
}
update(){console.log('StrategyDrawAllGrid algorithm');}
draw(){console.log('StrategyDrawAllGrid algorithm');}
}
class StrategyDrawTile extends StrategyDraw{
constructor(gui) {
var radius = 200;
var dim =1000;
var config={
radius,
dimension:dim*1.5
}
super(config);
}
setup(){}
update(){}
draw(){}
}
class StrategyDrawGrid extends StrategyDraw{
constructor(gui) {
var radius = 50;
var size = 50;
var dim =200;
var config={
radius,
dimension:dim*1.5
}
super(config);
this.radius = radius;
this.size = size;
// console.log('StrategyDrawGrid created');
gui.add(this,"radius",1,100).onChange(this.update_radius).step(0.5);
gui.add(this,"size",1,500).onChange(this.update_size).step(0.5);
var folder1 = gui.addFolder('f');
folder1.open();
//TODO: can't believe i'm using this
let that = this;
this.grids.forEach(function (argument,i) {
folder1.add({f: ()=> {
console.log("argument : ",argument);
console.log("i : ",i);
// this.current_grid = this.grids[0];
console.log("this : ",that);
that.current_grid = that.grids[i];
clear_canvas();
that.update_radius(that.radius,that);
that.update_size(that.radius,that);
that.update_draw();
// that.draw();
}},'f').name(argument.name());
})
DrawingStrategy.set_gui(gui);
DrawingStrategy.scene = DrawingStrategy.strategies.B;
DrawingStrategy.scene.setup();
DrawingStrategy.scene.update();
}
//TODO: get rid of this scope thing
update_radius(r,scope){
if(!scope)scope = this.object;
clear_canvas();
scope.current_grid.radius = r;
scope.current_grid.update_r_dependency();
scope.current_grid.update_tile();
scope.update_draw();
// this.object.draw();
}
//TODO: get rid of this scope thing
update_size(r,scope){
if(!scope)scope = this.object;
clear_canvas();
scope.current_grid.radius = r;
scope.current_grid.update_r_dependency_size();
scope.current_grid.update_tile();
scope.update_draw();
// this.object.draw();
}
setup(){
this.current_grid = this.grids[8];
}
update(){
var x = innerWidth*0.5;
var y = innerHeight*0.5;
this.grid_data = Grid.grid_data_from_tile(x,y,this.current_grid);
// console.log('StrategyDrawGrid algorithm');
}
draw(){
ccontext.strokeStyle = 'white';
Grid.draw_grid(ccontext,this.grid_data);
}
}