Senin, 05 Desember 2016

Membuat Segitiga dengan Canvas HTML5

Ok sekarang saya akan berbagi cara membuat segitiga menggunakan tag <canvas> di HTML5.

Pertama, copy code dibawah ini sebagai dasarnya :


<head>
    <style>
        canvas {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            z-index: 0;
        }
    </style>
</head>
<body>
    <canvas></canvas>

    <script>
    </script>

</body>


Lalu copy code dibawah ini dan taruh di bawah tag <script> :
  







    var c  = document.getElementsByTagName('canvas')[0],
        x  = c.getContext('2d');
        pr = window.devicePixelRatio || 1,
        w  = window.innerWidth,
        h  = window.innerHeight,

    c.width = w*pr;
    c.height = h*pr;
    x.globalAlpha = 0.9;

    var mh = Math.floor(c.height/3),
        rp = Math.floor((Math.random() * (c.height-mh)) + 0),
        rh = Math.floor((Math.random() * mh) + (rp+30)),
        cl = ['#00C8F8','#59C4C5', '#F3BA39', '#FBE2B4',
              '#FF4C65', '#588C73', '#F2E394', '#F2AE72',     
              '#D96459', '#8C4646'];


    x.beginPath();
    x.moveTo(0, rp);                    
    x.lineTo(0, rh);                    
    x.lineTo(c.width/2, c.height/2);    
    x.closePath();                      

    x.fillStyle = cl[Math.floor((Math.random() * 9) + 0)];
    x.fill();
    

    x.beginPath();
    x.moveTo(c.width, c.height-rp);
    x.lineTo(c.width, c.height-rh);
    x.lineTo(c.width/2, c.height/2);
    x.closePath();


    x.fillStyle = cl[Math.floor((Math.random() * 9) + 0)];
    x.fill();
Dan hasilnya akan seperti ini :





Hasil segitiganya adalah random, jadi setiap kita refresh akan keluar segitiga yang berbeda.
Sekian dan terimakasih ^_^
--------------------------------------------------------------------------------------------------------------
Big thanks for Google and all Blogger~

Senin, 19 September 2016

Go - Switch statement


Hello everyone! Comeback with me, Indomieboy~
Today, I will explain a little bit about Switch on Golang.

-----------------------------------------------------------------------------------------------

A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each switch case.

In Go programming, switch are of two types:
  • Expression Switch (I will use this)
  • Type Switch

Expression Switch

 The syntax for a Expression Switch statement in Go programming language is as follows:

switch(boolean-expression or integral type){
    case boolean-expression or integral type  :
       statement(s);      
    case boolean-expression or integral type  :
       statement(s); 
    /* you can have any number of case statements */
    default : /* Optional */
       statement(s);
}

Flow Diagram:


(image source: google)

Example:

package main

import "fmt"

func main() {
   /* local variable definition */
   var rank string = "2"
   var marks int = 90

   switch marks {
      case 90: rank = "1"
      case 80: rank = "2"
      case 50,60,70 : rank = "3"
      default: rank = "4"  
   }

   switch {
      case rank == "1" :
         fmt.Printf("WOW! You are a champion!\n" )     
      case rank == "2", rank == "3" :
         fmt.Printf("Well done\n" )      
      case rank == "4" :
         fmt.Printf("Try again\n" )      
      case rank == "5":
         fmt.Printf("Sorry you're loser\n" )
      default:
         fmt.Printf("Invalid rank\n" );
   }
   fmt.Printf("Your rank is  %s\n", rank );      
}
 And this the result:
(image source: my screenshot)
--------------------------------------------------------------------------------------------------------------

Sorry if my grammar full of mistakes

#CMIIW

 -----------------------------------------------------------------------------------------------------------------
Big thank's for Google & many blogger

Sabtu, 10 September 2016

How to Install Notepad++ and GoLang Plugin on Windows 8

 What you needs :

Steps : 

  1. Download and install Golang, from here.
  2. Set up your 'Environment Variables' on Control Panel. In order to do this open Control Panel > Search for 'Environment Variables'.
  3. Click 'New' on system variables.
  4. And create like this.
  5. Click OK and close Control Panel.
  6. Download and install Notepad++.
  7. Download go.xml and then copy it to  <Your install folder>/plugins/APIs
  8. Open Notepad++
  9. On the Notepad++ Toolbar menu select Language -> Define your language
  10. A user defined language window should open. Click the import button and navigate to the UserDefineLang.xml file and open it which you can download from here
  11. Restart Notepad++
  12. On the Notepad++ toolbar menu select Plugins -> Plugins Manager -> Show Plugin Manger
  13. Choose Gonpp and install Gonpp

How to test?

  1. Open Notepad++
  2. Click Language -> Go
  3. Type like this. You can change whatever you want in the words that circle.

  4. Than save as to C:/Go/Golang or C:/Program file/Go/Golang.
  5. And named as 'test.go' and click save.
  6. After that press "Alt+R"
  7. And...... Voila!
 --------------------------------------------------------------------------------------------------------------------------------

Sorry if my grammar full of mistakes

#CMIIW

----------------------------------------------------------------------------------------------------------------------------------
Big thank's for Github & many blogger