Vlookup mapping in javascript - javascript

I made is using Vlookup in Excel, Now I have do the same a webpage.
<div class="age">
<label for="age" class="age"> Please Enter your age : </label>
<input type="text" id="age" name="age" onkeypress='return isNumberKey(event)'>
</div>
<div class="bmi">
<label for="bmi" class="bmi">Please enter your Body Mass Index value : </label>
<input type="text" id="bmi" name="bmi" onkeypress='return isNumberKey(event)'>
</div>
<div class="afc">
<label for="afc" class="afc">Please enter your antral follicle count (afc) value : </label>
<input type="text" id="afc" name="afc" onkeypress='return isNumberKey(event)'>
</div>
<div class="amh">
<label for="amh" class="amh">Please Enter your Anti-Müllerian hormone (amh) level : </label>
<input type="text" id="amh" name="amh" onkeypress='return isNumberKey(event)'>
</div>
There are 6 arrays
var values = [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];
var age = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
var bmi = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
I have these spans where user can get the result after performing some internal calculations.
<div>
Final Score: <span id="result"> </span>
Percentage: <span id="percentage"> </span>
result: <span id="result"> </span>
</div>
For each input of the values of different fields, the input value should me mapped to the corresponding value from the array
for example. If the age input is 45, The value of 45th index of age array should be returned
I have attached the excel file for reference: Reference Excel
How should I go about it. looked up lot of examples, but none of them deal in multiple arrays/inputs from users.

It would be great if you could explain what exactly is the issue without requiring us to analyze your excel.
To return the n-th element from an array you can simply do array[n]
To find index of an element with value X you can call array.indexOf(X)

Related

Is there a way to convert mp4/wav files to a byte array in nativescript?

Working on trying to write mp4 and wav files to byte arrays, so that I am able to share them with other apps. Would appreciate any help. Thanks
If I assume if you're using python then its same as reading text_file or video_file.
Let's assume if your filename is test.ts then you can use below function.
def get_bytes_from_file(filename):
return open(filename, "rb").read()
get_bytes_from_file("test.ts")
You can also use scipy inbuild function scipy.io.wavfile.read and/or scipy.io.wavfile.write.Refer this.
If you have decimal value that you would like to convert to binary you can use the following:
In [3]: import numpy as np
...:
...: def bitfield(n):
...: """Convert integer into bitfield (as list)
...: From StackOverflow: http://stackoverflow.com/a/10322018/
...: """
...: return [int(digit) for digit in bin(n)[2:]]
...:
In [4]: p = 0x91
...: p = np.array(bitfield(p))
In [5]: p
Out[5]: array([1, 0, 0, 1, 0, 0, 0, 1])
If you want to convert string message to binary you can use this:
In [1]: import numpy as np
import codecs
In[2]: s = '44.6488N,63.5752W,20.5,2.25,125.6,11.5,6.8,T10.5,271.4,35.5,44.6491N,63.5755W'.encode('utf-8')
In[4]: s.hex()
Out[4]: '34342e363438384e2c36332e35373532572c32302e352c322e32352c3132352e362c31312e352c362e382c5431302e352c3237312e342c33352e352c34342e363439314e2c36332e3537353557'
In[10]: print(codecs.decode("34342e363438384e2c36332e35373532572c32302e352c322e32352c3132352e362c31312e352c362e382c5431302e352c3237312e342c33352e352c34342e363439314e2c36332e3537353557", "hex").decode('utf-8'))
Out[10]: 44.6488N,63.5752W,20.5,2.25,125.6,11.5,6.8,T10.5,271.4,35.5,44.6491N,63.5755W
In[11]: hex_string = "34342e363438384e2c36332e35373532572c32302e352c322e32352c3132352e362c31312e352c362e382c5431302e352c3237312e342c33352e352c34342e363439314e2c36332e3537353557"
for i in range(len(hex_string)//2):
print('{0}'.format(hex_string[i*2:i*2+2]), end=":")
Out[11]: 34:34:2e:36:34:38:38:4e:2c:36:33:2e:35:37:35:32:57:2c:32:30:2e:35:2c:32:2e:32:35:2c:31:32:35:2e:36:2c:31:31:2e:35:2c:36:2e:38:2c:54:31:30:2e:35:2c:32:37:31:2e:34:2c:33:35:2e:35:2c:34:34:2e:36:34:39:31:4e:2c:36:33:2e:35:37:35:35:57:
In[12]: p = '34342e363438384e2c36332e35373532572c32302e352c322e32352c3132352e362c31312e352c362e382c5431302e352c3237312e342c33352e352c34342e363439314e2c36332e3537353557'
p = int(p, 16)
p = np.array(bitfield(p))
p
Out[12] : array([1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0,
0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0,
0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0,
1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0,
1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1,
0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1,
1, 1, 0, 0, 1, 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, 0, 1, 1, 0, 1,
0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1,
0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0,
1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0,
0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1,
1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1,
0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1])

Canvas game slows down after a while. What could have caused this?

I'm making a breakout game with html canvas and javascript. I'm working on this project for a while.
Yesterday i realized that game started the slow down after hours of playing. I checked my code but everything was fine. Then i restarted chrome and the game back to normal. What could have caused this?
Is chrome collecting objects or something on the background and it gets heavy after hours? is that a thing?
Here is the all the js code:
document.addEventListener("DOMContentLoaded", function(){
canvas = document.getElementById("ctx").getContext("2d");
document.addEventListener("keydown", keyDown, false);
document.addEventListener("keyup", keyUp, false);
document.querySelector("#newGame").addEventListener("click", newGame, false);
document.querySelector("#pickLevel").addEventListener("click", pickLevel, false);
document.querySelector("#restart").addEventListener("click", restart, false);
document.querySelector("#toMainMenu").addEventListener("click", mainMenu, false);
levels = {
map01 : [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 10, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 13, 15, 17, 10, 1, 0, 0, 0, 0, 0,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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
};
let map_col = 14;
let map_row = 34;
let secondPassed = 0;
let oldTimeStamp = 0;
let WIDTH = canvas.canvas.width;
let HEIGHT = canvas.canvas.height;
let right_arrow_keycode = 39;
let left_arrow_keycode = 37;
let a_keycode = 65;
let d_keycode = 68;
let pressLeft;
let pressRight;
let game_over;
let islevelUp;
let dt = 1/60.0;
let brickList;
let tilesets = {
tileset1: {
image: new Image(),
columns: 7,
rows: 3,
tile_width: 32,
tile_height: 16
}
};
tilesets.tileset1.image.src = "img/tileset/brick_tileset.png";
let heart_sprite_sheet = {
spin: {
frame_set : [0,1,2,3],
image : new Image()
}
}
heart_sprite_sheet.spin.image.src = "img/heart/heart_sprite.png";
let delay = 0;
let frame_set;
let level;
function newGame(){
document.querySelector(".mainMenu").style.display="none";
level = 0;
score = 0;
levelUp();
}
function restart(){
document.querySelector(".gameOver").style.display="none";
level -= 1;
levelUp();
}
function mainMenu(){
document.querySelector(".gameOver").style.display="none";
document.querySelector(".mainMenu").style.display="block";
}
function pickLevel(){
score = 0;
document.querySelector(".pickLevel").style.display="block";
document.querySelector(".mainMenu").style.display="none";
}
function loop(timeStamp){
getDeltaTime(timeStamp);
ballCollision();
ballMovement();
paddleMovement();
heartMovement();
heartAnimUpdate();
// document.getElementById("output").innerHTML = "gameover: " + game_over + ", islevelup: " + islevelUp;
draw();
if(!game_over && !islevelUp){
window.requestAnimationFrame(loop);
}
else if(game_over){
gameOver();
}
else if(islevelUp){
levelUp();
}
}
function Animation(){
this.count = 0
this.delay = delay;
this.frame = 0;
this.frame_index = 0;
this.frame_set = frame_set;
}
Animation.prototype.change = function(frame_set, delay){
if(this.frame_set != frame_set){
this.count = 0;
this.delay = delay;
this.frame_index = 0;
this.frame_set = frame_set;
this.frame = this.frame_set[this.frame_index];
}
}
Animation.prototype.update = function(){
this.count ++;
if(this.count >= this.delay){
this.count = 0;
this.frame_index =(this.frame_index == this.frame_set.length -1)?0: this.frame_index + 1;
this.frame = this.frame_set[this.frame_index];
}
}
function Ball(){
this.image = new Image(),
this.x = 250,
this.y = 450,
this.velocity = 150,
this.radius = 8,
this.dx = 1,
this.dy = -1
}
function ballReset(){
ball.x = paddle.x + paddle.width/2;
ball.y = 450;
ball.dx = 1;
ball.dy = -1;
ball.velocity = 150;
}
function drawBall(){
canvas.drawImage(ball.image, Math.floor(ball.x), Math.floor(ball.y), ball.radius*2, ball.radius*2);
}
function ballMovement(){
ball.x += (ball.velocity * deltaTime ) * ball.dx * 0.999;
ball.y += (ball.velocity * deltaTime ) * ball.dy * 0.999;
}
function ballCollision(){
//borders for ball
if(ball.y - ball.radius <= 0 && ball.y < 0){
ball.dy = ball.dy * -1;
ball.y = ball.radius;
}
if(ball.y > HEIGHT){
heartList.pop();
if(heartList.length == 0){
game_over = true;
}else{
ballReset();
}
}
if(ball.x + ball.radius > WIDTH && ball.x > 0){
ball.dx = ball.dx * -1;
ball.x = WIDTH-ball.radius;
}
if(ball.x - ball.radius < 0 && ball.x < 0){
ball.dx = ball.dx * -1;
ball.x = ball.radius;
}
// ball and paddle collision detection
let testX = ball.x;
let testY = ball.y;
if(ball.x < paddle.x){
testX = paddle.x;
//left
}
else if(ball.x > paddle.x+paddle.width){
testX = paddle.x + paddle.width;
//right
}
if(ball.y < paddle.y){
testY = paddle.y;
//top
}
else if(ball.y > paddle.y+ paddle.height){
testY = paddle.y + paddle.height;
//bottom
}
let distX = ball.x - testX;
let distY = ball.y - testY;
let distance = Math.sqrt((distX*distX)+(distY*distY));
if(distance <= ball.radius){
let collidePoint = ball.x - (paddle.x + paddle.width/2);
collidePoint = collidePoint / (paddle.width/2);
let angle = collidePoint * Math.atan2(ball.y, ball.x);
ball.dx = ball.velocity * deltaTime * Math.sin(angle);
ball.dy = -ball.velocity * deltaTime * Math.cos(angle);
}
//brick collision
for (let i = 0; i < brickList.length; i++){
let b = brickList[i];
if(b.status){
let bottom = false;
let top = false;
let b_testX = ball.x;
let b_testY = ball.y;
if(ball.x < b.x){
b_testX = b.x;
}
else if(ball.x > b.x + b.width){
b_testX = b.x + b.width;
}
if(ball.y < b.y){
b_testY = b.y;
top = true;
}
else if(ball.y > b.y + b.height){
b_testY = b.y + b.height;
bottom = true;
}
let distX_fromBrick = ball.x - b_testX;
let distY_fromBrick = ball.y - b_testY;
let distance = Math.sqrt((distX_fromBrick * distX_fromBrick) + (distY_fromBrick * distY_fromBrick));
if(distance < ball.radius){
let collidePoint = ball.x - (b.x + b.width/2);
collidePoint = collidePoint / (b.width/2);
let angle = collidePoint * Math.atan2(ball.y, ball.x);
if(top){
ball.dx = ball.velocity * deltaTime * Math.sin(angle);
ball.dy = -ball.velocity * deltaTime * Math.cos(angle);
}
if(bottom){
ball.dx = -ball.velocity * deltaTime * Math.sin(angle);
ball.dy = ball.velocity * deltaTime * Math.cos(angle);
}
b.status = false;
brokenBricks ++;
scoreUp();
if(brokenBricks == brickList.length){
islevelUp = true;
}
}
}
}
}
function Paddle(){
this.image = new Image(),
this.x = 200,
this.y = 490,
this.width = 64,
this.height = 20,
this.velocity = 500
}
function drawPaddle(){
canvas.drawImage(paddle.image, Math.floor(paddle.x), Math.floor(paddle.y),paddle.width,paddle.height);
}
function paddleMovement(){
if(pressRight&&paddle.x+paddle.width<WIDTH){
paddle.x += (paddle.velocity * deltaTime )*0.999;
}
if(pressLeft&&paddle.x>0){
paddle.x -= (paddle.velocity * deltaTime )*0.999;
}
}
function Brick(x,y){
this.image = new Image(),
this.x = x,
this.y = y,
this.width = 32,
this.height = 16,
this.status = true
}
function drawMap (){
for(let i = 0; i < map.length; i++){
let value = map[i]-1;
let source_x = (value%tilesets.tileset1.columns) * tilesets.tileset1.tile_width;
let source_y = Math.floor(value/tilesets.tileset1.columns) * tilesets.tileset1.tile_height;
let destination_x = (i%map_col) * tilesets.tileset1.tile_width;
let destination_y = Math.floor(i/map_col) * tilesets.tileset1.tile_height;
if(map[i] != 0){
if(!isBrickAlive(destination_x, destination_y)){continue;}
}
canvas.drawImage(tilesets.tileset1.image, source_x, source_y, tilesets.tileset1.tile_width, tilesets.tileset1.tile_height, destination_x, destination_y, tilesets.tileset1.tile_width, tilesets.tileset1.tile_height );
}
}
function createBrick(){
for(let i = 0; i<map.length; i++){
if(map[i] != 0){
let x = (i%map_col)*tilesets.tileset1.tile_width;
let y = Math.floor(i/map_col)*tilesets.tileset1.tile_height;
let brick = new Brick(x, y);
brickList.push(brick);
}
}
}
function isBrickAlive(x,y){
for(let i = 0; i < brickList.length; i++){
let brick = brickList[i];
if(brick.status && brick.x == x && brick.y == y){
return true;
}
}
}
function scoreUp(){
score += 1;
}
function scoreText(){
canvas.font = `15px gameFont`;
canvas.fillStyle = "white";
canvas.fillText("SCORE:"+ score, 8, 30);
}
function Heart(x,y){
this.image = new Image(),
this.animation = new Animation(),
this.x = x,
this.y = y,
this.width = 7,
this.height = 7
}
function heartCreate(){
let heart1 = new Heart(350,8);
heartList.push(heart1);
let heart2 = new Heart(375,8);
heartList.push(heart2);
let heart3 = new Heart(400,8);
heartList.push(heart3);
let heart4 = new Heart(425,8);
heartList.push(heart4);
}
function heartDraw(){
for(let i = 0; i < heartList.length; i++){
let heart = heartList[i];
canvas.drawImage(heart_sprite_sheet.spin.image, heart.width * heart.animation.frame, 0, heart.width, heart.height, heart.x, heart.y, heart.width*3, heart.height*3);
}
}
function heartMovement(){
for(let i = 0; i < heartList.length; i++){
let heart = heartList[i];
heart.image = heart_sprite_sheet.spin.image;
heart.animation.change(heart_sprite_sheet.spin.frame_set, 12);
}
}
function heartAnimUpdate(){
for(let i = 0; i < heartList.length; i++){
let heart = heartList[i];
heart.animation.update();
}
}
function draw(){
canvas.clearRect(0,0,WIDTH,HEIGHT);
canvas.imageSmoothingEnabled = false;
canvas.save();
drawBg();
drawMap();
drawPaddle();
scoreText();
heartDraw();
drawBall();
canvas.restore();
}
function keyDown(event){
if(event.keyCode === right_arrow_keycode || event.keyCode === d_keycode){
pressRight = true;
}
if(event.keyCode === left_arrow_keycode || event.keyCode === a_keycode){
pressLeft = true;
}
}
function keyUp(event){
if(event.keyCode === right_arrow_keycode || event.keyCode === d_keycode){
pressRight = false;
}
if(event.keyCode === left_arrow_keycode || event.keyCode === a_keycode){
pressLeft = false;
}
}
function drawBg(){
switch(level){
case 1:
canvas.beginPath();
canvas.fillStyle = "#76428A";
canvas.fillRect(0,0,WIDTH,HEIGHT);
canvas.closePath();
break;
case 2:
canvas.beginPath();
canvas.fillStyle = "#8C2929";
canvas.fillRect(0,0,WIDTH,HEIGHT);
canvas.closePath();
break;
case 3:
canvas.beginPath();
canvas.fillStyle = "#639BFF";
canvas.fillRect(0,0,WIDTH,HEIGHT);
canvas.closePath();
break;
case 4:
canvas.beginPath();
canvas.fillStyle = "#4B692F";
canvas.fillRect(0,0,WIDTH,HEIGHT);
canvas.closePath();
break;
case 5:
canvas.beginPath();
canvas.fillStyle = "#9BADB7";
canvas.fillRect(0,0,WIDTH,HEIGHT);
canvas.closePath();
break;
case 6:
canvas.beginPath();
canvas.fillStyle = "#D95763";
canvas.fillRect(0,0,WIDTH,HEIGHT);
canvas.closePath();
break;
case 7:
canvas.beginPath();
canvas.fillStyle = "#3F3F74";
canvas.fillRect(0,0,WIDTH,HEIGHT);
canvas.closePath();
break;
case 8:
canvas.beginPath();
canvas.fillStyle = "#663931";
canvas.fillRect(0,0,WIDTH,HEIGHT);
canvas.closePath();
break;
case 9:
canvas.beginPath();
canvas.fillStyle = "#DF7126";
canvas.fillRect(0,0,WIDTH,HEIGHT);
canvas.closePath();
break;
default:
canvas.beginPath();
canvas.fillStyle = "#639BFF";
canvas.fillRect(0,0,WIDTH,HEIGHT);
canvas.closePath();
break;
}
//açık mavi: 639BFF
//mor: 76428A
//yeşil: 4B692F
//pembe: D77BBA
//turuncu: DF7126
//koyu mavi: 3F3F74
//pembe-kırmızı: D95763
//koyu mor: 45283C
//baby-blue: 9BADB7
//mavi: 5B6EE1
//koyu kırmızı: 8C2929
}
function getDeltaTime(timeStamp){
secondPassed = (timeStamp - oldTimeStamp) / 1000;
oldTimeStamp = timeStamp;
deltaTime = Math.min(secondPassed , dt);
return deltaTime;
}
function startGame(){
secondPassed = 0;
oldTimeStamp = 0;
brokenBricks = 0;
game_over = false;
pressLeft = false;
pressRight = false;
islevelUp = false;
brickList = new Array();
heartList = new Array();
createBrick();
heartCreate();
draw();
startEngine();
}
function startEngine(){
window.requestAnimationFrame(loop);
}
function gameOver(){
document.querySelector(".gameOver").style.display="block";
document.getElementById("score").innerHTML = score;
score = 0;
}
function levelUp(){
ball = new Ball();
paddle = new Paddle();
level++;
switch(level){
case 1:
map = levels.map01;
ball.image.src = "img/ball/blue_ball.png";
paddle.image.src = "img/paddle/black_paddle.png";
break;
case 2:
map = levels.map02;
ball.image.src = "img/ball/green_ball.png";
paddle.image.src = "img/paddle/blue_paddle.png";
break;
case 3:
map = levels.map03;
ball.image.src = "img/ball/purple_ball.png";
paddle.image.src = "img/paddle/brown_paddle.png";
break;
case 4:
map = levels.map04;
ball.image.src = "img/ball/red_ball.png";
paddle.image.src = "img/paddle/golden_paddle.png";
break;
case 5:
map = levels.map05;
ball.image.src = "img/ball/yellow_ball.png";
paddle.image.src = "img/paddle/green_paddle.png";
break;
case 6:
map = levels.map06;
ball.image.src = "img/ball/blue_ball.png";
paddle.image.src = "img/paddle/purple_paddle.png";
break;
case 7:
map = levels.map07;
ball.image.src = "img/ball/red_ball.png";
paddle.image.src = "img/paddle/red_paddle.png";
break;
case 8:
map = levels.map08;
ball.image.src = "img/ball/yellow_ball.png";
paddle.image.src = "img/paddle/black_paddle.png";
break;
case 9:
map = levels.map09;
ball.image.src = "img/ball/purple_ball.png";
paddle.image.src = "img/paddle/blue_paddle.png";
break;
default:
game_over = true;
break;
}
startGame();
}});

Second series not displaying in Highcharts

I am trying to create a graph to display performance of a system. My issue is that Higcharts, for some reason, won't recognize that I have more than one series. The first series displays perfectly, however the second is no where to be seen.
I am using Django 1.8 to loop the data from dictionaries.
My series code:
series: [
{% for ID, run in attDict.items|sort %}
{
yAxis: 0,
id: "Run" + {{forloop.counter}},
name: "RunID " + {{ID}},
color: getLineColor({{ID}}),
data: {{run}},
marker: {
fillColor: getFillColor({{forloop.counter}}),
},
visible: false
},
{% endfor %}
{% for key, task in TaskE.items|sort %}
{
yAxis: 1,
id: "during",
linkedTo: "Run" + {{forloop.counter}},
name: "Duringtask for run " + {{key}}
type: 'area',
color: '#12e000',
fillOpacity: 0.3,
data: {{task}},
visible: fasle
}{% if forloop.last %}{% else %},{% endif %}
{% endfor %}
]
The output look like this:
series: [
{
yAxis: 0,
id: "Run" + 1,
name: "RunID " + 250,
color: getLineColor(250),
data: [0, 0, 0, 0, 0, 0, 6, 33, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
marker: {
fillColor: getFillColor(1),
},
visible: false
},
{
yAxis: 0,
id: "Run" + 2,
name: "RunID " + 256,
color: getLineColor(256),
data: [0, 0, 0, 1, 0, 0, 0, 0],
marker: {
fillColor: getFillColor(2),
},
visible: false
},
{
yAxis: 0,
id: "Run" + 3,
name: "RunID " + 257,
color: getLineColor(257),
data: [0, 0, 0, 1, 0, 0, 0, 0],
marker: {
fillColor: getFillColor(3),
},
visible: false
},
{
yAxis: 0,
id: "Run" + 4,
name: "RunID " + 265,
color: getLineColor(265),
data: [83, 0, 101, 0, 0, 96, 0],
marker: {
fillColor: getFillColor(4),
},
visible: false
},
{
yAxis: 0,
id: "Run" + 5,
name: "RunID " + 295,
color: getLineColor(295),
data: [14, 3, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 70, 0, 0, 0, 37, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 52, 0, 0, 0, 0, 0, 0, 0, 45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 77, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 67, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 88, 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 3, 0, 58, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0],
marker: {
fillColor: getFillColor(5),
},
visible: false
},
{
yAxis: 0,
id: "Run" + 6,
name: "RunID " + 296,
color: getLineColor(296),
data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 116, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 0, 0, 1, 0, 0, 0, 0, 28, 15],
marker: {
fillColor: getFillColor(6),
},
visible: false
},
]
You are explicitly telling the chart not to show the series in the legend by using this:
linkedTo: "Run" + {{forloop.counter}}
When two series are linked, only the first one appears in the legend.
Toggling the visibility of this also toggles the linked series.
Reference:
http://api.highcharts.com/highcharts/plotOptions.series.linkedTo
Remove the linkedTo property from the second loop, and it should work fine.

Convert byte array to signed int64 in javascript

I know that there is no int64 data type in js. But i need to convert a byte array into a signed int64 to get same result comparing to BitConverter.ToInt64() method in .NET class library. There is an implementations of big integers in javascript (BigInt.js) which accept hex as input and gets a bigInt as output but result is not same as BitConverter.ToInt64() in BCL.
Example:
BitConverter.ToInt64() for '0x40e00a35661f92a2' will result in -6732283969128439744
I need a solution for doing this in java script, performance is not issue.
edit:
feed data in normal order into BigInt.js:
javascript: new BigInt('0x40e00a35661f92a2')// shows 4674747637673464482
feed data in reverse order into BigInt.js:
javascript: new BigInt('0xa2921f66350ae040')// shows 11714460104581111872
which neither matches the BitConverter.ToInt64() result:
C SHARP: BitConverter.ToInt64(new byte[] { 0x40, 0xe0, 0x0a, 0x35, 0x66, 0x1f, 0x92, 0xa2 }, 0); // shows -6732283969128439744
There is an implementation for converting hex string to Int64 (both signed and unsigned) here: LINK
That code returns right result:
javascript: new HexStringToInt64StringConverter(true).convert('a2921f66350ae040') // will return -6732283969128439744 same as BitConverter.ToInt64() in BCL
The functions from the link:
function HexStringToInt64StringConverter(signed) {
var hexCode = {
'0':"0000",
'1':"0001",
'2':"0010",
'3':"0011",
'4':"0100",
'5':"0101",
'6':"0110",
'7':"0111",
'8':"1000",
'9':"1001",
'a':"1010",
'b':"1011",
'c':"1100",
'd':"1101",
'e':"1110",
'f':"1111"
};
var preComputedLongMath = {
"20":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,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 5, 1, 6, 1, 6],
"265":[3, 6, 8, 9, 3, 4, 8, 8, 1, 4, 7, 4, 1, 9, 1, 0, 3, 2, 3, 2]
};
if (typeof(signed) != 'boolean') signed = false;
function toBinary(hex) {
hex = hex.toLowerCase();
var binary = "";
for (var i = 0; i < hex.length; i++) {
binary += hexCode[hex[i]];
}
return binary;
}
function to1nsComplement(binary) {
var compliment = "";
for (var i = 0; i < binary.length; i++) {
compliment += (binary.charAt(i) == "1" ? "0" : "1");
}
return compliment;
}
function arrayAdd(a, b) {
var carry = 0;
var number = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
for (var i = 19; i >= 0; i--) {
number[i] = a[i] + b[i] + carry;
if (number[i].toString().length > 1) {
carry = parseInt(number[i].toString().substring(0, number[i].toString().length - 1), 10);
number[i] = parseInt(number[i].toString().substring(number[i].toString().length - 1), 10)
} else {
carry = 0;
}
}
return number;
}
function removeZeroPad(number) {
var lock = false;
var output = [];
for (var i = 0; i < number.length; i++) {
if (lock) {
output.push(number[i]);
} else {
if (number[i] != 0) {
lock = true;
output.push(number[i]);
}
}
}
return output;
}
function binaryToDec(binary) {
var negative = false;
if (signed && (binary.charAt(0) == 1)) {
negative = true;
}
if (signed) {
binary = binary.substring(1);
if (negative) {
binary = to1nsComplement(binary);
}
}
var pos = 0;
var number = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
for (var i = binary.length - 1; i >= 0; i--) {
if (binary.charAt(i) == 1) {
number = arrayAdd(number, preComputedLongMath["2" + pos])
}
pos++;
}
if (negative) {
number = removeZeroPad(arrayAdd(number, preComputedLongMath["20"]));
number.splice(0, 0, "-");
} else {
number = removeZeroPad(number);
}
return number.join("");
}
this.convert = function (hex) {
var binary = toBinary(hex);
return binaryToDec(binary);
};
}

Phaser, Tileset and Tilemap transparency

I use Tiled to make a map. However when rendering the map in Phaser the transparency doesn't seem to work.
It works as expected in Tiled:
Unfortunately not when rendered with Phaser:
main.js:
var game = new Phaser.Game(320, 320, Phaser.AUTO, 'mquest', { preload: preload, create: create });
function preload() {
game.load.tilemap('test', 'assets/js/maps/test.json', null, Phaser.Tilemap.TILED_JSON);
game.load.image('forest_tiles', 'assets/img/forest_tiles.png');
}
function create() {
game.stage.backgroundColor = '#787878';
map = game.add.tilemap('test');
map.addTilesetImage('Forest', 'forest_tiles');
backgroundLayer = map.createLayer('Background');
foregroundLayer = map.createLayer('Foreground');
topLayer = map.createLayer('Top');
backgroundLayer.resizeWorld();
}
And the test.json:
{ "height":20,
"layers":[
{
"data":[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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
"width":20,
"x":0,
"y":0
}],
"orientation":"orthogonal",
"properties":
{
},
"renderorder":"right-down",
"tileheight":16,
"tilesets":[
{
"firstgid":1,
"image":"..\/..\/img\/forest_tiles.png",
"imageheight":160,
"imagewidth":240,
"margin":0,
"name":"Forest",
"properties":
{
},
"spacing":0,
"tileheight":16,
"tilewidth":16,
"transparentcolor":"#ffffff"
}],
"tilewidth":16,
"version":1,
"width":20
}
I thought the engine handled the transparency if a transparentcolor property was set as it was through Tiled, but apparently not.
The problem was solved when just transparent the white color through a software like Photoshop or Gimp.

Categories

Resources