HTML/JavaScript小工具

HTML/JavaScript小工具

2016年8月25日 星期四

10進位轉16進位程式寫法

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package 演算法;

/**
 *
 * @author howard
 */
public class TestM1 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
      int v = 48141;
      int tmp = v;
     
      String[] ohx = new String[]{"0","1","2","3","4","5","6","7","8","9",
                                     "A","B","C","D","E","F"};
      int[] numbers = new int[100];
      int i = 0;
      while (tmp > 15){
         int c = tmp % 16;
         numbers[i] = c;    
        tmp /= 16;    
        i++;
      }
      numbers[i] = tmp;
     
      for (int index = i;i>=0;i--){
          System.out.print(ohx[numbers[i]]);
      }
     
    }
   
}

2016年7月18日 星期一

ShaderLab map to Cg/HLSL variable types

Property types in ShaderLab map to Cg/HLSL variable types this way:
  • Color and Vector properties map to float4half4 or fixed4 variables.
  • Range and Float properties map to floathalf or fixed variables.
  • Texture properties map to sampler2D variables for regular (2D) textures; Cubemaps map to samplerCUBE; and 3D textures map to sampler3D.
https://docs.unity3d.com/Manual/SL-SurfaceShaders.html

Tags
http://docs.unity3d.com/462/Documentation/Manual/SL-SubshaderTags.html
光照 模型 之後再談brdf 

黃金比例

https://zh.wikipedia.org/wiki/%E9%BB%84%E9%87%91%E5%88%86%E5%89%B2%E7%8E%87

黃金比例的準確值為,所以是無理數,而大約值則為(小數點後20位,OEISA001622):

2016年7月4日 星期一

2016年6月24日 星期五

數字排列

public class BFS1_6 {
    static int[] arrays = {1,2,3,4,5,6,7};
    static int[] shwoArrays = new int[arrays.length];
    static int[] mark = new int[arrays.length];  
    static int count = 0 ;
    public static void dfs(int step){
        if (step == arrays.length){
            for(int value : shwoArrays){
                System.out.print(value+" ");
            }
            count++;
            System.out.println();
            return;
        }
       
        for (int i = 0;i<arrays.length;i++){
           
            if (mark[i] == 0){
                mark[i] = 1;
                shwoArrays[step] = arrays[i];
                dfs(step + 1);
                mark[i] = 0;
            }
           
        }
       
       
    }
    public static void main(String[] args) {
        // TODO code application logic here
        dfs(0);
        System.out.println(count);
    }

}



排列種類數量
2 2
3 6
4 24
5 120
7 5040
公式
2 * (N1 * N2*N3...)
如要計算
5 的排列種類數量
2 * 3 * 4 * 5 = 120

深度優先算法


package 演算法;

public class 深度優先算法_2 {
    /*
    1 表示可連接的線
    0 表示自己
    999 表示無法連線
    邏輯如下:
    1 先找到一個點
    2 看看跟哪個點有連線
    3 在進到有連線的點
    4 依照路徑一層一層找  
    */
   public static  int[][] myTree = { {0,1,1,999,1},
                       {1,0,999,1,999},
                       {1,999,0,999,1},
                       {999,1,999,0,999},
                       {1,999,1,999,0} };
 
   static int sum = 0;
   static int[] mark = new int[myTree.length];//記錄哪些點走過,不需要再走了
   public static void dfs(int point){
       System.out.println(point);//目前在哪個點
       sum++;//記錄一共走了多少點
       if (sum == myTree.length){      
           return;
       }    
       for (int i = 0 ; i  < myTree.length; i++){
           if (mark[i] == 0 && myTree[point][i] == 1){
                mark[i] = 1;
               dfs(i);              
           }
       }
   }
 
    public static void main(String[] args) {      
        mark[0] = 1;
         dfs(0);  
    }
   
}

2016年6月15日 星期三

三消遊戲基本演算法

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package 演算法;

/**
 *橫向存點
垂直存點

觸發點

每格都如此
 往右邊走
   如果 碰到相同
              Save 橫向存點
   如果 到邊界 或是 不相同
           return
回到觸發點
   往左邊走
   如果 碰到相同
              Save 橫向存點
   如果 到邊界 或是 不相同
           return



回到觸發點
   往上邊走
如果 碰到相同
              Save 垂直存點
  如果 到邊界 或是 不相同
           return


回到觸發點
   往下邊走
如果 碰到相同
              Save 垂直存點
  如果 到邊界 或是 不相同
           return

完成計算需要消除的點
清空除存點
 * @author howard
 */
public class 三消演算dfs_1 {
        static int[][] directArrays = {{0,1},
                                    {0,-1},
                                    {-1,0},
                                    {1,0}};
 
        static int[][] threeMatch={
            {0,0,0,0,0,0},
            {0,0,1,0,0,0},
            {1,1,1,0,0,0},
            {0,0,1,0,0,0},
            {0,0,1,0,0,0}      
        };
 
        public static void triggerPoint(int x,int y){
           for (int i = 0;i<directArrays.length;i++){
         
                int[]  direct =  directArrays[i];
       
                int nextX = x + direct[0];
                int nextY = y + direct[1];
                int matchNumber = threeMatch[x][y];
           
                nextPoint(matchNumber,nextX,nextY,direct);
             
            }        
        }
     
        public static void nextPoint(int matchNumber, int nextX,int nextY,int[] direct){
         
                if (nextX < 0 || nextX == threeMatch.length ||
                        nextY < 0 || nextY == threeMatch[0].length ||
                        threeMatch[nextX][nextY] != matchNumber){  
                    System.out.println("=======================");
                    return;
                }
             
             
                System.out.println("X:"+nextX+"Y:"+nextY);
                 nextX +=  direct[0];
                 nextY +=  direct[1];
               nextPoint(matchNumber,nextX,nextY,direct);
         
        }
     
    public static void main(String[] args) {
     
     
        triggerPoint(2,2);
     
    }
 

 
 
 
}

2016年4月14日 星期四

插入排序法

#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
int array[] = {8,9,5,7,6};

for(int i =0;i<5;i++){
int j = i + 1;
if (j > 4){
break;
}
int tag = array[j];
while(j > 0 && array[j-1] > tag){
array[j] = array[j-1] ;
j--;
}
array[j] = tag;
}

for(int i =0;i<5;i++){
cout << array[i] << endl;
}

return 0;
}

2016年2月24日 星期三

Lerp

float result = Mathf.Lerp (3f, 5f, 0.5f);
以上只3 ~ 5 中間的數
(3 + 5) * 0.5 = 4 

Vector3 from = new Vector3 (1f, 2f, 3f);
Vector3 to = new Vector3 (5f, 6f, 7f);

// Here result = (4, 5, 6)
Vector3 result = Vector3.Lerp (from, to, 0.75f);

向量轉換

int v = 1;
 v = Mathf.Lerp(v, 10f, 0.5f); //每個影格分一半
以上放在Update
v 的數值會越來越接近10
變化約如下
 Mathf.Lerp(5, 10f, 0.5f); // 5 ~ 10  的一半
 Mathf.Lerp(7.75f 10f, 0.5f); // 5 ~ 10  的一半
 Mathf.Lerp(8.75f 10f, 0.5f); // 5 ~ 10  的一半
 Mathf.Lerp(9.75f 10f, 0.5f); // 5 ~ 10  的一半
 Mathf.Lerp(10f 10f, 0.5f); // 5 ~ 10  的一半



Mathf.Lerp(1, 10f, 0.5f * Time.deltaTime);
每秒取一半的數值

unity3d 5 的Bug!!!! 粒子系統只能播一次

unity3d 5 的Bug!!!! 粒子系統只能播一次
不知啥時會解決於是記一下處理方法
 hitParticle.Play();
        hitParticle.Emit(1);
加入Emit搞定!!

https://issuetracker.unity3d.com/issues/particle-system-plays-only-once