Saturday, April 22, 2017

Algo Code Ep 6 - Upgrades

Dear readers, I have a new function to add.

It is checkversion(version number) .

It can check if the version number of Algo Code that someone is using is the version required or a later version.

*Although version are written as V a.b.c , you do not need to write V (abbreviation for version). And, you must write it as a.bc    .

For Version 1.0.0,
_________________________________________________________________________________
//color
cngCol=function(c_c) {
ctx.fillStyle=c_c;
}

//fill
text=function(wor_dr,x_y,y_x) {
ctx.fillText(wor_dr,x_y,y_x);
}
rect=function(x_x,y_y,w_j,h_j) {
ctx.fillRect(x_x,y_y,w_j,h_j);
}

//clear
cnvscls=function() {
ctx.clearRect(0,0,WIDTH,HEIGHT);
}

//time
wait=function(w_w) {

var v_v=w_w*25;
a_exist=true;

if(t_t<v_v && a_exist==true) {
b_exist=true;
}
if(t_t==v_v) {
a_exist=false;
b_exist=false;
n_n+=1;
t_t=0;
}

}

//console
conssay=function(w_v) {
console.log(w_v);
}

conscls=function() {
console.clear();
}

/*
document.onmousedown=function(mouse) {
if(mouseX>0 && mouseX<WIDTH && mouseY<0 && mouseY<HEIGHT) {
mouseisPressed=true;
}
}
*/
//rpt
vard=function() {
/*
var mouseX=mouse.clientX-0;
var mouseY=mouse.clientY-8;
*/
//time
if(b_exist==true) {
t_t+=1;
}
}

setInterval(vard,15);

//keyboard
document.onkeydown=function(event) {
//www.cambriaresearch.com/articles/15/javascript-char-codes-key-codes
    if(event.keyCode === 39)
        pressingRight = true;

    else if(event.keyCode === 37)
        pressingLeft = true;

    else if(event.keyCode === 38)
        pressingUp = true;

    else if(event.keyCode === 40)
        pressingDown = true;

    else if(event.keyCode === 65)
        pressingA = true;

    else if(event.keyCode === 66)
        pressingB = true;

    else if(event.keyCode === 67)
        pressingC = true;
}

document.onkeyup=function(event) {
//www.cambriaresearch.com/articles/15/javascript-char-codes-key-codes
    if(event.keyCode === 39)
        pressingRight = false;

    else if(event.keyCode === 37)
        pressingLeft = false;

    else if(event.keyCode === 38)
        pressingUp = false;

    else if(event.keyCode === 40)
        pressingDown = false;

    else if(event.keyCode === 65)
        pressingA = false;

    else if(event.keyCode === 66)
        pressingB = false;

    else if(event.keyCode === 67)
        pressingC = false;
}

checkversion=function(versionmon) {
if(version_num<versionmon) {
console.log('I am sorry. You need V '+version_num+' to run this program.');
}
}
_________________________________________________________________________________

This is fcnt.js.

For vbl.js,
_________________________________________________________________________________
//canvas
var WIDTH=360;
var HEIGHT=360;
var version_num=1.00;

//mouse
/*
var mouseX=mouse.clientX-0;
var mouseY=mouse.clientY-8;
var mouseisPressed=false;
*/

//keyboard
var pressingUp=false;
var pressingDown=false;
var pressingLeft=false;
var pressingRight=false;
var pressingA=false;
var pressingB=false;
var pressingC=false;

//time
var a_exist=false;
var b_exist=false;
var n_n=0;
var t_t=0;
_________________________________________________________________________________


For Version 1.0.1 users,

For fcnt.js :
_________________________________________________________________________________
/*
//logic gates
and=function(a_c,b_c) {
if(a_c=='0' && b_c=='0') {
and_R='0';
}
if(a_c=='0' && b_c=='1') {
and_R='0';
}
if(a_c=='1' && b_c=='0') {
and_R='0';
}
if(a_c=='1' && b_c=='1') {
and_R='1';
}
}
or=function(a_d,b_d) {
if(a_d=='0' && b_d=='0') {
or_R='0';
}
if(a_d=='0' && b_d=='1') {
or_R='1';
}
if(a_d=='1' && b_d=='0') {
or_R='1';
}
if(a_d=='1' && b_d=='1') {
or_R='1';
}
}
xor=function(a_e,b_e) {
if(a_e=='0' && b_e=='0') {
xor_R='0';
}
if(a_e=='0' && b_e=='1') {
xor_R='1';
}
if(a_e=='1' && b_e=='0') {
xor_R='1';
}
if(a_e=='1' && b_e=='1') {
xor_R='0';
}
}
*/
//settings
cngCol=function(c_c) {
ctx.fillStyle=c_c;
}
cngSpd=function(bdde) {
FFEspd=bdde;
}
cngFont=function(size,font) {
ctx.font=size+'px '+font;
}
checkversion=function(versionmon) {
if(version_num<versionmon) {
console.log('I am sorry. You need V '+version_num+' to run this program.');
}
}

//fill
text=function(wor_dr,x_y,y_x) {
ctx.fillText(wor_dr,x_y,y_x+30);
}
rect=function(x_x,y_y,w_j,h_j) {
ctx.fillRect(x_x,y_y,w_j,h_j);
}
ellipse=function(x_b,y_b,w_b,h_b) {
  ctx.beginPath();
  ctx.moveTo(x_b,y_b-h_b/2); // A
  ctx.bezierCurveTo(
    x_b+w_b/2,y_b-h_b/2, // C1
    x_b+w_b/2,y_b+h_b/2, // C2
    x_b,y_b+h_b/2); // A2

  ctx.bezierCurveTo(
    x_b-w_b/2,y_b+h_b/2, // C3
    x_b-w_b/2,y_b-h_b/2, // C4
    x_b,y_b-h_b/2); // A1

  ctx.fill();
  ctx.closePath();
}
line=function(xa,ya,xb,yb) {
ctx.beginPath();
ctx.moveTo(xa,ya);
ctx.lineTo(xb,yb);
ctx.stroke();
}
triangle=function(xa,ya,xb,yb,xc,yc) {
ctx.beginPath();
ctx.moveTo(xa,ya);
ctx.lineTo(xb,yb);
ctx.moveTo(xb,yb);
ctx.lineTo(xc,yc);
ctx.moveTo(xc,yc);
ctx.lineTo(xa,ya);
ctx.stroke();
ctx.fill();
ctx.closePath();
}
quad=function(xa,ya,xb,yb,xc,yc,xd,yd) {
ctx.beginPath();
ctx.moveTo(xa,ya);
ctx.lineTo(xb,yb);
ctx.moveTo(xb,yb);
ctx.lineTo(xc,yc);
ctx.moveTo(xc,yc);
ctx.lineTo(xd,yd);
ctx.moveTo(xd,yd);
ctx.lineTo(xa,ya);
ctx.stroke();
ctx.fill();
ctx.closePath();
}

//clear
cnvscls=function() {
ctx.clearRect(0,0,WIDTH,HEIGHT);
}

//time
wait=function(w_w) {

var v_v=w_w*25;
a_exist=true;

if(t_t<v_v && a_exist==true) {
b_exist=true;
}
if(t_t==v_v) {
a_exist=false;
b_exist=false;
n_n+=1;
t_t=0;
}

}

//console
conssay=function(w_v) {
console.log(w_v);
}

conscls=function() {
console.clear();
}

/*
document.onmousedown=function(mouse) {
if(mouseX>0 && mouseX<WIDTH && mouseY<0 && mouseY<HEIGHT) {
mouseisPressed=true;
}
}
*/
//rpt
vard=function() {
/*
var mouseX=mouse.clientX-0;
var mouseY=mouse.clientY-8;
*/
//time
if(b_exist==true) {
t_t+=1;
}
}

setInterval(vard,15);

//keyboard
document.onkeydown=function(event) {
//www.cambriaresearch.com/articles/15/javascript-char-codes-key-codes
    if(event.keyCode === 39)
        pressingRight = true;

    else if(event.keyCode === 37)
        pressingLeft = true;

    else if(event.keyCode === 38)
        pressingUp = true;

    else if(event.keyCode === 40)
        pressingDown = true;

    else if(event.keyCode === 65)
        pressingA = true;

    else if(event.keyCode === 66)
        pressingB = true;

    else if(event.keyCode === 67)
        pressingC = true;

    else if(event.keyCode === 90)
        pressingZ= true;

    else if(event.keyCode === 83)
        pressingS = true;

    else if(event.keyCode === 88)
        pressingX = true;

    else if(event.keyCode === 13)
        pressingEnter = true;
}

document.onkeyup=function(event) {
//www.cambriaresearch.com/articles/15/javascript-char-codes-key-codes
    if(event.keyCode === 39)
        pressingRight = false;

    else if(event.keyCode === 37)
        pressingLeft = false;

    else if(event.keyCode === 38)
        pressingUp = false;

    else if(event.keyCode === 40)
        pressingDown = false;

    else if(event.keyCode === 65)
        pressingA = false;

    else if(event.keyCode === 66)
        pressingB = false;

    else if(event.keyCode === 67)
        pressingC = false;

    else if(event.keyCode === 90)
        pressingZ = false;

    else if(event.keyCode === 83)
        pressingS = false;

    else if(event.keyCode === 88)
        pressingX = false;

    else if(event.keyCode === 13)
        pressingEnter = false;
}

//pictures
drawImage=function(source,x_s,y_s,w_s,h_s) {
var pic = new Image();
pic.onload = function(){
ctx.drawImage(pic,x_s,y_s,w_s,h_s);
}
pic.src="Images/"+source;
}
_________________________________________________________________________________

For vbl.js :
_________________________________________________________________________________
//canvas
var WIDTH=360;
var HEIGHT=360;
var version_num=1.01;

//mouse
/*
var mouseX=mouse.clientX-0;
var mouseY=mouse.clientY-8;
var mouseisPressed=false;
*/

//keyboard

var pressingUp=false;
var pressingDown=false;
var pressingLeft=false;
var pressingRight=false;
var pressingA=false;
var pressingB=false;
var pressingC=false;
var pressingZ=false;
var pressingS=false;
var pressingX=false;

//time
var a_exist=false;
var b_exist=false;
var n_n=0;
var t_t=0;
var FFEspd=1000/30;

//logic gates
var and_R='0';
var or_R='0';
var xor_R='0';
_________________________________________________________________________________


If the version required(or later) is not available, this message will appear in console.

"I am sorry. You need V <version number required> to run this program."

Please enjoy using Algo Code. Oh, and you are free to comment your programs that you created using Algo Code on CoFFee.

22-04-2017

No comments:

Post a Comment