%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home2/rezakur1/devita.rezakurnia.com/X9KQ7MW2RT8PY4ND6LV3JH5CG8BF2ZM7QW4/scene9/
Upload File :
Create Path :
Current File : //home2/rezakur1/devita.rezakurnia.com/X9KQ7MW2RT8PY4ND6LV3JH5CG8BF2ZM7QW4/scene9/scene9.js

/* ===================================
HEADER COMPONENT
=================================== */

fetch('../components/header.html')
.then(response => response.text())
.then(data => {

    document.getElementById(
        'header-container'
    ).innerHTML = data;

});


/* ===================================
REVEAL ON SCROLL
=================================== */

const reveals =
document.querySelectorAll('.reveal');

function revealElements(){

    reveals.forEach(item=>{

        const top =
        item.getBoundingClientRect().top;

        const trigger =
        window.innerHeight - 100;

        if(top < trigger){

            item.classList.add('show');
        }

    });

}

window.addEventListener(
    'scroll',
    revealElements
);

revealElements();

/* ===================================
SAVE PREDICTION
=================================== */

const predictionInput =
document.getElementById(
    'predictionInput'
);

const saveBtn =
document.getElementById(
    'savePredictionBtn'
);

if (saveBtn) {

    saveBtn.addEventListener(
        'click',
        async () => {

            const prediction =
            predictionInput.value.trim();

            if (!prediction) {

                alert(
                    'Silakan isi prediksi terlebih dahulu.'
                );

                return;
            }

            try {

                saveBtn.disabled = true;

                const originalText =
                    saveBtn.innerText;

                saveBtn.innerText =
                    'Menyimpan...';

                await ParticipantAnswerService.save({

                    sceneNumber: 9,

                    questionKey:
                        'prediction',

                    questionTitle:
                        '1.Bagaimana pengaruh ukuran kation dan/atau anion terhadap besarnya gaya elektrostatis? , 2. Adakah hubungan antara gaya elektrostatis dengan wujud lelehan senyawa ionik pada suhu kamar?, 3. Jika Na⁺ diganti dengan kation imidazolium (~300 pm), bagaimana energi kisi dan titik leleh berubah?',

                    answer:
                        prediction,

                });

                saveBtn.innerText =
                    '✓ Tersimpan';

                setTimeout(() => {

                    saveBtn.innerText =
                        originalText;

                    saveBtn.disabled =
                        false;

                }, 1500);

            } catch (error) {

                console.error(error);

                alert(
                    'Gagal menyimpan prediksi.'
                );

                saveBtn.disabled =
                    false;

                saveBtn.innerText =
                    'Simpan Prediksi';
            }

        }
    );
}

// /* ===================================
// THREE JS
// =================================== */

// let scene;
// let camera;
// let renderer;
// let latticeGroup;

// let autoRotate = true;
// let showBond = false;

// const viewer =
// document.getElementById(
//     'naclViewer'
// );

// initViewer();

// function initViewer(){

//     scene =
//     new THREE.Scene();

//     camera =
//     new THREE.PerspectiveCamera(

//         60,

//         viewer.clientWidth /
//         viewer.clientHeight,

//         0.1,
//         1000

//     );

//     camera.position.set(
//         0,
//         0,
//         15
//     );

//     renderer =
//     new THREE.WebGLRenderer({

//         antialias:true,
//         alpha:true

//     });

//     renderer.setSize(

//         viewer.clientWidth,
//         viewer.clientHeight

//     );

//     viewer.innerHTML = '';

//     viewer.appendChild(
//         renderer.domElement
//     );

//     const ambient =
//     new THREE.AmbientLight(
//         0xffffff,
//         1.5
//     );

//     scene.add(
//         ambient
//     );

//     createLattice(1);

//     animate();

// }


/* ===================================
CREATE LATTICE
=================================== */

function createLattice(level){

    if(latticeGroup){

        scene.remove(
            latticeGroup
        );

    }

    latticeGroup =
    new THREE.Group();

    const size =

        level === 1
        ? 1

        : level === 2
        ? 3

        : 5;

    const spacing = 2.2;

    const naMaterial =
    new THREE.MeshPhongMaterial({

        color:0xb388ff

    });

    const clMaterial =
    new THREE.MeshPhongMaterial({

        color:0x66bb6a

    });

    const sphereGeometry =
    new THREE.SphereGeometry(
        0.45,
        32,
        32
    );

    for(

        let x=0;
        x<size;
        x++

    ){

        for(

            let y=0;
            y<size;
            y++

        ){

            for(

                let z=0;
                z<size;
                z++

            ){

                const isNa =

                (x+y+z)%2===0;

                const sphere =
                new THREE.Mesh(

                    sphereGeometry,

                    isNa
                    ? naMaterial
                    : clMaterial

                );

                sphere.position.set(

                    (x-size/2)*spacing,

                    (y-size/2)*spacing,

                    (z-size/2)*spacing

                );

                sphere.userData = {

                    type:
                    isNa
                    ? 'Na⁺'
                    : 'Cl⁻',

                    radius:
                    isNa
                    ? '102 pm'
                    : '181 pm',

                    coordination:
                    '6'

                };

                latticeGroup.add(
                    sphere
                );

            }

        }

    }

    scene.add(
        latticeGroup
    );

}


/* ===================================
BOND VISUALIZATION
=================================== */

function createBondLines(){

    const material =
    new THREE.LineBasicMaterial({

        color:0xff4444

    });

    const points = [];

    points.push(
        new THREE.Vector3(
            -2,
            0,
            0
        )
    );

    points.push(
        new THREE.Vector3(
            2,
            0,
            0
        )
    );

    const geometry =
    new THREE.BufferGeometry()
    .setFromPoints(
        points
    );

    const line =
    new THREE.Line(
        geometry,
        material
    );

    line.name =
    'bondLine';

    latticeGroup.add(
        line
    );

}


/* ===================================
ANIMATION
=================================== */

function animate(){

    requestAnimationFrame(
        animate
    );

    if(
        autoRotate &&
        latticeGroup
    ){

        latticeGroup.rotation.y += 0.005;

    }

    renderer.render(
        scene,
        camera
    );

}


/* ===================================
ROTATE BUTTON
=================================== */
// addEventListener


/* ===================================
RESET BUTTON
=================================== */

// document
// .getElementById(
//     'resetBtn'
// )
// .addEventListener(
//     'click',
//     ()=>{

//         latticeGroup.rotation.set(
//             0,
//             0,
//             0
//         );

//         camera.position.set(
//             0,
//             0,
//             15
//         );

//     }
// );


/* ===================================
SHOW BOND BUTTON
=================================== */

// document
// .getElementById(
//     'bondBtn'
// )
// .addEventListener(
//     'click',
//     ()=>{

//         showBond =
//         !showBond;

//         const existing =

//         latticeGroup.getObjectByName(
//             'bondLine'
//         );

//         if(showBond){

//             if(!existing){

//                 createBondLines();

//             }

//         }else{

//             if(existing){

//                 latticeGroup.remove(
//                     existing
//                 );

//             }

//         }

//     }
// );


/* ===================================
SLIDER LATTICE
=================================== */

// document
// .getElementById(
//     'latticeSlider'
// )
// .addEventListener(
//     'input',
//     e=>{

//         const level =
//         parseInt(
//             e.target.value
//         );

//         createLattice(
//             level
//         );

//     }
// );


/* ===================================
CLICK ION
=================================== */

// const raycaster =
// new THREE.Raycaster();

// const mouse =
// new THREE.Vector2();

// renderer?.domElement?.addEventListener(
//     'click',
//     ionClickHandler
// );

// function ionClickHandler(event){

//     const rect =
//     renderer.domElement
//     .getBoundingClientRect();

//     mouse.x =

//     (
//         (
//             event.clientX
//             - rect.left
//         )
//         / rect.width
//     ) * 2 - 1;

//     mouse.y =

//     -(
//         (
//             event.clientY
//             - rect.top
//         )
//         / rect.height
//     ) * 2 + 1;

//     raycaster.setFromCamera(
//         mouse,
//         camera
//     );

//     const intersects =

//     raycaster.intersectObjects(

//         latticeGroup.children

//     );

//     if(
//         intersects.length > 0
//     ){

//         const ion =
//         intersects[0].object;

//         document.getElementById(
//             'selectedIonInfo'
//         ).innerHTML = `

//         <strong>
//             ${ion.userData.type}
//         </strong>

//         <br><br>

//         Jari-jari:
//         ${ion.userData.radius}

//         <br>

//         Bilangan Koordinasi:
//         ${ion.userData.coordination}

//         <br>

//         Struktur:
//         Oktahedral

//         `;

//     }

// }


/* ===================================
WINDOW RESIZE
=================================== */

window.addEventListener(
    'resize',
    ()=>{

        camera.aspect =

        viewer.clientWidth /
        viewer.clientHeight;

        camera.updateProjectionMatrix();

        renderer.setSize(

            viewer.clientWidth,
            viewer.clientHeight

        );

    }
);


const modal = document.getElementById("infoModal");
const openBtn = document.getElementById("openInfoModal");
const closeBtn = document.getElementById("closeInfoModal");

openBtn.addEventListener("click", () => {
    modal.classList.add("show");
});

closeBtn.addEventListener("click", () => {
    modal.classList.remove("show");
});

modal.addEventListener("click", (e) => {
    if (e.target === modal) {
        modal.classList.remove("show");
    }
});

Zerion Mini Shell 1.0