Bipes项目二次开发/海龟编程(六)

Bipes项目二次开发/海龟编程(六)

海龟编程,之前是有出过一期blog.csdn.net/weixin_4485... ,这次我将这个功能加到项目里面,前端python还是用skulpt.js。接下看我操作。

第一:配置

配置加了新模式,海龟编程。选择海龟编程后,运行按钮,将会运行海龟画图功能。 skulpt-controller代码改动

cpp 复制代码
// 新增画图输出
(Sk.TurtleGraphics || (Sk.TurtleGraphics = {})).target = 'draw-canvas'
window.Sk.TurtleGraphics.width = 600
window.Sk.TurtleGraphics.height = 600

// 新增运行海龟函数
runSkulptCode() {
        let code = Code.generateCode()
        let myPromise = this.sk.misceval.asyncToPromise(() => {
            return this.sk.importMainWithBody("<stdin>", false, code, true);
        })

        myPromise
            .then((res) => {})
            .catch((err) => {})
}

第二:静态页面

cpp 复制代码
<div class="draw-preview">
    <div class="draw-header">
      <span class="draw-header-left">海龟图</span>
      <div class="header-right">
        <img class="draw-close" src="./media/new-icon/close.png" title="关闭海龟">
      </div>
    </div>
    <div class="draw-content">
      <div id="draw-canvas" style="width: 600px; height: 600px;"></div>
    </div>
</div>

第三:js引用

cpp 复制代码
import Common from "./common";
import EventEmitterController from '../utils/event-emitter-controller'
import DragController from '../utils/drag-controller'

export default class DrawPreview extends Common {
    constructor() {
        super()
        // 创建拖拽容器
        this.element = new DragController(
            document.getElementsByClassName('draw-preview')[0],
            {
                minWidth: 400,
                minHeight: 400,
                maxWidth: 600,
                maxHeight: 600
            },
            'draw',
            (params) => {
                let { newWidth, newHeight } = params
                $('#draw-canvas').css({
                    width: newWidth + 'px',
                    height: newHeight - 52 + 'px'
                })
                window.Sk.TurtleGraphics.width = newWidth
                window.Sk.TurtleGraphics.height = newHeight - 52
                // console.log(params)
            }
        )

        this.state = false

        EventEmitterController.on('draw-preview-change', (state) => {
            this.changeCode(state)
        })
    }
    initEvent() {
        $('.draw-close').on('click', () => {
            this.changeCode(false)
        })
    }
    // 显示隐藏预览区
    changeCode(state) {
        $('.draw-preview').css('visibility', (state ? 'visible' : 'hidden'))
        this.state = state
    }
}

第四:效果

总结

这期的改动的代码也不多,不过现在项目会存在功能相互矛盾的地方,后期打算规划一下,让对应模式下,显示对应的功能模块。海龟编程其实也是挺有意思的,后期也打算出一些demo案例,放在目录里面。

相关推荐
CappuccinoRose几秒前
CSS、Less、Sass(含 SCSS)、Stylus
前端·css·less·sass·stylus
不听话坏9 小时前
Ignition篇(下 一) 动态执行前的事情
开发语言·前端·javascript
likeyi079 小时前
require 和 import的区别
开发语言·前端
pany9 小时前
做 AI 友好的开源 Vue3 模板 🌈
前端·vue.js·ai编程
小二·10 小时前
React 19 + Next.js 15 现代前端开发实战:App Router / Server Components / 流式渲染
前端·javascript·react.js
谙忆102411 小时前
前端图片直传对象存储:OSS/S3 预签名 URL、STS 临时凭证与回调校验
前端
CHNE_TAO_EMSM12 小时前
Android studio 打开文件时自动下载源码
前端·javascript·android studio
一孤程13 小时前
Airtest自动化测试第五篇:小程序与Web测试——跨平台自动化全覆盖
前端·自动化测试·小程序·自动化·测试·airtest
IT_陈寒13 小时前
SpringBoot自动配置不是你以为的那样的智能
前端·人工智能·后端
yume_sibai14 小时前
大屏数据可视化 - 边框红绿呼吸灯实现详解
前端·信息可视化·typescript