Skip to content
TheChatArchiveThe Chat Archive
chatgpt-4o-latest-20250326· OpenAIHugging Face LMArena Human Preference 140K

인터랙티브로 작동하는 3D 루빅스 큐브 학습 프로그을 colab용으로 만들어줘

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Mistralmistral-medium-2505’s answer.
  1. User

    인터랙티브로 작동하는 3D 루빅스 큐브 학습 프로그을 colab용으로 만들어줘

  2. Assistant

    물론입니다!
    아래는 Google Colab에서 실행 가능한 3D 루빅스 큐브 학습 프로그램입니다.
    이 프로그램은 웹 기술 (HTML + Three.js + JavaScript)를 이용하여 인터랙티브한 3D 큐브를 실시간으로 조작할 수 있도록 구성되어 있습니다.


    ✅ 기본 기능

    • 🧊 3D 루빅스 큐브 렌더링 (Three.js 사용)
    • 🖱 마우스 조작 (드래그로 회전 / 휠로 줌)
    • ⌨ 키보드 지원 (U/D/L/R/F/B + Shift = 반시계 방향)
    • 🔁 큐브 섞기 / 초기화 버튼
    • 🧠 초보자용 알고리즘 가이드 (HTML 우측 패널)

    ✅ 사용법

    1. 아래 코드를 Colab 코드 셀에 복사합니다.
    2. Shift + Enter 으로 실행합니다.
    3. 셀 출력창에서 큐브를 직접 조작해보세요!

    🧩 코드 셀 복사:

    %%html
    <!-- 3D 루빅스 큐브 인터랙티브 뷰어 for Google Colab -->
    <!DOCTYPE html>
    <html lang="ko">
    <head>
      <meta charset="UTF-8" />
      <title>3D 루빅스 큐브 - Colab</title>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
      <script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/controls/OrbitControls.js"></script>
      <style>
        body { margin: 0; font-family: sans-serif; }
        #canvas { width: 100%; height: 600px; display: block; }
        #panel {
          position: absolute;
          top: 8px;
          left: 8px;
          background: rgba(0,0,0,0.7);
          color: #fff;
          padding: 12px;
          border-radius: 8px;
          width: 250px;
          font-size: 13px;
          line-height: 1.5;
        }
        button {
          background: #4CAF50;
          border: none;
          padding: 6px 10px;
          margin: 3px;
          color: white;
          font-weight: bold;
          cursor: pointer;
          border-radius: 4px;
        }
        button:hover {
          background: #66BB6A;
        }
        .prime { background: #e64a19; }
        .prime:hover { background: #ff5722; }
        h3 { color: #4CAF50; margin-top: 0; }
        .algo {
          font-size: 12px;
          color: #ccc;
          font-family: monospace;
          background: #222;
          padding: 5px 8px;
          border-radius: 4px;
        }
      </style>
    </head>
    <body>
    <div id="canvas"></div>
    <div id="panel">
      <h3>🎲 면 회전</h3>
      <div>
        <button onclick="rotate('U')">U</button>
        <button onclick="rotate('D')">D</button>
        <button onclick="rotate('L')">L</button>
        <button onclick="rotate('R')">R</button>
        <button onclick="rotate('F')">F</button>
        <button onclick="rotate('B')">B</button>
      </div>
      <div>
        <button class="prime" onclick="rotate(`U'`)">U'</button>
        <button class="prime" onclick="rotate(`D'`)">D'</button>
        <button class="prime" onclick="rotate(`L'`)">L'</button>
        <button class="prime" onclick="rotate(`R'`)">R'</button>
        <button class="prime" onclick="rotate(`F'`)">F'</button>
        <button class="prime" onclick="rotate(`B'`)">B'</button>
      </div>
      <div style="margin-top:10px;">
        <button onclick="scramble()">🔀 섞기</button>
        <button onclick="resetCube()">🔄 초기화</button>
      </div>
      <h3>📘 초보자 가이드</h3>
      <div class="algo">① 흰 십자가: F R U R' U' F'</div>
      <div class="algo">② 코너 맞추기: R U R' U R U2 R'</div>
      <div class="algo">③ 중간층: U R U' R' U' F' U F</div>
      <div class="algo">④ 노랑 십자가: F R U R' U' F'</div>
      <div class="algo">⑤ PLL: R U R' U R U2 R'</div>
    </div>
    
    <script>
    let scene, camera, renderer, controls;
    let cube = new THREE.Group();
    let rotating = false;
    
    const COLORS = {
      U: 0xffffff, D: 0xffff00, F: 0x00ff00,
      B: 0x0000ff, L: 0xff8c00, R: 0xff0000,
      black: 0x111111
    };
    
    init();
    
    function init() {
      // 기본 씬 구성
      scene = new THREE.Scene();
      camera = new THREE.PerspectiveCamera(70, window.innerWidth/600, 0.1, 1000);
      camera.position.set(5,5,5);
    
      renderer = new THREE.WebGLRenderer({ antialias:true });
      renderer.setSize(window.innerWidth, 600);
      document.getElementById('canvas').appendChild(renderer.domElement);
    
      controls = new THREE.OrbitControls(camera, renderer.domElement);
      controls.enableDamping = true;
    
      scene.add(new THREE.AmbientLight(0xffffff, 0.6));
      const light = new THREE.DirectionalLight(0xffffff, 0.8);
      light.position.set(5,10,5);
      scene.add(light);
    
      createCube();
      animate();
    }
    
    function createCube() {
      scene.remove(cube);
      cube = new THREE.Group();
      const s = 1.05;  // 거리 보정
    
      for (let x=-1; x<=1; x++) {
        for (let y=-1; y<=1; y++) {
          for (let z=-1; z<=1; z++) {
            if (x === 0 && y === 0 && z === 0) continue;
    
            const geo = new THREE.BoxGeometry(0.95, 0.95, 0.95);
            const mats = [
              new THREE.MeshBasicMaterial({color: x=== 1 ? COLORS.R : COLORS.black}),
              new THREE.MeshBasicMaterial({color: x===-1 ? COLORS.L : COLORS.black}),
              new THREE.MeshBasicMaterial({color: y=== 1 ? COLORS.U : COLORS.black}),
              new THREE.MeshBasicMaterial({color: y===-1 ? COLORS.D : COLORS.black}),
              new THREE.MeshBasicMaterial({color: z=== 1 ? COLORS.F : COLORS.black}),
              new THREE.MeshBasicMaterial({color: z===-1 ? COLORS.B : COLORS.black}),
            ];
            const cubie = new THREE.Mesh(geo, mats);
            cubie.position.set(x*s, y*s, z*s);
            cubie.userData = {x, y, z};
            cube.add(cubie);
          }
        }
      }
    
      scene.add(cube);
    }
    
    function animate() {
      requestAnimationFrame(animate);
      controls.update();
      renderer.render(scene, camera);
    }
    
    function rotate(face) {
      if (rotating) return;
      rotating = true;
    
      const cw = !face.endsWith("'");
      const f = face[0];
      const angle = cw ? Math.PI/2 : -Math.PI/2;
      const group = new THREE.Group();
    
      // 축 및 선택자
      let axis, select;
      if (f==="U" || f==="D") {
        axis = new THREE.Vector3(0,1,0);
        let y = f==="U" ? 1.05 : -1.05;
        select = c => Math.abs(c.position.y - y) < 0.1;
      } else if (f==="L" || f==="R") {
        axis = new THREE.Vector3(1,0,0);
        let x = f==="L" ? -1.05 : 1.05;
        select = c => Math.abs(c.position.x - x) < 0.1;
      } else if (f==="F" || f==="B") {
        axis = new THREE.Vector3(0,0,1);
        let z = f==="F" ? 1.05 : -1.05;
        select = c => Math.abs(c.position.z - z) < 0.1;
      }
    
      cube.children.forEach(c => {
        if (select(c)) group.attach(c);
      });
    
      scene.add(group);
    
      let progress = 0;
      const duration = 15; // frame 수
    
      function animateRot() {
        progress++;
        group.rotation.setFromAxisAngle(axis, angle * progress / duration);
        if (progress < duration) {
          requestAnimationFrame(animateRot);
        } else {
          // 끝났으면 고정
          group.rotation.setFromAxisAngle(axis, angle);
          while (group.children.length > 0) {
            cube.attach(group.children[0]);
          }
          scene.remove(group);
          rotating = false;
        }
      }
    
      animateRot();
    }
    
    function scramble(times=20) {
      const moves = ['U','D','L','R','F','B',"U'","D'","L'","R'","F'","B'"];
      let count = 0;
      function doOne() {
        if (count >= times) return;
        rotate(moves[Math.floor(Math.random()*moves.length)]);
        count++;
        setTimeout(doOne, 300);
      }
      doOne();
    }
    
    function resetCube(){
      if(rotating) return;
      createCube();
    }
    
    // 키보드 조작
    window.addEventListener('keydown', e=>{
      const key = e.key.toUpperCase();
      if(['U','D','L','R','F','B'].includes(key)){
        rotate(e.shiftKey ? key+"'" : key);
      }
    });
    </script>
    </body>
    </html>
    

    ✅ 기능 요약

    항목설명
    🧊 큐브 회전마우스 드래그로 3D 회전
    ⌨ 키보드 작동U/D/L/R/F/B (Shift = 반시계)
    🔁 섞기무작위로 20회 자동 회전
    🔃 초기화큐브를 원래 상태로
    💡 학습 패널큐브 공식을 단계별로 텍스트 제공

    ✅ 자주 묻는 질문 (FAQ)

    Q. 키보드 입력이 안 먹어요!
    A. 셀 출력 영역을 클릭한 후 키보드 입력해주세요.

    Q. 더 고급 기능 (자동 푸는 알고리즘 등)은 없나요?
    A. 현재는 초보자 학습용에 초점 맞추었습니다. 원하시면 추후 A* 탐색 또는 Kociemba 알고리즘 등 추가 가능합니다 😊


    ✅ 결과 예시:

    • 출력창에 3D 큐브가 등장합니다.
    • 회전 / 조작 가능하며, 초보자용 구현에 매우 적합합니다 🎉

    필요하시면 추가 기능(큐브 상태 저장/로드, 큐브 해법 자동 연산, 스텝바이스텝 튜토리얼 등)도 구성해드릴 수 있습니다.

    원하시나요? 😄

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.