获取汉字GBK内码(AS3)

private function getGBKCode(str:String):String
{
var b:ByteArray = new ByteArray

//b.writeMultiByte(str, File.systemCharset);
b.writeMultiByte(str, ‘GBK’);
b.position = 0;
return b.readUnsignedByte().toString(16).toUpperCase() + b.readUnsignedByte().toString(16).toUpperCase();
}

一个AS3画任意虚线形状的类,很好用。

是不是很多朋友都在问如何用AS3绘制虚线?有了下面这个类,妈妈再也不用担心你了。

DashedLine(AS3画虚线的类)

用法:

先创建一个有graphics的显示对象,然后作为参数传给DashedLine类,并创建一个DashedLine实例。

接着你就可以像使用graphics一样来调用一些方法了:

* myDashedDrawing.moveTo(50, 50);
* myDashedDrawing.lineTo(100, 50);
* myDashedDrawing.curveTo(100, 100,200,200);

这里要注意一下,由于这个虚线实际上是一段一段的lineTo画出来的,所以如果你要用到填充。最好做两个shape层:一层直接填充,一层画虚线。

SVG图像格式path参数详解

悲催的发现as3版本的两个potracer都有问题,只好重新寻找其他办法来实现位图转矢量。

结果发现原版的poracer只能转eps、svg以及geojson等格式,所以只能再通过解析svg文件来转成as3的graphicsPath所需要的格式(geojson格式其实也可以转,不过他会把一条贝塞尔曲线转成8条直线,数据量肯定会大一些。所以还是从svg想办法。

转好的矢量在svg中都是通过path来存储绘图指令的,所以必须先要搞清楚他的含义。

这篇文章讲的非常详细了:

深度掌握SVG路径path的贝塞尔曲线指令

http://www.zhangxinxu.com/wordpress/2014/06/deep-understand-svg-path-bezier-curves-command/

命令 名称 参数
M moveto  移动到 (x y)+
Z closepath  关闭路径 (none)
L lineto  画线到 (x y)+
H horizontal lineto  水平线到 x+
V vertical lineto  垂直线到 y+
C curveto  三次贝塞尔曲线到 (x1 y1 x2 y2 x y)+
S smooth curveto  光滑三次贝塞尔曲线到 (x2 y2 x y)+
Q quadratic Bézier curveto  二次贝塞尔曲线到 (x1 y1 x y)+
T smooth quadratic Bézier curveto  光滑二次贝塞尔曲线到 (x y)+
A elliptical arc  椭圆弧 (rx ry x-axis-rotation large-arc-flag sweep-flag x y)+
R Catmull-Rom curveto*  Catmull-Rom曲线 x1 y1 (x y)+

 

恩,知道这些应该可以开始处理了。

通过js获取dpi的方法

 

这里有一个js获取dpi值的方法。

function js_getDPI() {
    var arrDPI = new Array();
    if (window.screen.deviceXDPI != undefined) {
        arrDPI[0] = window.screen.deviceXDPI;
        arrDPI[1] = window.screen.deviceYDPI;
    }
    else {
        var tmpNode = document.createElement(“DIV”);
        tmpNode.style.cssText = “width:1in;height:1in;position:absolute;left:0px;top:0px;z-index:99;visibility:hidden”;
        document.body.appendChild(tmpNode);
        arrDPI[0] = parseInt(tmpNode.offsetWidth);
        arrDPI[1] = parseInt(tmpNode.offsetHeight);
        tmpNode.parentNode.removeChild(tmpNode);    
    }
    return arrDPI;
}

RGB转HSB及HSB颜色模型说明

最近因为要做一个手机app,其中需要对色彩最一些识别。由于我们肉眼所看到的颜色用RGB无法区分(例如我们说的红色可能其RGB模型可能红色、绿色、蓝色都有),所以我们需要一个更容易描述的颜色模型。而hsb模型正好符合我们的要求。

HSB颜色模型可以理解为一个倒立的圆锥形,如下图所示

1353401545_7912    1353404459_6995

每一个颜色都由三个属性组成:

H: 色相

S:饱和度

B:明度

这个模型的好处在于,当我们描述一个红色的不同明暗时,它的色相值是不变的。

比方说我们有个红色,当光照条件不好的时候他表现为暗红,光照特别强时表现为浅红。但是他的色相是不会变化的,只有饱和度和明度发生变化。

所以,当我们对手机在不同光照条件下拍照时,用来判断颜色它的色相的变化是很小的。

RGB转HSB的公式

MAX=(R,G,B)中最大的值

MIN=(R,G,B)中最小的值

1.色相H的计算

如果R值是最大值 色相 H = 60 × ((G – B) ÷ (MAX – MIN))

如果G值是最大值 色相 H = 60 × ((B – R) ÷ (MAX – MIN)) +120

如果B值是最大值 色相 H = 60 × ((R – G) ÷ (MAX – MIN)) +240

如果RGB相等 色相 H = 0

注意:如果H为负值,则将其加上360

2.饱和度S的计算

S = (MAX – MIN) ÷ MAX

如果S的范围为0-255  S=S * 255

如果S的范围为0-100  S=S * 100

3.明度B的计算

明度 V = MAX

如果V的范围为0-255 V=V

如果V的范围为0-100 V=V/255 * 100

 

参考文章:

1.http://www.peko-step.com/tool/hsvrgb.html#ppick2

2.http://blog.csdn.net/viewcode/article/details/8203728

 

html5中viewport属性用法

随着高端手机(Andriod,Iphone,Ipod,WinPhone等)的盛行,移动互联应用开发也越来越受到人们的重视,用html5开发移动应用是最好的选择。然而,每一款手机有不同的分辨率,不同屏幕大小,如何使我们开发出来的应用或页面大小能适合各种高端手机使用呢?学习html5 viewport的使用能帮你做到这一点……

viewport 语法介绍:

01 <!– html document –>
02 <meta name=”viewport”
03     content=”
04         height = [pixel_value | device-height] ,
05         width = [pixel_value | device-width ] ,
06         initial-scale = float_value ,
07         minimum-scale = float_value ,
08         maximum-scale = float_value ,
09         user-scalable = [yes | no] ,
10         target-densitydpi = [dpi_value | device-dpi | high-dpi | medium-dpi | low-dpi]
11     “
12 />
width

控制 viewport 的大小,可以指定的一个值或者特殊的值,如 device-width 为设备的宽度(单位为缩放为 100% 时的 CSS 的像素)。

height

和 width 相对应,指定高度。

target-densitydpi

一个屏幕像素密度是由屏幕分辨率决定的,通常定义为每英寸点的数量(dpi)。Android支持三种屏幕像素密度:低像素密度,中像素密度,高像素密度。一个低像素密度的屏幕每英寸上的像素点更少,而一个高像素密度的屏幕每英寸上的像素点更多。Android Browser和WebView默认屏幕为中像素密度。

下面是 target-densitydpi 属性的 取值范围

  • device-dpi –使用设备原本的 dpi 作为目标 dp。 不会发生默认缩放。
  • high-dpi – 使用hdpi 作为目标 dpi。 中等像素密度和低像素密度设备相应缩小。
  • medium-dpi – 使用mdpi作为目标 dpi。 高像素密度设备相应放大, 像素密度设备相应缩小。 这是默认的target density.
  • low-dpi -使用mdpi作为目标 dpi。中等像素密度和高像素密度设备相应放大。
  • <value> – 指定一个具体的dpi 值作为target dpi. 这个值的范围必须在70–400之间。
1 <!– html document –>
2 <meta name=”viewport” content=”target-densitydpi=device-dpi” />
3 <meta name=”viewport” content=”target-densitydpi=high-dpi” />
4 <meta name=”viewport” content=”target-densitydpi=medium-dpi” />
5 <meta name=”viewport” content=”target-densitydpi=low-dpi” />
6 <meta name=”viewport” content=”target-densitydpi=200″ />

为了防止Android Browser和WebView 根据不同屏幕的像素密度对你的页面进行缩放,你可以将viewport的target-densitydpi 设置为 device-dpi。当你这么做了,页面将不会缩放。相反,页面会根据当前屏幕的像素密度进行展示。在这种情形下,你还需要将viewport的width定义为与设备的width匹配,这样你的页面就可以和屏幕相适应。

initial-scale

初始缩放。即页面初始缩放程度。这是一个浮点值,是页面大小的一个乘数。例如,如果你设置初始缩放为“1.0”,那么,web页面在展现的时候就会以target density分辨率的1:1来展现。如果你设置为“2.0”,那么这个页面就会放大为2倍。

maximum-scale

最大缩放。即允许的最大缩放程度。这也是一个浮点值,用以指出页面大小与屏幕大小相比的最大乘数。例如,如果你将这个值设置为“2.0”,那么这个页面与target size相比,最多能放大2倍。

user-scalable

用户调整缩放。即用户是否能改变页面缩放程度。如果设置为yes则是允许用户对其进行改变,反之为no。默认值是yes。如果你将其设置为no,那么minimum-scale 和 maximum-scale都将被忽略,因为根本不可能缩放。

所有的缩放值都必须在0.01–10的范围之内。

例:

(设置屏幕宽度为设备宽度,禁止用户手动调整缩放)

 <meta name=”viewport” content=”width=device-width,user-scalable=no” />

(设置屏幕密度为高频,中频,低频自动缩放,禁止用户手动调整缩放)

<meta name=”viewport” content=”width=device-width,target-densitydpi=high-dpi,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no”/>

使用ruby创建简易的静态html服务器,跟python -m SimpleHttpServer一样

最近好多html页面需要在手机上做测试,电脑上没有安装http服务器不方便测试。

昨天看到同事用python -m SimpleHttpServer可以很方便的将任意目录变成web环境。所以也想用ruby来设置一个。

找了一圈资料发现直接用ruby的rack就能很方便的设置一个。

设置方法:

第一步——安装rack

gem install rack

第二步——创建一个config.ru文件

use Rack::ContentLength
 
app = Rack::Directory.new Dir.pwd
run app

第三步——将config.ru保存到C盘的根目录

第四步——创建一个批处理server.bat到C盘的根目录

rackup -o 0.0.0.0 -p 80 c:/config.ru

使用的时候,先进入到需要映射的目录,然后执行批处理 c:/server.bat

第五步——打开你的浏览器输入http://你的ip

常用的Dos批处理编辑

1.设置变量

设置:set MY_DIR=C:\xxx

使用:%MY_DIR%\readme.txt      =>’C:\xxx\readme.txt’

 

2.批处理文件所在的目录

%~dp0  只能在批处理中使用,表示批处理文件所在的目录

 

3.当前的执行目录

%cd%  在哪个目录执行就表示哪个目录

比如在C:\下执行D:\aa.bat   %cd%为C:\

away3d 4.x以后的功能更新说明(英文)

4.0.1
– Fixes to object controllers
4.0.2
– Fixed cone geometry normals
4.0.3
– Added WireframeCylinder primitive
– Added View3D.queueSnapshot() to take screen shots of view
4.0.4
– Fixed issues with geometry validation in primitives
4.0.5
– Implemented changes related to finalized AWD 2.0 specification
– Improved LookAtController (#217)
– Fixed visual bug in AwayStats (#220)
– Added torus geometry primitive
– Optimized Fresnel specular method
– Added texture support in ambient method
4.0.6
– Implemented geometry splitting in AWD2Parser (large meshes) (#136)
– Added support for alpha in video texture (#54)
4.0.7
– Fixed crash caused by null alpha mask in shadow depth rendering (#274)
– Fixed bounds calculation for flat geometries (#273)
– Fixed issue related to primitive validation (#257)
– Fixed device loss (#263, #269)
– Fixed issue with removing assets from library (#162)
– Fixed bug related to RTT dimensions (#279)
– Unified and improved sub-mesh splitting (better support for large meshes)
– Improved tool classes
– Optimized Object3D.updateTransform() (#232)
– Fixed crash issue in AIR (#230)
– Fixed lightPicker invalidation bug (#216)
– Fixed bug only appearing in software rendering (#234)
– Fixed issues in 3DS parser (#294, #291)
– Added NearShadowMapMethod
– Implemented support for nested objects in Drag3D (#283)
– Fixes to segment rendering and management
– Implemented visible property on View3D (#155)
– Enabled texture repeating in materials loaded from OBJ files (#5)
– Properly implemented and tested Sound3D (#227, #41)
– Fixed bug in MD5 parser caused by zero-weights (#65)
– Added alpha property for shadow map methods
– Added WebcamTexture
– Improved Stage3DProxy interface
– Added doubleSided property to PlaneGeometry
– Added backbuffer cap to avoid bug caused by too large backbuffers (#285)
– Fixed issue with small OBJ files (#304)
– Fixed wrap issue in HoverController (#299)
– Enabled integration of other Stage3D frameworks (e.g. Starling)
– Fixed Sprite3D clipping bug (#309)
– Lowered texture limit to 1×1 (#308)
– Fixed OBJParser issue related to specular shading (#70, #64)
– Fixed delegation issue in composit AWDParser (#315)
– Fixed issue with texture disposal (#316)
– Implemented Tim Knip’s DAEParser
– Slightly refactored loading system internals, renamed some events
– Removed deprecated bitmap/video materials
– Refactored picking system
– Optimizations to scene graph and picking
– Fixed parsing of texture names from AWD2 files (#200)
– Fixed bug in OBJParser concerning escaped line-breaks (#330)
– Fixed pivot point issue (#333)
– Added path data classes
– Refactored animation system
– Refactored object controllers (328, #331)
– Fix MD2 render state for different passes (#340)
– Fixed normal/tangent issues in CylinderGeometry (#209)
– Added default materials for objects (#170)
– Added skeleton and forceCPU properties to SkeletonAnimator
– Fixed bug in UV generation for cube primitives
– Fixed bug in SkeletonAnimator playback with negative playbackSpeed
– Fixed bug in SegmentSet (#198)
4.0.8
– Fixed infinite recursion issue in SkeletonDifferenceNode
– Fix for Gold alpha blending regression
4.0.9
– Fixed MD5 mesh bug (#364)
4.0.10
– Fixed incorrect z values in project() and x/y/z values in unproject() methods of lensbase
– Fixed incorrect bounds normals returned by mouse event on an object with triangle picking enabled
– Fixed missing delta data on MouseEvent3D.MOUSE_WHEEL events
4.0.11
– Doublesided materials considered correctly in triangle picking
– Fixed incorrect mouse events from Sprite3D
– Introduced zOffset parameter on all scenegraph objects to allow manual sorting offsets
– Fixed incorrect picking event from firing when a bounds collision is detected from inside the bounds
– Fixed missing mouse down events when running on tablets
– Added ability to resize the viewport of a View3D object independent of Stage3DProxy when sharing a context
– Updated Adobe’s AGALMiniAssembler to the latest from https://github.com/graphicscore/graphicscorelib
– Implemented getSceneCollision on RaycastPicker (#418)
4.1.0 (Alpha)
– Merged stereo rendering feature
– Merged particle animation feature
– Merged compact geometry feature
– Merged ATF texture feature
– Merged view volume partitions feature
– Merged multipass materials feature
– Merged realtime reflections feature
– Rebuilt tools package to work with new compact geometry feature
– Removed name arg in animation set interface method addAnimation, name to be set on asset.
– Renamed rootDelta property on AnimatorBase to positionDelta
– Deprecated TripleFilterShadowMethod in favour of SoftShadowMethod
– Added DXF parser
– Fix order of material vs animation code generation. Closes #405
– Increased max shadow map samples for DitheredShadowMapMethod
– Increased max shadow map samples for SoftShadowMethod
– Updated DirectionalLight’s scene transform (and as a result the sceneDirection) if dirty when sceneDirection is queried. Closes #391
– Replaced Texture constants not available in older compilers with string literals for backward compatibility
– PlaneGeometry: Fix faulty and missing uv’s when doubleSided is true.
– Changed composite shader methods to work by passing in a method rather than subclassing
– Moved responsibility for light picker updates to material passes
– Moved shader compilation classes into own package, extracted dependency counts into class
4.1.1 (Beta)
– Added mouseEnabled, mouseChildren and extra properties to Mesh.clone(). Closes #414
– Added WireframeTetrahedron geometry primitive (#375)
– Added support for constrained mode
– Added BlendMode.LAYER support for entities.
– Refactor to worldspace calcuations for scene partitions
– Improvements to shadow rendering
– Fixes to normal values for various primitive geometry classes
– Fixes to Merge, Mirror, Explode and GeomUtil tools. Closes #437, #438, #439, #440, #441
– Compiler warnings removed
– Background texture can deactivate mipmapping on creation. Closes #468
– View doesn’t dispose of a shared stage3DProxy when has shareContext = true (#475)
– Fixes to DAE parser (#486 & #484)
– Fixed EnvMapMethod using mask. Closes #480
– Fixed shadows for large scene position values. Closes #412
– Various fixes: unpaired mouse over/mouse out events, ObjectContainer3D bounds, missing removeChildAt(), OBJ parser ignores zero-length geometries, check for zero length geometries in CompactSubGeometry, normalise normals & tangents after transform (#472)
– Added OcclusionMaterial
– Added getParticleNodeName() to ParticleNodeNBase (#488)
– Added ParticleInitialColorNode to allow different initial colors for each particle
– Added BitmapData & ATF option for ImageParser (#489, #526)
– Added spritesheet animation to the animators classes
– Optimised ShaderRegisterCache creation/reset (#477)
– Fix incorrect values from uproject() method on view and camera
– Fix SubGeometry faceWeights variable (incorrect uint cast). Closes #511 & #505
– Added fix for steps = 0 in HoverController. Closes #467
– Fixed viewport scaling and offset when using a shared context. Closes #329
– Added PerspectiveOffCenterLens
– Fix to convertToSeparateBuffers in CompactSubGometry. Closes #491
– Fixed FirstPersonController wrap issue on panAngle. Closes #506
– Fix for SingleFileLoader when getting file extensions for urls with query strings. Closes #463
– Fixed 3D mouse events when using OrthographicLens. Closes #469
– Fixed mouse picking with 2 views. Closes #483
– Fixed mouse click event to behave correctly for a mouse click. Closes #399
– Fixed incorrect aspect ratio on a view when using Filter3D API. Closes #501
– Fixed scene partition error for floating cameras. Closes #519
– Added constrained mode option
– Fix to SkyBox clipping when using extreme frustum values. Closes #481
– Fixed materials ignoring invalidation when new effects methods are assigned. Closes #476
– Fixed ShaderPicker memory leak when view is disposed. Closes #461
– Mipmaps explicitly disposed when calling dispose() on TextureMaterial. Closes #459 & #417
– Fix for mesh normals data when using PickingType.SHADER on view.mousePicker. Closes #537
– Fix for incorrect thickness value being get/set on Segment. Closes #392
– Fixed single frame glitch for ambient light on startup of a scene. Closes #410
– Fix to MeshHelper class for correctly handling CompactSubGeometry classes. Closes #444
4.1.2
– Upgraded AWD parser to version 2.1
– Added SphereMaker Command
– Fix to animation errors and container mismatches on Collada parser (Closes #428 & #445)
– Fix for using second normal on SimpleWaterNormalMethod. Closes #558.
– Fixes to memory leaks around animators (Closes #562)
– Moved interleaveBuffers() method from away3d.utils.GeometryUtil to away3d.tools.utils.GeomUtils and removed away3d.utils.GeometryUtil
– Removed dummy COLLADA_ROOT_ container from Collada parser
– Fix to operation of PerspectiveOffCenterLens
– Fix State reseting when device loss experienced for animations
– Added Basic 3D multitouch support
– Extend LookAtController and HoverController to allow upAxis to be defined
– Update Epsilon value in Shadow Methods to be the equivalent of inverse-distance for both point and directional lights
– Re-worked getContainerBounds method to work with translations and rotations of nested containers and entities.
– Added bounds for Segment Sets
– Fixes to Geometry primitive normals
– Fixes to various AssetLoader issues and parser inconsistencies
– Orthographic lens fixed to work with sharedcontext views
– Various fixes to SegmentSet, added support for multiple buffers
– Picking fixes for sharedcontext views
– Added ParticleRotateToPositionNode in particle animators
4.1.3
– Fix issue with Segment thickness when sciccorRect is set in a view
– Fixed Bounds.getMeshBounds()
– Fixed index setting of ParticleFollowState
– Fix for sharing context collider with overlapping views
4.1.4 (Gold)
– Added baseDependency getter to AssetLoader
– New Wireframe regular polygon primitive
– Added getCenter() method to Bounds
– Updated geometry primitives to use scaleU and scaleV
– Code formatting and cleaning
– ASDoc updates in comments
– Updated Bounds to ignore lights
– Fix to unproject (closes #446)
– Add wrapPanAngle to FirstPersonController
– Fix to Wireframe geometry primitive properties and geometry updates
– Fix for runtime error when removing a lightpicker from a material with a shadow method
– Fix to GradientDiffuseMethod to stop material from disappearing when no lights are applied
– Get rid of compilation warnings in ViewVolume
– Fix for incorrect sorting with blended entities (Closes #605)
– Fix to Loader3D when automatically adding root objects to the scene from an AWD file
4.1.5
– Fix to SegmentSet bounds calculations. Closes #610
– Added support for new ATF format. Closes #615
– Fix to background image when using a scissorRect. Closes #622
– Optimisation to MD2 parser. Closes #631
– Fix to pitch/roll/yaw/rotate for scaled objects. Closes #626
– Fix on filter method for custom filterFunc. Closes #619
– Added support for 4096×4096 textures. Closes #647
4.1.6
– Memory optimisations for internal Matrix3D and Vector3D use
– Fix to zIndex calculation on Entities with non-root parent. Closes #659
– Fix for removing effects methods on a multipass material. Closes #671
– Updated context loss handling for views with 3D filters. Closes #669
– Corrected pivot point calculation for scaled meshes. Closes #650
– Fix for background texture renderer when using BlendMode on a Mesh. Closes #569
– Fix for controller using targets with non-root parent. Closes #377
– Compatibility fix for UV animation applied to a multipass material. Closes #553
– Stability update to StereoView3D. Closes #466
– Compatibility fix to calling Merge.apply() to meshes with lit materials. Closes #624
– Compatibility fix for SpriteSheetAnimator applied to materials with shadows enabled. Closes #617
– Enable doublesided meshes to be used with OutlineMethod. Closes #604
– Visual discrepancy fix between single pass and multipass materials when using fog effects method. Closes #596
– Fix to filtered shadow method when using cascading shadows
– Fix to segment set rendering when using 3d filters
– Fix to multipass material when using multiple point lights
– Added useSmoothingGroups option in 3DS parser to allow smoothing on files with no smoothing group data
– Fix for play method on animators to restart stopped animations when playing the same state
– Fix to duration property for non-looping animations
– Updates to AWD and 3DS parser to allow class instance reuse on multiple assets.