function drawStack-mobile(context, value){ //var value = document.getElementById(value).value; var c = document.getElementById(context); var ctx = c.getContext("2d"); ctx.clearRect(0, 0, 300, 300); ctx.beginPath(); // rect: x,y,breite,höhe var x = 0; var y = 0; var height = 5*50; var width = 7.5; var distance = 7.5; var posX = x+10; var posY = 300-y-height-40; ctx.lineWidth = 1; //ctx.rect(posX, posY, width, height); //ctx.fillText(height,posX+width/2-5,posY+height/2+5; // draw six towers à 50 coins each ctx.strokeStyle = "lightgray"; ctx.beginPath(); for(i = 0; i<6;i++){ shift=(width+distance)*i; ctx.rect(10+shift,posY,width, height); } ctx.stroke(); //var residual=0; var amount = [50,1]; var stack = [0,0,0,0] var current_value=value; for(i = 0; i < amount.length; i++){ residual=(current_value%amount[i]); stack[i]=(current_value-residual)/amount[i]; current_value=residual; } // draw actual amount //ctx.strokeStyle = "mediumseagreen"; //ctx.strokeStyle = "crimson"; //ctx.strokeStyle = "orange"; //ctx.strokeStyle = "cornflowerblue"; ctx.strokeStyle = "gray"; ctx.beginPath(); shift=0; /*for(j = 0; j < stack.length-1; j++){ height = amount[j]*5; posY = 300-y-height-20; for(i = 0; i < stack[j]; i++){ ctx.rect(10+shift,posY,width, amount[j]*5); ctx.fillText(amount[j],10+shift+5,290); shift+=(width+5); } } alert(shift);*/ shift=0; height = amount[3]*5; ctx.font = "15px Segoe UI"; for(z = 0; z < stack.length; z++){ stackFull = false; index=0; for(k = 0; k < stack[z]*amount[z]; k++){ if(index >= 50){ shift+=(width+distance); index = 0; } if(k%amount[z]==0 && amount[z]!=1){ ctx.fillText(amount[z], shift+distance-5, 275) } else if (k%(amount[z]*stack[z])==0 && amount[z]==1) { ctx.fillText(amount[z]*stack[z], shift+distance-5, 275) } height = 5; posY = 300-y-height-40; ctx.rect(shift+10,posY-(index)*5,width, 5); index+=1; } shift+=(width+distance); //ctx.fillText(amount[z],10+shift+10,290); } var total = 0; for(p = 0; p< amount.length; p++){ total+=stack[p]*amount[p]; } ctx.stroke(); ctx.font = "bold 15px Segoe UI"; ctx.fillText(total+" ECU", 65,295); ctx.stroke(); } //ctx.fillText(height,posX+width/2-6,300);