- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 Flash(AS3) 新手,这只是我的一个小实验。
我正在尝试变形通过网络摄像头捕获的图像。网络摄像头快照部分已经在工作,但我仍然不知道如何进行变形部分。任何人都可以向我指出如何使用 flash actionscript 3 实现图像变形的教程(或请发布代码示例)?
可以找到我试图实现的变形示例 here .谢谢。
最佳答案
几年前,我需要类似的东西。幸运的是,Grant Skinner 已经开发出来 camgoo .
从那时起,我仍然拥有快速而肮脏的端口。
注意:您将需要库中包含要变形的图像的 MovieClip,链接为 Img,以及链接为 Brush 的画笔 MovieClip。最简单的入门方法是从 Grant Skinner 的网站上的原始 as2 源中获取符号,将它们放在 as3 文档中,并在适当的位置使用 Morph 类,只需尝试类似 的内容。 addChild(new Morph());
代码根本没有优化,它是一个非常快速和文字的端口。 actionscript-3 功能在它们最好的时候没有使用:
package
{
import flash.display.*;
import flash.events.*;
import flash.geom.*;
import flash.filters.*;
/**
* @author Grant Skiner - original code: http://incomplet.gskinner.com/index2.html#camgoo
* @author port - George Profenza
*/
public class Morph extends Sprite
{
private var rect:Rectangle;
private var mapBmp:BitmapData;
private var blurredMapBmp:BitmapData;
private var blurF:BlurFilter;
private var pt:Point;
private var dispMapF:DisplacementMapFilter;
// holder for transient values (ex. during drag, animation)
private var tmp:Object;
private var mapHolder:MovieClip;
private var debugBitmap:Bitmap;
private var img:MovieClip;
private var brush:MovieClip;
private var isAnimating:Boolean = false;
private var btn:Sprite;
private var btn2:Sprite;
public function Morph()
{
init();
}
private function init():void
{
trace('init');
img = new Img();
addChild(img);
brush = new Brush();
brush.scaleX = brush.scaleY = .75;
addChild(brush);
mapHolder = new MovieClip();
addChild(mapHolder);
debugBitmap = new Bitmap(new BitmapData(img.width, img.height, false, 0x808080));
debugBitmap.alpha = 0;
mapHolder.addChild(debugBitmap);
rect = new Rectangle(0,0,Math.floor(img.width),Math.floor(img.height));
pt = new Point(0,0);
// set up bitmaps:
mapBmp = new BitmapData(rect.width,rect.height,false,0x808080);
blurredMapBmp = mapBmp.clone();
// set up filters:
blurF = new BlurFilter(8,8,2);
dispMapF = new DisplacementMapFilter(blurredMapBmp, pt,BitmapDataChannel.RED, BitmapDataChannel.GREEN, 100, 100, DisplacementMapFilterMode.CLAMP);
brush.visible = false;
this.addEventListener(MouseEvent.MOUSE_DOWN, startGoo);
btn = new Sprite();
btn.graphics.beginFill(0);
btn.graphics.drawRect(0, 0, 50, 50);
btn.graphics.endFill();
btn.visible = false;
addChild(btn);
btn.addEventListener(MouseEvent.CLICK, onAnimClick);
btn2 = new Sprite();
btn2.graphics.beginFill(0);
btn2.graphics.drawRect(0, 0, 50, 50);
btn2.graphics.endFill();
btn2.y = btn.height + 5;
btn2.visible = false;
addChild(btn2);
btn2.addEventListener(MouseEvent.CLICK, endAnimate);
}
private function onAnimClick(e:MouseEvent):void
{
isAnimating = true;
animateGoo();
}
private function startGoo(e:MouseEvent):void{
tmp = { oldx:mouseX, oldy:mouseY };
this.addEventListener(MouseEvent.MOUSE_UP, endGoo);
this.addEventListener(MouseEvent.MOUSE_MOVE, gooify);
}
private function endGoo(e:MouseEvent):void{
tmp = null;
this.removeEventListener(MouseEvent.MOUSE_UP, endGoo);
this.removeEventListener(MouseEvent.MOUSE_MOVE, gooify);
}
private function clearGoo():void {
mapBmp.fillRect(rect,0x808080);
blurredMapBmp.fillRect(rect,0x808080);
applyMap();
}
private function gooify(e:MouseEvent):void{
var dx:Number = mouseX-tmp.oldx;
var dy:Number = mouseY-tmp.oldy;
tmp = {oldx:mouseX,oldy:mouseY};
brush.rotation = (Math.atan2(dy, dx)) * 180 / Math.PI;
brush.x = mouseX;
brush.y = mouseY;
var g:Number = 0x80+Math.min(0x79,Math.max(-0x80, -dx*2 ));
var b:Number = 0x80+Math.min(0x79,Math.max(-0x80, -dy*2 ));
var ct:ColorTransform = new ColorTransform(0,0,0,1,0x80,g,b,0);
mapBmp.draw(brush,brush.transform.matrix,ct,BlendMode.HARDLIGHT);
applyMap();
}
private function applyMap() {
blurredMapBmp.applyFilter(mapBmp, rect, pt, blurF);
img.filters = [dispMapF];
}
private function animateGoo():void {
removeEventListener(MouseEvent.MOUSE_DOWN, startGoo);
addEventListener(MouseEvent.MOUSE_DOWN, endAnimate);
addEventListener(Event.ENTER_FRAME, animate);
tmp = {count:100,dir:-4,scale:dispMapF.scaleX}
}
private function animate(e:Event):void {
tmp.count+=tmp.dir;
if (tmp.count >= 100 || tmp.count <= 0) { tmp.dir *= -1; }
dispMapF.scaleX = dispMapF.scaleY = tmp.count / 100 * tmp.scale;
applyMap();
}
private function endAnimate(e:MouseEvent):void {
isAnimating = false;
removeEventListener(MouseEvent.MOUSE_DOWN, endAnimate);
removeEventListener(Event.ENTER_FRAME, animate);
addEventListener(MouseEvent.MOUSE_DOWN, startGoo);
tmp = null;
dispMapF = new DisplacementMapFilter(blurredMapBmp, pt,BitmapDataChannel.RED, BitmapDataChannel.GREEN, 100, 100, DisplacementMapFilterMode.CLAMP);
applyMap();
}
public function set anim(value:Boolean):void {
value ? btn.dispatchEvent(new MouseEvent(MouseEvent.CLICK)) : btn2.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
isAnimating = value;
}
public function get anim():Boolean {
return isAnimating;
}
}
}
关于actionscript-3 - 现在是吗啡时间! (AS3 中的图像变形),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3254409/
在 ActionScript 中深度克隆对象的最佳方法是什么? 最佳答案 执行此操作的最佳方法是将 ByteArray 与方法 writeObject 一起使用。像这样: function clone
我有以下问题:我从用户那里获取日期(作为字符串数据类型)。现在,我想知道 actionscript 中是否有一个函数可以将其转换为日期格式。现在,我只是解析字符串并将各个部分连接在一起。即: chan
我想知道是否有任何简单的方法可以通过使用某种应用程序(例如 ruby 的 irb 或 javasctip spidermonkey)来测试 actionscript,您只需打开终端并立即输入代码即
我没有特定的代码示例,但是有没有通用的方法来猜测代码片段是什么版本的 Actionscript:1 或 2 或 3? 我在某处读到,如果它是时间线中的代码,则它被认为是 Actionscript 1。
版本之间的主要区别是什么? 最佳答案 除了库更改之外,Actionscript 3 还针对完全不同的虚拟机 (AVM2) 进行编译和运行,该虚拟机是从头开始重新编写的。据报道,它执行编译的 AS3 代
我需要一点帮助来了解类在Actionscript 3中的工作方式。我理解您从“包”开始,然后为什么要导入任何必需的库,然后命名该类并说明它是公共/私有还是扩展任何内容。 在那之后,我不明白。看来您写的
我对以下语句有疑问 trace(Number("1/2")) //output NaN 但 trace(Number("1.2")) //output 1.2 所以,我有点困惑,为什么第一个语句没有给
当我的目标是 10.3 及更高版本时,此代码在 actionscript 3 中工作正常,但是当我的目标是 Flash Player 9 时,它给了我错误场景 1, 第 1 层,第 1 帧,第 7 行
我开始学习Flex和ActionScript,并遇到了有趣的陈述:无类型变量。那是: var x:*; 要不就 var x; 我发现它们可以保存undefined值。不能使用Object类型的变量。但
我不确定我的代码是否有问题或是否必须以不同的方式处理错误。我有一个Gear实例,另一个是bLine。齿轮落在线上时,我试图使两者同时运动。所以我在实例编码的内部是: var ev2:Event = n
我的问题基本上如下。有一个扩展 EventDispatcher 的类的实例。当我像这样向对象添加事件监听器时,一切顺利: myObject.addEventListener('eventName',
应该很容易。我有一个对象。我想修改它,但在修改之前我想保存它的副本以便我可以返回。我尝试设置副本=原始,但是当我修改原始的属性时,副本也会显示更改。我假设这是因为在 ActionScript 中任何时
如果我没有在代码中专门键入一个变量,它会编译为默认数据类型吗?例如,“for each ... in”函数在不输入变量的情况下效果最好: for each (var element in myArra
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,
我正在关注 hemanth sharma 关于 starling 框架的优秀教程系列。我或多或少地复制了他的代码,并对我想到的游戏进行了一些更改。代码与他在项目中使用的代码 80% 相同。尽管如此,我
我正在尝试构建一个基于 Web 的 Flash 应用程序。我对闪存很陌生。我想以两种形式开发它——演示版和付费版。要使此应用程序充当付费版本,我需要某种序列号。为了实现这一目标,我用谷歌搜索并遇到了类
我正在尝试编写一个简单的 as3 绘图类,但它不起作用。甚至没有触发事件。可能是什么问题? 用法: var drawingBoard:Drawing = new Drawing(); drawingB
有没有可以从Action Script代码自动生成类图的工具? 最佳答案 我刚刚搜索谷歌并很快找到,http://seantheflexguy.com/blog/2007/11/20/actionsc
我正在开发一款小型联网 Flash 游戏。我有自己的 C/Linux 内置服务器,我通过闪存套接字连接到服务器。我正在争论是否将游戏逻辑的重载放在客户端或服务器上。主要担心的是有人破解了代码并破坏了其
跟踪 mouseX / mouseY 时或 localX / localY显示对象的坐标,为什么x从 1 开始,而 y从 0 开始? 例如,我用 MouseEvent.MOUSE_MOVE 在舞台上绘
我是一名优秀的程序员,十分优秀!