线条飞鸟动画-理解动画的三个关键变换-平移、缩放、旋转

下面是编程之家 jb51.cc 通过网络收集整理的代码片段。

编程之家小编现在分享给大家,也给大家做个参考。

-- main
-- Use this function to perform your initial setup
function setup()

    displayMode(FULLSCREEN)

    x = WIDTH/2
    y = HEIGHT/2
    img = sprite("Cargo Bot:Starry Background")

    -- 第一只 mesh 鸟 -- The 1st mesh bird  
    myMeshBird1 = mesh()
    
    -- 第二只 mesh 鸟 -- The 2nd mesh bird   
    myMeshBird2 = mesh()
    myMeshBird2.texCoords = {vec2(0,0),vec2(0,1),vec2(1,0)}
    myMeshBird2.texture = img

    -- 第三只 mesh 鸟 -- The 3rd mesh bird    
    myMeshBird3 = mesh()

    -- 用于控制循环的变量 -- variable for loop control    
    i,j = 0,0
    k = 1
    m,n = 1000,1
    a,b = 255,1
       
    parameter.integer("i",150,0)
    parameter.integer("j",0)   
    parameter.integer("k",-1,1,1)
    parameter.integer("m",2000,1000)  
    parameter.integer("n",-5,5,1)
    parameter.integer("a",255,255)  
    parameter.integer("b",1)    
    
    parameter.integer("l1",100,300,200)
    parameter.integer("h1",200)    
    parameter.integer("l2",10,200,60)
    parameter.integer("h2",10)    

    -- 三只对象实例鸟 -- Three object instance birds
    myBird1 = Bird(x,y)
    myBird2 = Bird(x+50,y)
    myBird3 = Bird(x,y)
end

-- This function gets called once every frame
function draw()
    
    -- 用来设置颜色渐变效果 -- Color alpha control    
    -- Alpha channel has a maximum of 255
    local alpha = math.min(ElapsedTime * 20%255,255) 
    -- Set tint using tint(grey,alpha)
    tint(255,alpha)                              
    
    -- 用 tint() 函数控制色彩透明度变化 -- Use tint()
    if alpha == 255 then 
        tint(0,alpha)
    elseif alpha == 50 then 
        tint(255,alpha) 
    end    
        
    -- 控制翅膀坐标变化 -- control change of wings' coords  
    -- 若 i 达到最大值,则把步长 k 设置为 -1,i + k 值会递减 -- when i become max,set step k to -1,i+k will decrease
    -- 若 i 达到最小值,则把步长 k 设置为 1,i + k 值会递增  -- when i become min,set step k to 1,i+k will increase 
    -- 当 i 最大时调用声音,以保证声音和动作同步   -- load sound while i become max,to make sure sound and motion synchronize
    if i == 150 then
        k = -1
        sound("A Hero's Quest:Walk 2 (Short)")
    elseif i == 0 then 
        k = 1
    end
    
    -- 控制缩放 -- contrl scale 
    if m == 1500 then n = -1 elseif m == 0 then n = 1 end
    
    -- 用变量 a,b 直接控制色彩透明度变化 -- use variable a,b to control change of color's alpha directly
    if a == 255 then b = -1 elseif a == 50 then b = 1 end
    
    -- 开始递增或递减 -- start increase or decrease
    i = i + 5 * k
    j = j + 8 * k
    m = m + 2 * n
    a = a + b 
    
    -- 设置背景色 -- set background color 
    background(11,11,86)
    
    -- 设置背景参照物 -- set background object 
    pushStyle()
    pushMatrix()
    -- scale(m/500,m/500)
    -- translate(-m,m)
    fill(255,alpha)
    stroke(255,118,alpha)
    ellipse(500,1250-m,m-350)
    popMatrix()
    popStyle()
    
    -- 用于三只 mesh 鸟的颜色 -- colors of three mesh birds 
    myColor1 = color(255,alpha)
    myColor2 = color(79,a)
    myColor3 = color(79,2,a)    
    
    -- 构成飞鸟线条的顶点坐标 -- vertex coords of bird line 
    -- vec2 向量 p1(0,0) 为中心点提供坐标 -- vec(0,0) is the central point 
    p1 = vec2(0,0)
    -- 组成右边翅膀的顶点 -- vertices of right wing 
    -- p2,p3 = vec2(200+i/8,-150+2*j),vec2(60-i/3,10+j/3)
    p2,p3 = vec2(l1+i/8,vec2(l2-i/3,h2+j/3)
    -- 组成左边翅膀的顶点 -- vertices of left wing 
    -- p4,p5 = vec2(-200-i/8,vec2(-60+i/3,10+j/3)
    p4,10+j/3)
    
    -- 用这些坐标设置 mesh 的顶点 -- set mesh vertices 
    myMeshBird1.vertices = {p1,p2,p3,p1,p4,p5}
    myMeshBird2.vertices = {p1,p5}    
    myMeshBird3.vertices = {p1,p5}    
        
    -- 平移 
    translate(3*x/4,3*y/4)
    
    -- 整体循环缩放全部飞鸟比例,产生鸟群距离变化的感觉 -- total birds loop scale,to feel birds distance changing 
    scale(m/1500)
    
    -- 直接用 line() 函数画的飞鸟 -- use line() draw bird directly
    pushMatrix()     
    pushStyle()
    translate(x/2,y)   
    scale(3)
    stroke(0,39,255)
    strokeWidth(5)

    -- 右边翅膀线条 -- lines of right wing 
    line(p1[1],p1[2],p2[1],p2[2])
    line(p1[1],p3[1],p3[2])
    line(p3[1],p3[2],p2[2])
    -- 左边翅膀线条 -- lines of right wing
    line(p1[1],p4[1],p4[2])
    line(p1[1],p5[1],p5[2])
    line(p4[1],p4[2],p5[2])    
    -- 用文字标出飞鸟的编号 -- print bird's No.
    fill(0,51,255)
    -- text("零号鸟",p1[1],p1[2])
    text("1",p1[2])       
    popStyle()
    popMatrix()
    
    -- 用 class Bird 绘制的对象实例鸟 -- object instance bird drawing with class Bird 
    pushMatrix()
    pushStyle()
    -- myBird.deltaX = myBird.deltaX + 5*k
    -- myBird.deltaY = myBird.deltaY + 5*k
    rotate(m)
    scale(0.2)
    myBird1:setColors(myColor)
    myBird1:draw()   
    popStyle() 
    popMatrix()

    -- 用 class Bird 绘制的对象实例鸟 -- object instance bird drawing with class Bird 
    pushMatrix()
    pushStyle()
    rotate(-m)
    scale(0.3)
    myBird2:setColors(myColor)
    myBird2:draw()   
    popStyle() 
    popMatrix()

    -- 用 class Bird 绘制的对象实例鸟 -- object instance bird drawing with class Bird 
    pushMatrix()
    pushStyle()
    rotate(-m)
    scale(0.3)
    myBird3:setColors(myColor2)
    myBird3:draw()   
    popStyle() 
    popMatrix()
    
    -- 用 mesh 绘制的一号飞鸟 -- No.1 mesh bird 
    pushMatrix()
    pushStyle()
    translate(-x/4,-y/2)
    scale(.8)
    myMeshBird1:setColors(myColor1)
    -- myMeshBird1.shader.time = ElapsedTime*5
    myMeshBird1:draw()
    -- 用文字标出飞鸟的编号  -- print bird's No.      
    fill(173,255)
    -- text("一号鸟",p1[2])    
    popStyle()
    popMatrix()
    
    -- 用 mesh 绘制的二号飞鸟 -- No.1 mesh bird 
    pushMatrix()
    pushStyle()
    translate(300,200)
    scale(.5)
    myMeshBird2:setColors(myColor2)
    myMeshBird2:draw()
    -- 用文字标出飞鸟的编号  -- print bird's No. 
    fill(63,218,26,255)
    -- text("二号鸟",p1[2])
    text("2",p1[2])        
    popStyle()    
    popMatrix()
    
    -- 用 mesh 绘制的三号飞鸟 -- No.1 mesh bird 
    pushMatrix()
    pushStyle()
    translate(30,80)
    scale(2)
    myMeshBird3:setColors(myColor3)
    myMeshBird3:draw()
    -- 用文字标出飞鸟的编号  -- print bird's No.   
    fill(218,25,197,255)
    -- text("三号鸟",p1[2])
    text("3",p1[2])        
    popStyle()    
    popMatrix()
        
end

-- Bird class
Bird = class()

function Bird:init(x,y)
    -- you can accept and set parameters here
    -- 最初的位置坐标 -- bird's position
    self.x = x
    self.y = y
    -- 最初的坐标偏移量 -- bird's offset 
    self.deltaX = 0
    self.deltaY = 0 
    
    self.i1,self.j1 = 0,0
    self.k1 = 1 
          
    flag = mesh()   
    
    myColor = color(55,172,255)
    Bird:setColors(myColor) 
end

function Bird:draw()
    -- Codea does not automatically call this method
    
    if self.i1 == 150 then
        self.k1 = -1
    elseif i == 0 then 
        self.k1 = 1
    end
    
    self.i1 = self.i1 + 5 * self.k1
    self.j1 = self.j1 + 8 * self.k1
        
    self.deltaX = self.i1
    self.deltaY = self.j1
    
    flag.vertices = {
        vec2(self.x,self.y),vec2(self.x + 200 - self.deltaX/8,self.y - 150 + self.deltaY * 2),vec2(self.x + 60 - self.deltaX/3,self.y + 10+self.deltaY/3),vec2(self.x,vec2(self.x - 200 + self.deltaX/8,vec2(self.x - 60 + self.deltaX/3,self.y + 10 + self.deltaY/3),}
    -- Bird:setColors(myColor)
    fill(24,201,255)
    -- text("对象鸟",self.x,self.y)
    text("Object Instance Bird",self.y)        
    flag:draw()    
end

function Bird:setColors(colors)
    flag:setColors(colors)
end

function Bird:touched(touch)
    -- Codea does not automatically call this method
end

以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


1.github代码实践源代码是lua脚本语言,下载th之后运行thmain.lua-netTypevgg-savevgg_cifar10/-S0.0001,报错: 试看看安装lua:报错了,参考这篇文章:ubuntu18.04安装lua的步骤以及出现的问题_weixin_41355132的博客-CSDN博客问题解决,安装成功:情况并没有好转,出现相
此文为搬运帖,原帖地址https://www.cnblogs.com/zwywilliam/p/5999924.html前言在看了uwa之前发布的《Unity项目常见Lua解决方案性能比较》,决定动手写一篇关于lua+unity方案的性能优化文。整合lua是目前最强大的unity热更新方案,毕竟这是唯一可以支持ios热更新的办法。然而作
Rime输入法通过定义lua文件,可以实现获取当前时间日期的功能。1.TIMERime是一款可以高度自定义的输入法,相关教程可以查看往期文章,关于时间获取是指输入一个指定关键字,输出当前时间,效果如下(我定义了time关键字):实现如下:①在用户文件夹中新建一个rime.lua文件加入如下代码 ti
localfunctiongenerate_action(params)localscale_action=cc.ScaleTo:create(params.time,params.scale_x,params.scale_y)localfade_action=cc.FadeIn:create(params.time)returncc.Spawn:create(scale_action,fade_action)end
2022年1月11日13:57:45 官方:https://opm.openresty.org/官方文档:https://opm.openresty.org/docs#table-of-contents为什么建议使用opm不建议使用luarocks?http://openresty.org/cn/using-luarocks.html官方解释:请注意!LuaRocks并不是OpenResty官方推荐的装包方式。LuaRoc
在Lua中的table(表),就像c#中的HashMap(哈希表),key和value一一对应。元表:table的一个操作的拓展,里面包含关联了对应的方法,元方法就是其中一个。元方法:当你通过键来访问table的时候,如果这个键没有值,那么Lua就会寻找该table的metatable(假定有metatable)中的__index键。如果__inde
表排序:table.sort(list[,comp])参数list:指定表,可选参数comp:排序函数,无参数时通常按升序排序。排序函数针对表中连续的序列,其间不可以存在空洞或nil,排序函数需要两个形参(对应表中每次参加比较的两个数据),需要一个比较两个形参表达式的返回值,不能含有等于关系,例如>=,<=,==。do
一、安装lua环境1.1安装依赖包[root@centos7~]#yuminstallgccreadline-devel1.2下线lua源码包并解压[root@centos7~]#wgethttp://www.lua.org/ftp/lua-5.3.5.tar.gz[root@centos7~]#tarxvflua-5.3.5.tar.gz-C/usr/local/src1.3进行编译[root@centos7~]
官网OpenResty® 是一个基于 Nginx 与Lua的高性能Web平台,其内部集成了大量精良的Lua库、第三方模块以及大多数的依赖项。用于方便地搭建能够处理超高并发、扩展性极高的动态Web应用、Web服务和动态网关。OpenResty® 通过汇聚各种设计精良的 Nginx 模块(主要由
表参考《lua程序设计》可以认为,表是一种动态分配的对象,程序只能操作指向表的引用(或指针)。除此以外,Lua语言不会进行隐藏的拷贝(hiddencopies)或创建新的表--创建表a={}--创建空表k="x"a[k]=10--键“x”值10a[20]="great"--键20值“great”print(a["x"])-->10
https://github.com/galenho/crossover.git一个跨平台的lua游戏服务器开发框架,该框架采用多线程并发来处理消息,开发者只需要调用相应的接口函数并绑定相应的回调函数即可,在逻辑层表现为单线程的开发模式,使开发者易用,易调试,易维护,易扩展,同时拥有快速的响应能力。   框架使用面
参考链接:https://www.runoob.com/lua/lua-metatables.htmlhttps://www.jianshu.com/p/cb945e7073a3 元表是一个table,可以让我们改变table的行为,每个行为有对应的元方法例如,对table进行设置键值,查找键值,运算等,就会触发对应的元方法1--__index:table被访问时,如果找不到这
https://github.com/yuin/gopher-luahttps://github.com/yuin/gopher-lua Lua5.1ReferenceManual-contentshttp://www.lua.org/manual/5.1/ go中使用luapackagemainimport( lua"github.com/yuin/gopher-lua")funcmain(){ l:=lua.NewState() d
编译问题不要留到运行时才跑出来啊。早上9:00-中午3:00,6个小时,服了自己了。 写了一个测试,springboot+redis+lua执行到redisTemplate.execute(redisScript,idList)的时候一直报错,integer无法转换为string。我一直以为是lua脚本写错了,翻文档翻过来又翻过去,写法变了又变,还是解
        。。是字符串连接符,字典用=号连接,  注意fordoend都是连一起,  注意ifthen,  如果local在函数里,是可以访问,非local出了函数一样能用,  doend代码块也是一样,    注意点号表示,只能key是字符串,  注意括号不是必须
C语言与Lua之间的相互调用详解写一个C调用Lua的Demo编译运行C语言调用Lua编译问题总结正确的编译命令问题1:缺少-lm参数问题2:缺少-ldl参数​1、为什么会出现undefinedreferenceto‘xxxxx’错误?​2、-l参数和-L参数写一个C调用Lua的Demo编译运行add.c内容//你需要
1、动态输出打开E:\study\openresty\openresty-1.19.9.1-win64目录下的confginx.conf文件在server中增加一下代码 location/hello{ default_typetext/html; content_by_lua'ngx.say("<p>hello,world</p>")'; }运行后,效果如下图localhost
参见:lipp/lua-websockets:WebsocketsforLua.(github.com)github网址可能需手动转换lipp.github.com/lua-websockets/>github.com/lipp/lua-websocketswebsockets为底层的类似于TCP、UDP的socket(实现上基于更底层的socket),不同于上层的webserver服务端(Service)需并行地支持多
lua发送消息到rabbitmq,我们选择类库lua-resty-rabbitmqstomp 来完成这个任务。类库安装:进入nginx.conf中 lua_package_path 中对应的目录下的resty目录(没有则创建),执行:wget-chttps:/aw.githubusercontent.com/wingify/lua-resty-rabbitmqstomp/master/libes
1Lua介绍Lua是一门以其性能著称的脚本语言,被广泛应用在很多方面。Lua一般用于嵌入式应用,现在越来越多应用于游戏当中,魔兽世界,愤怒的小鸟都有用到。优势Lua极易嵌入到其他程序,可当做一种配置语言。提升应用性能,比如:游戏脚本,nginx,wireshark的脚本兼容性强,可以直接使用C