Sunday, April 30, 2017

Algo Code Blog

Dear Algo Code readers,

I have created a blog for Algo Code. It is at algocode321.blogspot.my .

Thanks.

30-04-2017

Sunday, April 23, 2017

CoFFeeLands

Hey, dear readers!

I am going to create a new series called CoFFeeLands. It involves a lot of stories. I hope that you enjoy it.

Thanks!

23-04-2017

Saturday, April 22, 2017

Drag Me Down

Dear readers,
Here is a song that you will like. Please enjoy it.


Thanks for drinking!

22-04-2017

Happy Earth Day!

To all our respected readers,

Happy Earth Day 2017!!!

Here are some things that you can to for the Earth.
1. Plant trees
2. Use less electricity
3. Use less petrol
4. Do not use plastic bags

Please have a nice Earth Day!

22-04-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

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

Algo Code Ep 4 - A New Game

Hello again, dear readers.

I have created a short game that is called K.U.

Here is the code for it.

_________________________________________________________________________________
var lives=1;
var start=false;
var strt=false;
var stage=1;
//borders
var bord1=60;
var bord2=-70;
//liquids
var lava=-20;
var lavcol='red';
var water=240;
var watcol='turquoise';

var player={
    x:30,
    y:210,
    width:30,
    height:30,
}

conscls();
conssay('Please use game() to start game.');

game=function() {
conscls();
start=true;
conssay('Your mission is to kill the red block.');
}

update=function() {
if(start==true && stage==1) {
cngCol('beige');
rect(0,0,WIDTH,HEIGHT);
cngCol('tan');
rect(0,240,WIDTH,120);
cngCol('white');
rect(60,0,230,100);
rect(90,240,170,120);
cngCol('tan');
rect(60,0,30,100);
rect(260,0,30,100);
rect(bord1,70,200,30);
rect(bord2,330,360,30);
if(watcol=='turquoise') {
cngCol(lavcol);
rect(90,lava,170,90);
}
cngCol(watcol);
rect(90,water,170,90);
}

if(start==true && stage==1 && lives==1) {
cngCol('red');
rect(player.x,player.y,player.width,player.height);
}

if(pressingRight==true && start==true) {
player.x+=5;
}

if(pressingLeft==true && start==true) {
player.x-=5;
}

if(pressingA==true && start==true) {
bord1-=5;
}

if(pressingB==true && start==true) {
bord2-=5;
}

if(pressingC==true && start==true) {
bord2+=5;
}

if(pressingUp==true && start==true) {
player.y-=7.5;
}

if(pressingUp==false && player.y<210) {
player.y+=5;
}
if(stage==1) {
if(player.x>90 && player.x<230 && player.y<300 && bord2>-140) {
player.y+=5;
}

if(player.x>90 && player.x<230 && player.y>=300 && bord2<=-140) {
player.y+=5;
}

if(lava<240 && bord1<=-140) {
lava+=5;
}

if(water>=240 && bord2<=-140) {
water+=5;
}

if(water>=240 && bord2<=-140 && watcol=='black') {
water+=5;
lava+=5;
}

if(lava==240 && water==240 && bord1<=-140) {
lava+=5;
watcol='black';
}

if(lava>=240 && bord2<=-140) {
lava+=5;
}

if(player.x>90 && player.x<230 && player.y>360) {
conssay('SUCCESS!');
lives=0;
strt=true;
stage=2;
}

if(player.x>90 && player.x<230 && player.y<=300 && lava==240 && water>240) {
conssay('SUCCESS!');
lives=0;
strt=true;
stage=2;
}

if(watcol=='black') {
conssay('FAIL');
}
}

if(stage==2 && strt==true) {
lives=1;
player.x=30;
player.y=210;
strt=false;
}
if(stage==2) {

}

//border
if(player.x<0) {
player.x=0;
}

if(player.x>330) {
player.x=330;
}

if(player.y<0) {
player.y=0;
}
}

setInterval(update,15);
_________________________________________________________________________________

Oh, and
A is for the border above open
B is for the border below open
C is for the border below close

You can save this code in Program Test.

Unfortunately, this game only has one level. (CURRENTLY)

You can help by expanding (creating new levels) or upgrading my level.

Thanks.

21-04-2017

Algo Code Ep 3 - Knowing the Program

Welcome back, readers!

Today, I will introduce to you the functions and variables in Algo Code*.

1. text(word,x,y)
-write text on the canvas

2. rect(x,y,width,height)
-draw rectangles or squares

3. conssay(word)
-write text on the console

4. cnvscls()
-clear the canvas

5. conscls()
-clear the console

6. cngCol(color)
-change color used

7. var n=0
-set variables

Also, here are the variables in Algo Code.
1. WIDTH
-width of the canvas

2. HEIGHT
-height of the canvas

3. pressingkey
-if a key on the keyboard is pressed

For pressingkey, you can use 
1. pressingUp
2. pressingDown
3. pressingLeft
4. pressingRight
5. pressingA
6. pressingB
7. pressingC

These are the functions and variables for Algo Code.


* Note: This  guide is for V 1.0.0

Thanks for drinking!

21-04-2017

Saturday, April 01, 2017

Catch!

Catch!



Tic Tac Toe

Tic Tac Toe






Games

Hey readers!


I am going to put some games on CoFFee so that you can play them. Please enjoy.

Oh, and happy April Fool's Day!

1-4-2017