Pages

Friday, April 21, 2017

Algo Code Ep 5 - New Version!!!

Dear readers, I have created a new version of Algo Code.

Introducing... Algo code V 1.0.1 !!!!!

Added:

Functions:
1. ellipse(middleX, middleY, width, height) - for drawing ellipses
2. quad( x1,y1,x2,y2,x3,y3,x4,y4) - for drawing quadrilaterals
3. line (startX, startY, endX, endY) - for drawing lines
4. triangle(x1,y1,x2,y2,x3,y3) - for drawing triangles
5. drawImage(file name*,x,y, width,height) - for drawing pictures
*You must write type of pictures, like .png, .gif or .jpeg Write in "n" or 'n ' No asterisk.
e.g., "Hello.gif" "Smiley.png"

Variables:
1. pressingZ
2. pressingS
3. pressingX
4. pressingEnter

Enter is the return key.

Files:
Algo Code {
       Program Test {
       }
       Project 1 {
            app.html
            fcnt.js
            MAIN.js
            vbl.js
            Images {
                 pictures for drawImages()
            }
       }
}

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;
}

//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;

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

//keyboard
var pressingEnter=false;
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';
_________________________________________________________________________________

Okay, so I think that's all. Thanks!

Notes:
K.U. can be used on V 1.0.1 also.

Oh, and please enjoy using Algo code V 1.0.1 .

21-04-2017

No comments:

Post a Comment