小学科学教学论坛

注册

 

发新话题 回复该主题

【AI科学助教】光的反射与折射动画 [复制链接]

1#
https://chat.deepseek.com/

豆包 或 deep seek


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





成功了!直接领走https://www.doubao.com/share/code/3ede0ce09896e83d
本主题由 管理员 徐玉红 于 2025/4/2 19:27:13 执行 批量删帖 操作
分享 转发
TOP
2#


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

TOP
3#


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

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


又出来一个叛逆的!


TOP
4#

再次调整,终于好了,还自带3种物质的折射率与变化!伙伴们看看还可以怎么完善?


TOP
5#

让它自我反省的时候你是怎么提示的?
TOP
6#

自我反省很有意思。
TOP
7#

回复 5楼嘉琳的帖子

告诉他出现什么问题,自己检查代码,我希望它达到什么效果
TOP
8#

画出法线会不会更直观
TOP
9#

你已经用得很丝滑了!
TOP
10#

“AI科学助教”我没有用过,感觉对我们科学教学很有帮助。
TOP
11#

回复 8楼董敏尔的帖子

好主意👍
TOP
12#

回复 10楼一剑飘香的帖子

我自己编的
TOP
13#


TOP
14#

现学现用,这个可太好用啦,就是下载的代码,要放到哪里去会生成这个程序呢?
TOP
15#

这些功能需会员的吧。
TOP
16#

这个可以,在想使用的时候是不是录屏保存下来,哈哈
TOP
17#

好方法,真棒
TOP
18#

这个反复思考,需要不断和他讲述出现问题的地方,然后让他不断改进,是这样吗?
TOP
19#

Ai助教科学课,你用的炉火纯青啦
快乐科学
TOP
20#

AI是非常好的工具啊
TOP
21#

与时俱进,将ai科学合理地融入教学中
TOP
22#

看到了好几个帖子,看来徐老师是AI科学的领跑者。
TOP
23#

Ai确实方便很多,还能帮我们作图。
TOP
24#

现学现用,这个可太好用啦,就是下载的代码,要放到哪里去会生成这个程序呢?
胡璐佳 发表于 2025/3/30 11:29:18
同问
TOP
25#

是AI 小导师了
TOP
26#

信息技术水平也要过硬呀
TOP
27#

回复 18楼冥王星的帖子

完全正确
TOP
28#

根据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(); // 初始绘制
    



TOP
29#

太棒了,感谢老师分享
TOP
30#

豆包🆚 deep seek

豆包
感觉是书呆子,听不懂科学语言,有两个问题一致改不过来!




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



TOP
发新话题 回复该主题