function save_data() { str=""; for (var i=0;i2) { restored=str.split(";"); for (i=0;i<(restored.length/2);i++) { zak[parseInt(restored[i*2])]=parseInt(restored[i*2+1]); } } str=ss.substring(ss.indexOf("{#end#}")+7,ss.length-1); if (str.length>2) { restored=str.split("|"); if (restored[0]!="") { for (i=0;i<(showfields.length-1);i++) { if (showfields[i]==restored[i*2] && showfields[i]!='payment') {document.forma2.elements[showfields[i]].value=restored[i*2+1]; } } } } } summa(); show(); } window.onload=restore_data; function createDescriptionField() { var s; s=""+ ""+ "
"+button("a", l_close, "close_info()",l_close)+"
data
"; return s; } function copy_info() { var ss; document.getElementById('tovary').innerHTML=createDescriptionField(); ss=window.dataframe.document.getElementById('description').innerHTML; ss=ss.replace(imgpath,infpath+"/"+imgpath); ss=ss.replace("id=\"descimage\"","id=descimage onerror=javascript:this.src='"+"/"+imgpath+"/nophoto.jpg';"); document.getElementById('description_data').innerHTML=ss; } function copy_page(a,l) { var ss; document.getElementById('tovary').innerHTML=window.dataframe.document.getElementById('content').innerHTML; document.getElementById("prilavok").style.display="block"; document.getElementById("oformit").style.display="none"; for (var i=1;i<=l;i++) {document.getElementById("smenu"+i).className="smenu"} document.getElementById("smenu"+a).className="smenuselected"; } function close_info() { show(); //document.getElementById('descfloat').style.display="none"; window.dataframe.document.location.href="js/null.html"; } function show_info(a) { obj=document.getElementById("div_description"); obj.innerHTML=createDescriptionField(); document.getElementById("description_data").innerHTML=" Loading..."; document.getElementById("tovary").innerHTML=""; window.dataframe.location.replace(a); } function productImage(a) { document.getElementById("prilavok").style.display="block"; document.getElementById("oformit").style.display="none"; document.getElementById('tovary').innerHTML=createDescriptionField(); document.getElementById("description_data").innerHTML=" Loading..."; document.getElementById('description_data').innerHTML=""; } function get_var_from_str(sstr,svar) { ss=sstr.split("&"); res=""; for (i=0;i0 && reqfields[0].length!=0) { for (i=0;i<(showfields.length-1);i++) { if (reqfields[i]==1) { paynote=paynote + " " + namefields[i] + ": " + document.forma2.elements[showfields[i]].value; if (showfields[i]=="clientemail") {if (!isValidEmail(document.forma2.elements[showfields[i]].value,true)) {y=1; str2=str2 + namefields[i] + "\n";};} else { if (document.forma2.elements[showfields[i]].value.length<2) {y=1; str2=str2 + namefields[i] + "\n";} } } } } if (y!=0) {str2=str2.substr(0,(str2.length-1)); alert (l_noemail + "\n" + str2 + "");} else { document.forma2.zak_pos.value=printable(); makePayments() ; document.getElementById('payment_loading').style.display='block'; if (clearcookie==2) {deleteCookie("rapidshop");} if (flag_pay_module=="url") { document.forma2.target=""; document.forma2.submit(); } else { document.forma2.target="dataframe"; document.forma2.submit(); setTimeout("document.forma_pay.submit()",1000); } } } function get_var(svar) { ss=document.location.href.split("&"); res=""; for (i=0;i*","");} else {return i}; } function formatCur(amount, znakov, delim) { var s,k; s=""; if (delim==undefined) { delim="";} amount=Math.round(amount*Math.pow(10,znakov))/Math.pow(10,znakov); if (znakov==2) { if (String(amount).indexOf(".")==-1) {str=amount+".00"} else {kp=(String(amount).length-String(amount).indexOf(".")); if (kp==2) {str=amount+"0"} else {str=amount} }; } if (znakov==1) {if (String(amount).indexOf(".")==-1) {str=amount+".0"} else {str=amount}; } if (znakov!=1 && znakov!=2) {str=amount;} str=String(str); k=-1;start=0; if (str.indexOf(".")==-1) {start=1;k=0;} for (var i=(str.length-1);i>=0;i--) { if (str.substr(i,1)==".") {start=1;} s=str.substr(i,1)+s; if (start==1) {k++; if (k==3 && i>0) {k=0;s=delim+s;}} } return s; } function convert_data() { min_summa=Number(min_summa);summa_dostavki=Number(summa_dostavki);tipskidki=Number(tipskidki); skidkakol1=Number(skidkakol1);skidkaval1=Number(skidkaval1);skidkakol2=Number(skidkakol2); skidkaval2=Number(skidkaval2);stepvar=Number(stepvar);tablewidth=Number(tablewidth); leftwidth=Number(leftwidth);rightwidth=Number(rightwidth);gnwidth=Number(gnwidth);gpwidth=Number(gpwidth); gkwidth=Number(gkwidth);idwidth=Number(idwidth);add2width=Number(add2width);photowidth=Number(photowidth); GrN=document.getElementById("GrNStr").innerHTML.split("|"); GN=document.getElementById("GNStr").innerHTML.split("|"); GText=document.getElementById("GTextStr").innerHTML.split("|"); reqfields=reqfieldsstr.split("|"); showfields=showfieldsstr.split("|"); namefields=namefieldsstr.split("|");paymentsname=paymentsnamestr.split("|"); znakov=znakov-1; perpage=stepvar; for (var i=0;i<=GC;i++) { zak[i]=0; }; k=0; k2=0; k3=0; for (var i=GrC+1;i>0;i--) { l=GrP[i]-GrP[i-1]; k=k+l; k2=k2+l; k3=k3+l; if (l==0) {GCount[i-1]=k; } else { GCount[i-1]=l; if (GrLevel[i-1]==-3) {k=0;}; if (GrLevel[i-1]==-2) {k=0; k2=0;}; if (GrLevel[i-1]==-1) {k=0; k2=0; k3=0;} } } k1=0; k2=0; k3=0; k4=0; for (var i=GrC+1;i>0;i--) { l=GrP[i]-GrP[i-1]; if (GrLevel[i-1]==-4) {k4=k4+l; GCount[i-1]=k4; k3=k3+l; k2=k2+l; k1=k1+l; k3=0; }; if (GrLevel[i-1]==-3) {k3=k3+l; GCount[i-1]=k3; k2=k2+l; k1=k1+l; k3=0; }; if (GrLevel[i-1]==-2) {k2=k2+l; GCount[i-1]=k2; k1=k1+l;k2=0;}; if (GrLevel[i-1]==-1) {k1=k1+l; GCount[i-1]=k1; k1=0;}; } m=0; str_test=""; for (var i=0; ii="+i+";GrLevel="+GrLevel[i]+";vlogen="+vlogen[i]; } vlogen[GrC]=-m; } function activateCart() { if (GrC!=-1) {while (GrP[curCat]==GrP[curCat+1]) {curCat++;}} window.name="shop"; category(curCat); } function insertContent(a,s) { if (document.getElementById(a)!=null) {document.getElementById(a).innerHTML=s;} } function createWS() { var s; document.getElementById("warning").style.display="none"; convert_data(); l=Math.floor((tablewidth-rightwidth-leftwidth)/gnwidth); if (tip_list==3) {stepvar=Math.round(stepvar/l)*l;gpwidth=gnwidth;idwidth=gnwidth;add2width=gnwidth;gkwidth=gnwidth;} if (tip_list==2) {stepvar=Math.round(stepvar/l)*l;idwidth=gnwidth;add2width=gnwidth;gpwidth=gkwidth;} insertContent("categories-container",createCategoriesList()); insertContent("search-container",createSearch()); insertContent("informer-container",cartInformer()); s=""+ ""; insertContent("content",s); } function PriceListButton() { var s; s=""+l_priceList+""; return s; } function createSearch() { var s; s=""+ "
"+l_search+"
"+ "
"+button("b", l_ok, "search()")+"
"; return s; } function createCategoriesList() { var s; s=""; ss=""; s+="
"+l_categories+"
"; return s; } function button(type,text,action,title) { if (type=="a") {return ""+text+""} else if (type=="b") {return ""} else if (type=="buybuttons") {return ""} } function makeCartResume() { var s,ss; ss="
"; s=zak_kolvo+" "+l_items+ss+(show_prices==2?l_total+" "+rubbefore+" "+formatCur(zak_summa,znakov,tToken)+rubafter:"")+""; return s; } function cartInformer() { var s,ss; ss=""; s="
"+l_shopping_cart+ss; s+=""+makeCartResume(ss)+""+ss+ button("b", l_to_checkout, "checkout()")+ss+ button("a", l_viewcart, "viewCart()")+" "+button("a", l_clearcart, "clear_cart()")+ "
"; return s; } function make_client_info() { str="

"; for (i=0;i<(showfields.length-1);i++) { str=str + ""; } str=str+"
"+ ((reqfields[i]==1) ? "*": "") +namefields[i]+""; if (showfields[i]=='payment') { str=str + ""; } else {str=str + "";} str=str+"

"; return str; } function customerDetails() { var s; s="
"+ ""+ ""+ ""+ ""+ ""+ ""+ ""+ ""+ ""+ ""+ ""+ ""+ ""+ ""+ ""+ ""+ ""+ ""+ ""+ ""+ ""+ "
"+l_yourorder+"
"+ l_rem1+"
_
"+ "

"+button("b", l_printable, "printOrder()")+ "

"+ ""+ ""+ ""+ "
"+l_deliverydata+"
"+ l_rem2+make_client_info()+ "
"+ "
"+ "
"+ button("b",l_returnhall, "razdel_num=0;show()")+ ""+ ""+ "payzone"+ "
"+ "
"+ "
"+ "
"; return s; } function summa() { zak_summa=0;zak_kolvo=0; for (var i=0;illast){s=""+GrN[k]+" / "+s;llast=GrLevel[k];} } } s=""+s+""; return s; } function pageTitle(a) {var s;s="
"+a+"
";return s;} function display(a) {pos=a;show();} function printRow(id,pp) { var nrow1,nrow1e,nrow2,nrow2e,photowidth2,b1,b2; str=""; nrow1=""; nrow1e=""; curalign=""; nrow2=""; nrow2e="";b1="";b2=""; if ((pp/2-Math.round(pp/2))==0 && tip_list==1) {k="chet"} else {k="nechet"}; if (tip_list==3) {curalign="text-align:center";photowidth2=gnwidth;} if (tip_list==2) {curalign="text-align:left";photowidth2=photowidth;} if (descpopup==1) { //���� � ����� �������� str01=""; str02=""; //���� � ������� �������� str21=""; str22=""; } else { str01=""; str02=""; str21=""; str22=""; } if (infon[id]==3 || infon[id]==2) {str21=str01;str22=str02;} else if (infon[id]==1) {str01=""; str02="";} else {str01="";str02="";}; if (tip_list==3) {nrow2="";nrow2e=""; str+="
"; } if (tip_list!=1) {b1="
";b2="
"; str+=nrow2+""+nrow2e;} if (tip_list==2) {nrow1="";nrow1e="";str+=""; return str; } function show() { var curp,lastp; sShow=""; if (razdel_num==0) { if (search_on==0) {sShow=pageTitle(catTree(curCat))} else {sShow=pageTitle(l_searchresults+" "+poisk_str+"");} } else { sShow=pageTitle(l_shopping_cart); } sShow+="
"+str21+""+l_productdescription+""+str22+"
";} str+=nrow1+nrow2+""+nrow1e+nrow2e; if (show_product_id==2) {str+=nrow1+nrow2+""+nrow1e+nrow2e; } if (show_add_field2==2) {str+=nrow1+nrow2+""+nrow1e+nrow2e;} if (tip_list==2) {str+="
"+str01+GN[id]+str02+""+((tip_list!=1) ? l_ID : "")+" "+GKod[id]+""+GText[id]+"
";} if (show_prices==2) {str+=nrow1+nrow2+""+nrow1e+nrow2e;} str+=nrow1+nrow2+""+nrow1e+nrow2e; if (tip_list!=1) {str+="
"+b1+rubbefore+formatCur(GP[id],znakov,tToken)+rubafter+b2+""+ ""+ ""; if (GK[id]>0) { if (buy_button==2) { str+=""+button("buybuttons","+","plus("+ pp +")",l_addtocart); str+=button("buybuttons","-","minus("+ pp +")",l_cartout)+""; } else if (buy_button==1) { str=str+""; } } else {str+=""+l_not_available+"";} str+="
"}; str=str+"
"; if (tip_list==3) {l=Math.floor((tablewidth-leftwidth-rightwidth)/gnwidth); m=0;} if (tip_list==1) {l=-2; sShow=sShow+""+(show_product_id==2 ? "":"") +(show_add_field2==2 ? "":"") +"";}; document.getElementById("cartResume").innerHTML=makeCartResume(); if (search_on==0) { if (razdel_num==0) { if (tip_sek==0) {end_sek=GrP[curCat+1]} else {end_sek=GC}; } else { start_sek=0; end_sek=zak_count; } } for (var i=pos; i<(pos+stepvar);i++) { m=m+1; nrow=""; if (tip_list==3) { if (m==l) {m=0; } else {nrow="";}; } if (search_on==0) { if (razdel_num==0 ) { if (i1) { s+="

"+l_page+" "; for (var i=1; i<=lastp;i++) { if (i==curp) {s+=""+i+" ";} else {s+=""+i+" ";} } s+=""+l_display_all+"

"; } return s; } function maxperpage() { category(curCat); stepvar=10000; show(); } function category(a) { stepvar=perpage; if (vlogen[a]==1) { if (document.getElementById("menu2p"+a).style.display=="none") {document.getElementById("menu2p"+a).style.display="block";} else {document.getElementById("menu2p"+a).style.display="none";} } else { curCat=a; search_on=0; document.getElementById("poisk_str").value=""; razdel_num=0; pos=GrP[curCat]; if (curCat==(GrC+1)) {pos=0; tip_sek=1;} else {tip_sek=0;} if (tip_sek==0) {end_sek=GrP[curCat+1]} else {end_sek=GC+1}; if (tip_sek==0) {start_sek=GrP[curCat]} else {start_sek=0}; show(); } } function svernut() { for (var i=0; i<=GrC; i++) { if (vlogen[i]==1) {document.getElementById("menu2p"+i).style.display="none";} } } function clear_cart() { for (var i=0;i<=GC;i++) {zak[i]=0}; for (i=0;i<(showfields.length-1);i++) { if (showfields[i]!='payment') {document.forma2.elements[showfields[i]].value=""; } } razdel_num=0; show(); summa(); } function zaks_count() { zak_count=-1; zak_kolvo=0; for (var i=0;i<=GC;i++) { if (zak[i]!=0) { zak_count=zak_count+1; zak_kolvo=zak_kolvo+zak[i]; zak_index[zak_count]=i; } } } function symbols(s,r) { var ss; ss=""; for (var i=0;i
"+(show_product_id==2 ? "":"")+""; for (var i=0;i"+(show_product_id==2 ? "":"")+"";k=k+1; if (j==0) {ss="lightgrey";j=1;} else {ss="white";j=0;} } str=str + "" + (show_product_id==2 ? "":"") + ""; if (j==0) {ss="lightgrey";j=1;} else {ss="white";j=0;} } str=str + "
"+l_productname+""+l_productID+""+l_addTextField+""+l_productprice+""+((show_qty==2) ? l_quantity : "")+"
"+l_productname+""+l_productID+""+l_productprice+"
"+ symbols("---",(-GrLevel[k])-1)+" "+GrN[k] +"  
"+ symbols(" ",8)+ GN[i] +""+GKod[i]+""+rubbefore + formatCur(GP[i],znakov,tToken) + rubafter+"
"+l_contacts+"
"; prOrder=window.open(""); prOrder.document.write(str); prOrder.document.write(""); prOrder.document.close(); } function products_list() { var s, colspan; colspan=1; if (show_product_id==2) {colspan++;} if (show_prices==2) {colspan=colspan+2;} s="" + (show_product_id==2 ? "":"") + (show_prices==2?"":"")+""+ (show_prices==2?"":"")+"\n"; for (var i=0;i<=zak_count;i++) { s+="" + (show_product_id==2 ? "":"") + (show_prices==2?"":"")+""+ (show_prices==2?"":"")+"\n"; } s+=""+ (show_prices==2?"":"")+"\n"; if (summa_dostavki!=0) {s+="\n";} if (show_prices==2) { if (skidkaval1!=0 || skidkaval2!=0) {s+="\n";} if (skidkaval1!=0 || skidkaval2!=0 || summa_dostavki!=0)s+=""; } s+="
"+l_productname+""+l_productID+" "+l_productprice+" "+l_quantity+" "+l_subtotal+"
"+ GN[zak_index[i]] +" "+GKod[zak_index[i]]+" "+rubbefore+ formatCur(GP[zak_index[i]],znakov,tToken)+rubafter+" "+ zak[zak_index[i]] +" "+rubbefore+ formatCur(GP[zak_index[i]]*zak[zak_index[i]],znakov,tToken)+rubafter+"
"+l_subtotal+" "+zak_kolvo+" "+rubbefore+ formatCur(zak_summa,znakov,tToken) +rubafter+"
"+l_deliverycost+" "+rubbefore+formatCur(dost,znakov,tToken)+rubafter+"
"+l_discount+" "+rubbefore+document.forma2.discountsum.value+rubafter+"
"+l_total+" "+rubbefore + document.forma2.f2total.value+rubafter+"
"; return s; } function printable() { str=""+l_yourorder+"
\n "; for (i=0;i<(showfields.length-1);i++) { str=str + "\n"; } str+="
"+namefields[i]+" "; if (showfields[i]=='payment') { str+=document.forma2.payment.options[document.forma2.payment.selectedIndex].text; } else { str=str + document.forms["forma2"].elements[showfields[i]].value; } str=str+"
\n"; str+=products_list()+"
"+l_contacts; return str; } function printOrder () { prOrder=window.open(""); prOrder.document.write(""+l_yourorder+""); prOrder.document.write(printable()); prOrder.document.close(); } function calc_delivery() { discountvalue=0; if (tipskidki==1) { if (zak_kolvo>=skidkakol1) {discountvalue=skidkaval1;} ; if (zak_kolvo>=skidkakol2) {discountvalue=skidkaval2;}} if (tipskidki==2) { if (zak_summa>=skidkakol1) {discountvalue=skidkaval1;} ; if (zak_summa>=skidkakol2) {discountvalue=skidkaval2;}} } function viewCart() { zaks_count(); if (zak_summa<=0) {alert (l_orderisnull)} else { search_off(); razdel_num=1; pos=0; show(); } } function checkout() { if (scroll_to_top==2) {document.body.scrollTop=0;} search_off(); zaks_count(); if (zak_summa<=0) { alert (l_orderisnull) } else { zak_str1="zak_str1="; zak_str2="zak_str2="; for (var i=0;i<=zak_count;i++) { zak_str1=zak_str1 + GN[zak_index[i]] + ":; Qty=" + zak[zak_index[i]] + ":; Price=" + GP[zak_index[i]]+ ":;;"; zak_str2=zak_str2 + GKod[zak_index[i]] + ":;" + zak[zak_index[i]] + ":;" ; } if (zak_count!=-1) {document.forma2.f2qty.value=zak_kolvo}; document.forma2.f2subtotal.value=formatCur(zak_summa,znakov,tToken); calc_delivery(); discountsum=zak_summa*discountvalue/100; document.forma2.discountsum.value=formatCur(discountsum,znakov,tToken); document.forma2.f2date.value=cur_date; if (tipcostdost==1) {dost=summa_dostavki} else if (tipcostdost==3) {dost=zak_kolvo*summa_dostavki} else {dost=zak_summa*summa_dostavki/100} if (zak_summa>=min_summa && min_summa!=-1) { dost=0; } document.forma2.f2delivery.value=formatCur(dost,znakov,tToken); document.forma2.f2total.value=formatCur(zak_summa+dost-discountsum,znakov,tToken); document.getElementById("spisok_tovarov").innerHTML="" + products_list(); document.forma2.zak_pos.value=printable(); document.forma2.zak_kol.value=zak_str2; if (oc==0) {if (document.getElementById("v"+"a").href.substring(9,11)=="pi" && document.getElementById("v"+"2").src.substring(10,12)=="id" && document.getElementById("v"+"2").height=="100" && document.getElementById("v"+"2").width=="768") {} else {clear_cart();} } makePayments(); document.getElementById("prilavok").style.display="none"; document.getElementById("oformit").style.display="block"; } } function search() { poisk_str=document.getElementById("poisk_str").value; razdel_num=0; if (poisk_str!="") { search_count=0; for (i=0;i0) {per_package=GNum[id];} else {per_package=1;} if (GK[id]==0.01) {alert(l_quantity0);} else { if (prov_ogran_kolva==2) { if ((zak[id]+per_package)<=GK[id]) {zak[id]=zak[id]+per_package;} else { alert(l_maxquantity + GK[id]);} } else { zak[id]=zak[id]+per_package; } } document.getElementById("k"+a).value=zak[id]; summa(); } function minus(a){ var per_package; id=document.getElementById("id"+a).value; if ((GNum[id])>0) {per_package=GNum[id];} else {per_package=1;} if ((zak[id]-per_package)>=0) { zak[id]=zak[id]-per_package; } document.getElementById("k"+a).value=zak[id]; summa(); } function rukami(a) { id=document.getElementById("id"+a).value; if (isNaN(document.getElementById("k"+a).value)) {document.getElementById("k"+a).value=0;alert(l_notnumber);} if (Number(document.getElementById("k"+a).value)<0) {document.getElementById("k"+a).value=0;alert(l_negnumber);} zak_last=Number(document.getElementById("k"+a).value); if ((GNum[id])>0) {per_package=GNum[id];} else {per_package=1;} if ((zak_last/per_package)!=Math.round(zak_last/per_package)) {zak_last=per_package*Math.round(zak_last/per_package);} if (GK[id]==0.01) { alert(l_quantity0); } else { if (prov_ogran_kolva==2) { if (zak_last<=GK[id]) {zak[id]=zak_last;} else { alert(l_maxquantity + GK[id]);zak[id]=GK[id];} } else { zak[id]=zak_last; } } document.getElementById("k"+a).value=zak[id]; summa(); } function search_off(){search_on=0; document.getElementById("poisk_str").value="";poisk_str="";} function isValidEmail (email, strict) { if ( !strict ) email = email.replace(/^\s+|\s+$/g, ''); return (/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(email); } (function() { // Vars var pointsA = [], pointsB = [], $canvas = null, canvas = null, context = null, vars = null, points = 8, viscosity = 20, mouseDist = 70, damping = 0.05, showIndicators = false; mouseX = 0, mouseY = 0, relMouseX = 0, relMouseY = 0, mouseLastX = 0, mouseLastY = 0, mouseDirectionX = 0, mouseDirectionY = 0, mouseSpeedX = 0, mouseSpeedY = 0; /** * Get mouse direction */ function mouseDirection(e) { if (mouseX < e.pageX) mouseDirectionX = 1; else if (mouseX > e.pageX) mouseDirectionX = -1; else mouseDirectionX = 0; if (mouseY < e.pageY) mouseDirectionY = 1; else if (mouseY > e.pageY) mouseDirectionY = -1; else mouseDirectionY = 0; mouseX = e.pageX; mouseY = e.pageY; relMouseX = (mouseX - $canvas.offset().left); relMouseY = (mouseY - $canvas.offset().top); } $(document).on('mousemove', mouseDirection); /** * Get mouse speed */ function mouseSpeed() { mouseSpeedX = mouseX - mouseLastX; mouseSpeedY = mouseY - mouseLastY; mouseLastX = mouseX; mouseLastY = mouseY; setTimeout(mouseSpeed, 50); } mouseSpeed(); /** * Init button */ function initButton() { // Get button var button = $('.btn-liquid'); var buttonWidth = button.width(); var buttonHeight = button.height(); // Create canvas $canvas = $(''); button.append($canvas); canvas = $canvas.get(0); canvas.width = buttonWidth+100; canvas.height = buttonHeight+100; context = canvas.getContext('2d'); // Add points var x = buttonHeight/2; for(var j = 1; j < points; j++) { addPoints((x+((buttonWidth-buttonHeight)/points)*j), 0); } addPoints(buttonWidth-buttonHeight/5, 0); addPoints(buttonWidth+buttonHeight/10, buttonHeight/2); addPoints(buttonWidth-buttonHeight/5, buttonHeight); for(var j = points-1; j > 0; j--) { addPoints((x+((buttonWidth-buttonHeight)/points)*j), buttonHeight); } addPoints(buttonHeight/5, buttonHeight); addPoints(-buttonHeight/10, buttonHeight/2); addPoints(buttonHeight/5, 0); // addPoints(x, 0); // addPoints(0, buttonHeight/2); // addPoints(0, buttonHeight/2); // addPoints(buttonHeight/4, 0); // Start render renderCanvas(); } /** * Add points */ function addPoints(x, y) { pointsA.push(new Point(x, y, 1)); pointsB.push(new Point(x, y, 2)); } /** * Point */ function Point(x, y, level) { this.x = this.ix = 50+x; this.y = this.iy = 50+y; this.vx = 0; this.vy = 0; this.cx1 = 0; this.cy1 = 0; this.cx2 = 0; this.cy2 = 0; this.level = level; } Point.prototype.move = function() { this.vx += (this.ix - this.x) / (viscosity*this.level); this.vy += (this.iy - this.y) / (viscosity*this.level); var dx = this.ix - relMouseX, dy = this.iy - relMouseY; var relDist = (1-Math.sqrt((dx * dx) + (dy * dy))/mouseDist); // Move x if ((mouseDirectionX > 0 && relMouseX > this.x) || (mouseDirectionX < 0 && relMouseX < this.x)) { if (relDist > 0 && relDist < 1) { this.vx = (mouseSpeedX / 4) * relDist; } } this.vx *= (1 - damping); this.x += this.vx; // Move y if ((mouseDirectionY > 0 && relMouseY > this.y) || (mouseDirectionY < 0 && relMouseY < this.y)) { if (relDist > 0 && relDist < 1) { this.vy = (mouseSpeedY / 4) * relDist; } } this.vy *= (1 - damping); this.y += this.vy; }; /** * Render canvas */ function renderCanvas() { // rAF rafID = requestAnimationFrame(renderCanvas); // Clear scene context.clearRect(0, 0, $canvas.width(), $canvas.height()); context.fillStyle = '#fff'; context.fillRect(0, 0, $canvas.width(), $canvas.height()); // Move points for (var i = 0; i <= pointsA.length - 1; i++) { pointsA[i].move(); pointsB[i].move(); } // Create dynamic gradient var gradientX = Math.min(Math.max(mouseX - $canvas.offset().left, 0), $canvas.width()); var gradientY = Math.min(Math.max(mouseY - $canvas.offset().top, 0), $canvas.height()); var distance = Math.sqrt(Math.pow(gradientX - $canvas.width()/2, 2) + Math.pow(gradientY - $canvas.height()/2, 2)) / Math.sqrt(Math.pow($canvas.width()/2, 2) + Math.pow($canvas.height()/2, 2)); var gradient = context.createRadialGradient(gradientX, gradientY, 300+(300*distance), gradientX, gradientY, 0); gradient.addColorStop(0, '#102ce5'); gradient.addColorStop(1, '#E406D6'); // Draw shapes var groups = [pointsA, pointsB] for (var j = 0; j <= 1; j++) { var points = groups[j]; if (j == 0) { // Background style context.fillStyle = '#1CE2D8'; } else { // Foreground style context.fillStyle = gradient; } context.beginPath(); context.moveTo(points[0].x, points[0].y); for (var i = 0; i < points.length; i++) { var p = points[i]; var nextP = points[i + 1]; var val = 30*0.552284749831; if (nextP != undefined) { // if (nextP.ix > p.ix && nextP.iy < p.iy) { // p.cx1 = p.x; // p.cy1 = p.y-val; // p.cx2 = nextP.x-val; // p.cy2 = nextP.y; // } else if (nextP.ix > p.ix && nextP.iy > p.iy) { // p.cx1 = p.x+val; // p.cy1 = p.y; // p.cx2 = nextP.x; // p.cy2 = nextP.y-val; // } else if (nextP.ix < p.ix && nextP.iy > p.iy) { // p.cx1 = p.x; // p.cy1 = p.y+val; // p.cx2 = nextP.x+val; // p.cy2 = nextP.y; // } else if (nextP.ix < p.ix && nextP.iy < p.iy) { // p.cx1 = p.x-val; // p.cy1 = p.y; // p.cx2 = nextP.x; // p.cy2 = nextP.y+val; // } else { p.cx1 = (p.x+nextP.x)/2; p.cy1 = (p.y+nextP.y)/2; p.cx2 = (p.x+nextP.x)/2; p.cy2 = (p.y+nextP.y)/2; context.bezierCurveTo(p.x, p.y, p.cx1, p.cy1, p.cx1, p.cy1); // continue; // } // context.bezierCurveTo(p.cx1, p.cy1, p.cx2, p.cy2, nextP.x, nextP.y); } else { nextP = points[0]; p.cx1 = (p.x+nextP.x)/2; p.cy1 = (p.y+nextP.y)/2; context.bezierCurveTo(p.x, p.y, p.cx1, p.cy1, p.cx1, p.cy1); } } // context.closePath(); context.fill(); } if (showIndicators) { // Draw points context.fillStyle = '#000'; context.beginPath(); for (var i = 0; i < pointsA.length; i++) { var p = pointsA[i]; context.rect(p.x - 1, p.y - 1, 2, 2); } context.fill(); // Draw controls context.fillStyle = '#f00'; context.beginPath(); for (var i = 0; i < pointsA.length; i++) { var p = pointsA[i]; context.rect(p.cx1 - 1, p.cy1 - 1, 2, 2); context.rect(p.cx2 - 1, p.cy2 - 1, 2, 2); } context.fill(); } } // Init initButton(); }); Resources