Skip to content

Instantly share code, notes, and snippets.

View rayyee's full-sized avatar
🌴
On vacation

Ray Yee rayyee

🌴
On vacation
View GitHub Profile
@rayyee
rayyee / Color.as
Created June 4, 2014 05:57
Color.as
/**
* Add alpha to RGB color
* @param rgb
* @param a
* @return
*/
public static function addAlpha( rgb:uint, a:uint = 0xFF ):uint
{
return (a << 24) | rgb;
}
// =================================================================================================
//
// based on starling.text.TextField
// modified to use text layout framework engine for rendering text
//
// =================================================================================================
package starling.extensions
{
import flash.display.BitmapData;
package starling.extensions.DistanceFieldFont
{
import flash.geom.Rectangle;
import flash.utils.Dictionary;
import starling.display.Image;
import starling.text.BitmapChar;
import starling.textures.Texture;
import starling.textures.TextureSmoothing;
import starling.utils.HAlign;
@rayyee
rayyee / Gaussian.as
Created July 22, 2014 11:44
正态分布随机数
public const c0:Number = 2.515517;
public const c1:Number = 0.802853;
public const c2:Number = 0.010328;
public const d1:Number = 1.432788;
public const d2:Number = 0.189269;
public const d3:Number = 0.001308;
/**
* 正态分布的随机数.a控制波形的顶点,b控制波形的扁度
* @param a 如a是0即,随机出0的机率会大到-1,1,-2,2,然后递减
* @param b 如b是2即,随机出>-2和<2之间的数字机率最大(注意这里的b 是方差,等于标准差的平方)
@rayyee
rayyee / Crawler.java
Created July 30, 2014 07:08
简单的爬虫
package com.rayyee;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import java.io.File;
@rayyee
rayyee / test.cpp
Created August 25, 2014 10:50
*&p 形参的一种表现
#include <cstddef>
const char *advanceP(const char *&p, size_t n)
{
const char *pp = p;
p += n;
return pp;
}
typedef struct
{
@rayyee
rayyee / coroutine.h
Created September 26, 2014 08:34
Coroutines in C
/* coroutine.h
*
* Coroutine mechanics, implemented on top of standard ANSI C. See
* http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html for
* a full discussion of the theory behind this.
*
* To use these macros to define a coroutine, you need to write a
* function that looks something like this.
*
* [Simple version using static variables (scr macros)]
attribute vec4 a_position;
attribute vec3 a_normal;
attribute vec2 a_texCoord;
attribute vec2 a_texCoord1;
varying vec2 v_texture_coord;
varying vec2 v_texture_coord1;
// height of the wave in world units.
uniform float u_amplitude;
attribute vec4 a_position;
attribute vec2 a_texCoord;
attribute vec2 a_texCoord1;
attribute vec2 a_texCoord2;
attribute vec4 a_color;
varying vec4 v_color;
varying vec2 v_texture_coord;
varying vec2 v_texture_coord1;
varying vec2 v_texture_coord2;
#ifdef GL_ES
varying mediump vec2 v_texture_coord;
varying mediump vec2 v_texture_coord1;
#else
varying vec2 v_texture_coord;
varying vec2 v_texture_coord1;
#endif
uniform sampler2D lightmap;
void main(void)