小学科学教学论坛

首页 » 小学科学教学论坛 » AI赋能 » 【AI科学助教】光的反射与折射动画
徐玉红 - 2025/3/29 21:30:40
https://chat.deepseek.com/

豆包 或 deep seek


给AI
科学助教发任务:
做一个光的反射和折射演示动画,通过调整入射角,可以改变反射角和折射角,以html结构为答案



240692

成功了!直接领走https://www.doubao.com/share/code/3ede0ce09896e83d
徐玉红 - 2025/3/29 21:31:58

点一下执行,调整入射角很丝滑,感觉缺少标注

240693
徐玉红 - 2025/3/29 21:33:53

指令:在入射光线、反射光线和折射光线上标注方向,在旁边标注名称

结果出来一个无法显示的,让他自我反省


又出来一个叛逆的!


240694
徐玉红 - 2025/3/29 21:35:28
再次调整,终于好了,还自带3种物质的折射率与变化!伙伴们看看还可以怎么完善?

240695
240696
嘉琳 - 2025/3/29 21:56:50
让它自我反省的时候你是怎么提示的?
喻伯军 - 2025/3/29 22:50:58
自我反省很有意思。
徐玉红 - 2025/3/29 23:15:29
回复 5楼嘉琳的帖子

告诉他出现什么问题,自己检查代码,我希望它达到什么效果
董敏尔 - 2025/3/29 23:49:47
画出法线会不会更直观
秋清 - 2025/3/30 9:48:53
你已经用得很丝滑了!
一剑飘香 - 2025/3/30 10:18:06
“AI科学助教”我没有用过,感觉对我们科学教学很有帮助。
徐玉红 - 2025/3/30 10:44:04
回复 8楼董敏尔的帖子

好主意👍
徐玉红 - 2025/3/30 10:44:17
回复 10楼一剑飘香的帖子

我自己编的:default6:
胡璐佳 - 2025/3/30 11:28:30

240718
胡璐佳 - 2025/3/30 11:29:18
现学现用,这个可太好用啦,就是下载的代码,要放到哪里去会生成这个程序呢?
金亚军 - 2025/3/30 11:49:01
这些功能需会员的吧。
陈晶晶 - 2025/3/30 13:25:53
这个可以,在想使用的时候是不是录屏保存下来,哈哈
柚子茶 - 2025/3/30 14:44:18
好方法,真棒
冥王星 - 2025/3/30 15:02:12
这个反复思考,需要不断和他讲述出现问题的地方,然后让他不断改进,是这样吗?
沈亚娟 - 2025/3/30 16:06:13
Ai助教科学课,你用的炉火纯青啦
370558447 - 2025/3/30 19:31:48
AI是非常好的工具啊
虞芳子 - 2025/3/30 19:41:13
与时俱进,将ai科学合理地融入教学中
李煜鋆 - 2025/3/30 19:52:19
看到了好几个帖子,看来徐老师是AI科学的领跑者。
恋泉 - 2025/3/30 19:56:29
Ai确实方便很多,还能帮我们作图。
曹文佳 - 2025/3/30 19:59:43
现学现用,这个可太好用啦,就是下载的代码,要放到哪里去会生成这个程序呢?
胡璐佳 发表于 2025/3/30 11:29:18
同问
永康 吕梦婕 - 2025/3/30 20:23:42
是AI 小导师了
王丽洁 - 2025/3/30 20:51:22
信息技术水平也要过硬呀
徐玉红 - 2025/3/30 20:53:05
回复 18楼冥王星的帖子

完全正确
徐玉红 - 2025/3/30 20:53:56
根据8楼董老师的建议,进行了改进这样好多了!




    
        .container {
            display: flex;
            align-items: flex-start;
            gap: 20px;
        }
        canvas {
            border: 1px solid #ccc;
            background: #fff;
        }
        .controls {
            display: flex;
            flex-direction: column;
            gap: 10px;
        }
        .angle-display {
            margin-top: 10px;
        }
    


    <div class="container">
        
        <div class="controls">
            入射角调整:
            
            <div class="angle-display">
                当前入射角:<span>30</span>°
            </div>
        </div>
    </div>

    
        const canvas = document.getElementById('canvas');
        const ctx = canvas.getContext('2d');
        const slider = document.getElementById('angleSlider');
        const angleValue = document.getElementById('angleValue');

        // 介质参数
        const n1 = 1.0;          // 空气折射率
        const n2 = 1.33;         // 水折射率
        const interfaceY = 300;  // 界面位置
        const rayLength = 150;   // 光线长度
        const normalX = 300;     // 法线X坐标

        function drawArrow(x1, y1, x2, y2, label, color) {
            // 画光线
            ctx.beginPath();
            ctx.moveTo(x1, y1);
            ctx.lineTo(x2, y2);
            ctx.strokeStyle = color;
            ctx.lineWidth = 2;
            ctx.stroke();

            // 画箭头
            const angle = Math.atan2(y2 - y1, x2 - x1);
            ctx.beginPath();
            ctx.moveTo(x2, y2);
            ctx.lineTo(x2 - 10 * Math.cos(angle - Math.PI/6), y2 - 10 * Math.sin(angle - Math.PI/6));
            ctx.lineTo(x2 - 10 * Math.cos(angle + Math.PI/6), y2 - 10 * Math.sin(angle + Math.PI/6));
            ctx.fillStyle = color;
            ctx.fill();

            // 写标签(沿光线方向偏移)
            ctx.fillStyle = color;
            ctx.font = "14px Arial";
            const labelX = (x1 + x2)/2 + 15 * Math.cos(angle);
            const labelY = (y1 + y2)/2 + 15 * Math.sin(angle);
            ctx.fillText(label, labelX, labelY);
        }

        function draw() {
            ctx.clearRect(0, 0, canvas.width, canvas.height);

            // 填充水介质区域(淡蓝色)
            ctx.fillStyle = 'rgba(173, 216, 230, 0.2)';
            ctx.fillRect(0, interfaceY, canvas.width, canvas.height - interfaceY);

            // 画界面
            ctx.beginPath();
            ctx.moveTo(0, interfaceY);
            ctx.lineTo(canvas.width, interfaceY);
            ctx.setLineDash([5, 5]);
            ctx.strokeStyle = "#666";
            ctx.stroke();
            ctx.setLineDash([]);

            // 画法线
            ctx.beginPath();
            ctx.moveTo(normalX, interfaceY - 100);
            ctx.lineTo(normalX, interfaceY + 100);
            ctx.strokeStyle = "#999";
            ctx.stroke();
            ctx.fillStyle = "#666";
            ctx.fillText("法线", normalX + 10, interfaceY - 50);

            const theta = slider.value * Math.PI / 180;
            const endpointX = normalX; // 入射点X坐标
            const endpointY = interfaceY; // 入射点Y坐标

            // 入射光线(法线左侧)
            const startX = endpointX - rayLength * Math.sin(theta);
            const startY = endpointY - rayLength * Math.cos(theta);
            drawArrow(startX, startY, endpointX, endpointY, "入射光线", "red");

            // 反射光线(法线右侧)
            const reflectX = endpointX + rayLength * Math.sin(theta);
            const reflectY = endpointY - rayLength * Math.cos(theta);
            drawArrow(endpointX, endpointY, reflectX, reflectY, "反射光线", "blue");

            // 折射光线(法线右侧下方)
            const sinTheta2 = (n1/n2) * Math.sin(theta);
            if (sinTheta2  {
            angleValue.textContent = slider.value;
            draw();
        });

        draw(); // 初始绘制
    



240761
孙萌 - 2025/3/30 20:58:32
太棒了,感谢老师分享
徐玉红 - 2025/3/30 20:59:15
豆包
感觉是书呆子,听不懂科学语言,有两个问题一致改不过来!

240765


deep seek
感觉是学霸,在思考过程中可以看出,都是有科学理论作为基础来推论的!


240766
123456
查看完整版本: 【AI科学助教】光的反射与折射动画