猫史档案馆


【岛三喵】谁不喜欢能随机飞行的蝴蝶呢?

用户:阳光的流熔怪Uyt5阳光的流熔怪Uyt5查看:7 回复:24 评论:7 创建时间:2022-03-10T00:15:04


center_image

center_image

//by 路人
//使用时请注明作者
console.clear()
obj = world.querySelector('#翅膀')
const ENTITY_QUAT = new Box3Quaternion(0, 0, 0, 1)
async function rotate(entity, t = 0, l = 1) {//代码报错的速度是秒速5厘米!
    entity.bounds = new Box3Vector3(1, 1, 3)
    entity.meshOrientation = entity.meshOrientation.rotateZ(t)
    while (true) {
        for (let i = 0; i <= 45; i++) {
            entity.rotate = l * (Math.PI / 180 * i * 1.3)
            await sleep(5)
        }
        for (let i = 45; i >= 0; i--) {
            entity.rotate = l * (Math.PI / 180 * i * 1.3)
            await sleep(5)
        }
    }
}
function asin(k) {
    return Math.asin(k) / Math.PI * 2
}
async function move(entity, entity1, pos, pos1) {
    entity.spos = new Box3Vector3(pos1.x - pos.x, pos1.y - pos.y, pos1.z - pos.z)
    //转化为原点到spos的角
    //压缩到xz平面上
    entity.db = entity.spos.z//对边
    entity.xb = Math.sqrt((entity.spos.z) * (entity.spos.z) + (entity.spos.x) * (entity.spos.x))
    entity.meshOffset = new Box3Vector3(0, 0, 1.8)
    entity1.meshOffset = new Box3Vector3(0, 0, 1.8)
    if (entity.spos.x >= 0) {//喵码警告
        if (entity.db / entity.xb >= 0) {
            entity.meshOrientation = ENTITY_QUAT.rotateY(Math.asin(entity.db / entity.xb)).rotateX(-1 * entity.rotate * asin(entity.db / entity.xb)).rotateZ(entity.rotate * (1 - asin(entity.db / entity.xb)))
            entity1.meshOrientation = ENTITY_QUAT.rotateY(-Math.asin(entity.db / entity.xb)).rotateZ(Math.PI).rotateX(entity.rotate * asin(entity.db / entity.xb)).rotateZ(-1 * entity.rotate * (1 - asin(entity.db / entity.xb)))
        }
        else {
            entity.meshOrientation = ENTITY_QUAT.rotateY(Math.asin(entity.db / entity.xb)).rotateX(entity.rotate * (asin(-entity.db / entity.xb))).rotateZ(entity.rotate * (1 - asin(-entity.db / entity.xb)))
            entity1.meshOrientation = ENTITY_QUAT.rotateY(-Math.asin(entity.db / entity.xb)).rotateZ(Math.PI).rotateX(-1 * entity.rotate * (asin(-entity.db / entity.xb))).rotateZ(-1 * entity.rotate * (1 - asin(-entity.db / entity.xb)))
        }
    }
    else {//哈哈,啊哈哈哈哈哈哈————bug来咯——————
        if (entity.db / entity.xb >= 0) {
            entity.meshOrientation = ENTITY_QUAT.rotateY(-Math.asin(entity.db / entity.xb) + Math.PI).rotateX(-1 * entity.rotate * asin(entity.db / entity.xb)).rotateZ(-1 * entity.rotate * (1 - asin(entity.db / entity.xb)))
            entity1.meshOrientation = ENTITY_QUAT.rotateY(Math.asin(entity.db / entity.xb) + Math.PI).rotateZ(Math.PI).rotateX(entity.rotate * asin(entity.db / entity.xb)).rotateZ(entity.rotate * (1 - asin(entity.db / entity.xb)))
        }
        else {
            entity.meshOrientation = ENTITY_QUAT.rotateY(-Math.asin(entity.db / entity.xb) + Math.PI).rotateX(entity.rotate * asin(-entity.db / entity.xb)).rotateZ(-1 * entity.rotate * (1 - asin(-entity.db / entity.xb)))
            entity1.meshOrientation = ENTITY_QUAT.rotateY(Math.asin(entity.db / entity.xb) + Math.PI).rotateZ(Math.PI).rotateX(-1 * entity.rotate * asin(-entity.db / entity.xb)).rotateZ(entity.rotate * (1 - asin(-entity.db / entity.xb)))
        }
    }
}
async function createWay(obj, obj1, seedx, seedy) {//代码比较喵,建议当模块使用
    obj.x = Math.sin(seedx / 114 * 514 / 4) * 32 + Math.cos(seedy / 810 * 1919) * 32 + 喵//生成较为平滑的随机数 好臭啊
    obj.y = 12 + Math.sin(seedx / 404 * 505) * 3
    obj.z = Math.cos(seedx / 996 * 1024) * 32 + Math.sin(seedy / 1919 * 1680) * 32 + 喵
    move(obj, obj1, obj.position, new Box3Vector3(obj.x, obj.y, obj.z))
    obj.position = new Box3Vector3(obj.x, obj.y, obj.z)
    obj1.position = new Box3Vector3(obj.x, obj.y, obj.z)
    //我们仍未知道那天所见bug的名字
}
async function fly(obj, obj1) {//Tips:你调试蓝了 你调试红了 你调试没了
    obj.meshEmissive = 1
    obj.meshShininess = 1
    obj.meshColor = new Box3RGBAColor(1, 1, 0, 1)
    obj1.meshEmissive = 1
    obj1.meshShininess = 1
    obj1.meshColor = new Box3RGBAColor(1, 1, 0, 1)
    obj.meshOrientation = ENTITY_QUAT
    obj1.meshOrientation = ENTITY_QUAT
    rotate(obj)
    rotate(obj1, Math.PI, -1)
    obj.seedx = Math.random() * Math.PI * 2
    obj.seedy = Math.random() * Math.PI * 2
    while (true) {
        createWay(obj, obj1, obj.seedx, obj.seedy)
        obj.seedx += 0.001
        obj.seedy -= 0.001
        await sleep(10)
    }
}
async function addFly() {
    for (let i = 0; i < 40; i++) {
        left = world.createEntity(obj)
        right = world.createEntity(obj)
        fly(left, right)
        // await sleep(1000)
    }
}
addFly()

代码费了我七天功夫,应该是最后的作品了

模型文件在过审,更新代码和模型会在置顶发


回复

上一页1 页 / 共 1下一页
时当日色QWQ时当日色QWQ

沙发

点赞1


评论


未名用户未名用户

哇!!

点赞0


评论


Stephan轩Stephan轩

地板)()

点赞0


评论


机敏的月见草VbEk机敏的月见草VbEk

前排

点赞0


评论


yee089yee089

qp

点赞0


评论


用户_869149用户_869149

啊啊啊路人复活了!!!!!!!!!!!!!!

点赞0


评论


用户_869149用户_869149

天花板!

点赞0


评论


云游box3der尖头叉子云游box3der尖头叉子

前排

点赞0


评论


阳光的流熔怪Uyt5阳光的流熔怪Uyt5

模型链接https://box3.fun/v/519107

点赞0


评论


nature君nature君

板凳(路人大佬活了!!!!)

点赞0


评论


墨染云天墨染云天

imgsrc="https://static.codemao.cn/emoji/codemao/%E7%BC%96%E7%A8%8B%E7%8C%AB_%E7%82%B9%E8%B5%9E.gif"alt="emotion_编程猫_点赞"

点赞0


评论


灵清帝王吃爆一切厕所灵清帝王吃爆一切厕所

我才发现原来岛三处处是大佬

点赞0


评论


阳光的流熔怪Uyt5阳光的流熔怪Uyt5

顶?

好熟悉的词语,我想不起来它的意思了

点赞0


评论


IaeaIaea

你这

点赞0


评论


阳光的流熔怪Uyt5阳光的流熔怪Uyt5

挖坟(?)毕竟花了七天功夫,质量也还可以

点赞0


评论


Star_Ink_sansStar_Ink_sans

收藏(喜)顺便纪念路人复活)

点赞0


评论


KeluoKeluo

收藏

点赞0


评论


无事勿扰111无事勿扰111

能弄个Python吗?

点赞0


评论


GZ006GZ006

路人活啦——

点赞0


评论


被遗忘的屑被遗忘的屑

挖,,

点赞0


评论


TAM无敌TAM无敌

哇哇哇哇哇哇

 

点赞0


评论


可小嘉可小嘉

emotion_编程猫_厉害了

点赞0


评论


无敌版滑稽战神无敌版滑稽战神

6!

点赞0


评论


阳光的流熔怪Uyt5阳光的流熔怪Uyt5

莫名其妙的被挖上来了?)之前的作品,诸位也可以看到代码冗长且意义不明。

如果我有空的话或许会重写一遍(立flag)

点赞1


评论