Unnamed Fossil Project

Check-in [5f984ad9e3]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:first version of encode lines seems to be working.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:5f984ad9e3f9bf8cfdb1070f9789b2626f9b1a32
User & Date: Derek 2013-02-26 17:38:52
Context
2013-02-26
19:01
fixed some boundary problems with the encode line function. check-in: d78910d918 user: Derek tags: trunk
17:38
first version of encode lines seems to be working. check-in: 5f984ad9e3 user: Derek tags: trunk
2013-02-24
21:55
variables for zoom in and out buttons. check-in: 29ee9c1008 user: Derek tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to maze.html.

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
...
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
...
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<style>
canvas{margin:0px;padding:0px;}
body{overflow:hidden;margin:0px;padding:0px;}
.menudiv{position:absolute;left:20px;top:0px;height:99%;background-color:#ed9;background-color:rgba(80,80,80,0.75);padding:2px 8px 2px 8px;border-style:solid;border-width:1px;border-color:#000;}
.menubutton{border-style:ridged;border-width:2px;height:12%;max-height:85px;border-color:#444;border-style:solid;background-color:#eee;
font-weight:bold;width:100%;padding:0px 8px 0px 8px;margin:2.5% 0px 2.5% 0px;}
.bigtxt{font-size:125%;}
/*.menubutton:hover{border-color:#c80;background-color:#ec7;}*/
/*.menubutton:hover{border-style:outset;}*/
.menubutton:hover{border-color:#fff;}
.menubutton:active{border-style:solid;background-color:#888;border-color:#000}
</style><script>//<!--

//globals
var canvas,ctx,mazecanvas,menudiv,
arr=[],width=30,height=30,pxsize=2,maxpxdimsum=800,
................................................................................
x,y,goalx,goaly,startx,starty,
dx=0,dy=0,
screenblocks=33,//controls zoom
dt=30,speed=12,turbofactor=1.75,pcolor="#2b2",
keys=[],mousedown=null,mouseloc=null,mousejoystickradius=80;edit=false,testonly=false,brush=1,victory=false,
savetime=10000,
helpmsg="Help Message goes here.";


















































function save(){
localStorage.saved=false;
localStorage.mazestate=JSON.stringify(
{x:x,y:y,w:width,h:height,startx:startx,starty:starty,goalx:goalx,goaly:goaly,arr:arr});
localStorage.saved=true;}

................................................................................
function playmode(){edit=false,eb.value="Edit";eb.style.backgroundColor="#fb6";pcolor=testonly?"#fe4":"#2b2";}
function editmode(){edit=true,eb.value="Test";eb.style.backgroundColor="#fea";pcolor="#f82";victory=false;}

var _=addbutton;
_("Start","#cfc",function(){x=startx+0.5,y=starty+0.5;victory=false;testonly=false;playmode();});
_("File","#cbf",function(){});
eb=_("Edit","#fb6",function(){edit?playmode():(editmode(),testonly=true);});
_("Reset","#faa",function(){testonly=false;playmode();reset(200,100);});
_("Help","#acf",function(){alert(helpmsg);});
zi=_("+",0,function(){screenblocks*=0.8;});
zo=_("-",0,function(){screenblocks/=0.8;});
//undo=_("<",0,function(){alert('undo stuff goes here.');}
zi.className+=" bigtxt";zo.className+=" bigtxt";//undo.className+=" bigtxt";
}

................................................................................
window.onload=function(){
canvas=crElem("canvas",document.body);
mazecanvas=crElem("canvas");
function resize(){canvas.width=window.innerWidth-2;canvas.height=window.innerHeight-2;}
window.onresize=resize;
resize();
ctx=canvas.getContext("2d");
if(!load())reset(50,50);
drawmaze();

function changespeed(){
dx=0,dy=0;
var r=mousejoystickradius,tf=turbofactor;
if(!edit&&mousedown&&mouseloc||edit&&brush==4){// mouse joystick
dx+=tf*speed*Math.min(Math.max((mouseloc[0]-mousedown[0])/r, -1),1);







<
<







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







|







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
...
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
...
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<style>
canvas{margin:0px;padding:0px;}
body{overflow:hidden;margin:0px;padding:0px;}
.menudiv{position:absolute;left:20px;top:0px;height:99%;background-color:#ed9;background-color:rgba(80,80,80,0.75);padding:2px 8px 2px 8px;border-style:solid;border-width:1px;border-color:#000;}
.menubutton{border-style:ridged;border-width:2px;height:12%;max-height:85px;border-color:#444;border-style:solid;background-color:#eee;
font-weight:bold;width:100%;padding:0px 8px 0px 8px;margin:2.5% 0px 2.5% 0px;}
.bigtxt{font-size:125%;}


.menubutton:hover{border-color:#fff;}
.menubutton:active{border-style:solid;background-color:#888;border-color:#000}
</style><script>//<!--

//globals
var canvas,ctx,mazecanvas,menudiv,
arr=[],width=30,height=30,pxsize=2,maxpxdimsum=800,
................................................................................
x,y,goalx,goaly,startx,starty,
dx=0,dy=0,
screenblocks=33,//controls zoom
dt=30,speed=12,turbofactor=1.75,pcolor="#2b2",
keys=[],mousedown=null,mouseloc=null,mousejoystickradius=80;edit=false,testonly=false,brush=1,victory=false,
savetime=10000,
helpmsg="Help Message goes here.";

//pos or neg encodes maze in lines, depending on which is shorter.
//goes through and encodes all lines at least a certain length, then repeats with half that length
//till all points are encoded without unnecessary redundancy.
function encodelines(o){
var w=o.w,h=o.h,s=o.start,e=o.end,arr=o.arr.slice(0),i=0,j,k,v,min,l=w*h,r=[],//retval
lines=[[[],[]],[[],[]]];//pos,neg*horiz,vert
arr[s[0]+w*s[1]]=0;//assure start empty
for(v=0;v<2;++v){//pos,neg
for(min=(w+h)/4;min>0;min/=2){
for(i=0;i<l;++i){if(arr[i]==2)continue;j=i;k=i;
while((i==j||j%w)&&(arr[j]==v||arr[j]==2)){if(arr[j]==v)k=j;++j;}//2 means already encoded
if(k-i>=min){lines[v][0].push([i,k-i]);alert("horizontal: "+i+","+k);for(j=i;j<=k;++j)arr[j]=2;continue;}//k==i means length zero
j=i;k=i;
while(j<l&&(arr[j]==v||arr[j]==2)){if(arr[j]==v)k=j;j+=w;}
if((k-i)/w>=min){lines[v][1].push([i,k/w]);alert("vertical:"+i+","+k);for(j=i;j<=k;j+=w)arr[j]=2;}}}
for(j=0;j<l;++j)if(arr[j]==2)arr[j]=v;}//reset 2s
i=0;
r[i++]=w;r[i++]=h;
r[i++]=1;r[i++]=s[0];r[i++]=s[1];
r[i++]=1;r[i++]=e[0];r[i++]=e[1];
r[i++]=0;
alert(JSON.stringify(lines));
var nl=lines[0][0].length+lines[0][1].length,pl=lines[1][0].length+lines[1][1].length;
lines=lines[nl<pl?0:1];//use shorter lineset
var a=lines[0],b=lines[1],lastk=0;
k=0;
function _sort(s,t){return s[0]-t[0];}
a.sort(_sort);b.sort(_sort);
alert(JSON.stringify({a:a,b:b}));
for(j=0;j<a.length;j+=2){
k=a[j];r[i++]=a[j];r[i++]=a[j+1];lastk=k;}
k=0;lastk=0;
for(j=0;j<b.length;j+=2){
k=b[j];r[i++]=(k-lastk)/w;r[i++]=b[j+1];lastk=k;}
return r;}

//alert()
setTimeout(function(){alert('here');encodelines({w:width,h:height,start:[0,0],end:[10,100],arr:arr});}, 1000);

function decodelines(str){
}

function encodearrayhex(arr){
}

function decodearrayhex(hexstr){
}


function save(){
localStorage.saved=false;
localStorage.mazestate=JSON.stringify(
{x:x,y:y,w:width,h:height,startx:startx,starty:starty,goalx:goalx,goaly:goaly,arr:arr});
localStorage.saved=true;}

................................................................................
function playmode(){edit=false,eb.value="Edit";eb.style.backgroundColor="#fb6";pcolor=testonly?"#fe4":"#2b2";}
function editmode(){edit=true,eb.value="Test";eb.style.backgroundColor="#fea";pcolor="#f82";victory=false;}

var _=addbutton;
_("Start","#cfc",function(){x=startx+0.5,y=starty+0.5;victory=false;testonly=false;playmode();});
_("File","#cbf",function(){});
eb=_("Edit","#fb6",function(){edit?playmode():(editmode(),testonly=true);});
_("Reset","#faa",function(){testonly=false;playmode();reset(20,20);});
_("Help","#acf",function(){alert(helpmsg);});
zi=_("+",0,function(){screenblocks*=0.8;});
zo=_("-",0,function(){screenblocks/=0.8;});
//undo=_("<",0,function(){alert('undo stuff goes here.');}
zi.className+=" bigtxt";zo.className+=" bigtxt";//undo.className+=" bigtxt";
}

................................................................................
window.onload=function(){
canvas=crElem("canvas",document.body);
mazecanvas=crElem("canvas");
function resize(){canvas.width=window.innerWidth-2;canvas.height=window.innerHeight-2;}
window.onresize=resize;
resize();
ctx=canvas.getContext("2d");
if(!load())reset(20,20);
drawmaze();

function changespeed(){
dx=0,dy=0;
var r=mousejoystickradius,tf=turbofactor;
if(!edit&&mousedown&&mouseloc||edit&&brush==4){// mouse joystick
dx+=tf*speed*Math.min(Math.max((mouseloc[0]-mousedown[0])/r, -1),1);