国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

跳動的愛心代碼--李峋愛心代碼(完整源碼)

這篇具有很好參考價值的文章主要介紹了跳動的愛心代碼--李峋愛心代碼(完整源碼)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報違法"按鈕提交疑問。

本文章分為兩部分:
第一部分為實(shí)現(xiàn)效果展示,第二部分是實(shí)現(xiàn)跳動愛心源碼。
關(guān)注微信公眾號: ClassmateJie

跳動的愛心效果展示

愛心代碼,前端,javascript,開發(fā)語言
關(guān)注微信公眾號【ClassmateJie】獲取完整源碼,回復(fù)愛心代碼。

實(shí)現(xiàn)步驟

1.建一個html文件,代碼如下:

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>愛心跳動,3D拖拽搬</title>
  <link rel="stylesheet" href="./css/style.css">

</head>

<body>

  <script src='./js/three.min.js'></script>
  <!-- <script src='./js/MeshSurfaceSampler.js'></script> -->
  <script src='./js/TrackballControls.js'></script>
  <script src='./js/simplex-noise.js'></script>
  <script src='./js/OBJLoader.js'></script>
  <script src='./js/gsap.min.js'></script>
  <script src="./js/script.js"></script>


  <script>


    (function () {
      const _face = new THREE.Triangle();

      const _color = new THREE.Vector3();

      class MeshSurfaceSampler {

        constructor(mesh) {

          let geometry = mesh.geometry;

          if (!geometry.isBufferGeometry || geometry.attributes.position.itemSize !== 3) {

            throw new Error('THREE.MeshSurfaceSampler: Requires BufferGeometry triangle mesh.');

          }

          if (geometry.index) {

            console.warn('THREE.MeshSurfaceSampler: Converting geometry to non-indexed BufferGeometry.');
            geometry = geometry.toNonIndexed();

          }

          this.geometry = geometry;
          this.randomFunction = Math.random;
          this.positionAttribute = this.geometry.getAttribute('position');
          this.colorAttribute = this.geometry.getAttribute('color');
          this.weightAttribute = null;
          this.distribution = null;

        }

        setWeightAttribute(name) {

          this.weightAttribute = name ? this.geometry.getAttribute(name) : null;
          return this;

        }

        build() {

          const positionAttribute = this.positionAttribute;
          const weightAttribute = this.weightAttribute;
          const faceWeights = new Float32Array(positionAttribute.count / 3); // Accumulate weights for each mesh face.

          for (let i = 0; i < positionAttribute.count; i += 3) {

            let faceWeight = 1;

            if (weightAttribute) {

              faceWeight = weightAttribute.getX(i) + weightAttribute.getX(i + 1) + weightAttribute.getX(i + 2);

            }

            _face.a.fromBufferAttribute(positionAttribute, i);

            _face.b.fromBufferAttribute(positionAttribute, i + 1);

            _face.c.fromBufferAttribute(positionAttribute, i + 2);

            faceWeight *= _face.getArea();
            faceWeights[i / 3] = faceWeight;

          } // Store cumulative total face weights in an array, where weight index
          // corresponds to face index.


          this.distribution = new Float32Array(positionAttribute.count / 3);
          let cumulativeTotal = 0;

          for (let i = 0; i < faceWeights.length; i++) {

            cumulativeTotal += faceWeights[i];
            this.distribution[i] = cumulativeTotal;

          }

          return this;

        }

        setRandomGenerator(randomFunction) {

          this.randomFunction = randomFunction;
          return this;

        }

        sample(targetPosition, targetNormal, targetColor) {

          const cumulativeTotal = this.distribution[this.distribution.length - 1];
          const faceIndex = this.binarySearch(this.randomFunction() * cumulativeTotal);
          return this.sampleFace(faceIndex, targetPosition, targetNormal, targetColor);

        }

        binarySearch(x) {

          const dist = this.distribution;
          let start = 0;
          let end = dist.length - 1;
          let index = - 1;

          while (start <= end) {

            const mid = Math.ceil((start + end) / 2);

            if (mid === 0 || dist[mid - 1] <= x && dist[mid] > x) {

              index = mid;
              break;

            } else if (x < dist[mid]) {

              end = mid - 1;

            } else {

              start = mid + 1;

            }

          }

          return index;

        }

        sampleFace(faceIndex, targetPosition, targetNormal, targetColor) {

          let u = this.randomFunction();
          let v = this.randomFunction();

          if (u + v > 1) {

            u = 1 - u;
            v = 1 - v;

          }

          _face.a.fromBufferAttribute(this.positionAttribute, faceIndex * 3);

          _face.b.fromBufferAttribute(this.positionAttribute, faceIndex * 3 + 1);

          _face.c.fromBufferAttribute(this.positionAttribute, faceIndex * 3 + 2);

          targetPosition.set(0, 0, 0).addScaledVector(_face.a, u).addScaledVector(_face.b, v).addScaledVector(_face.c, 1 - (u + v));

          if (targetNormal !== undefined) {

            _face.getNormal(targetNormal);

          }

          if (targetColor !== undefined && this.colorAttribute !== undefined) {

            _face.a.fromBufferAttribute(this.colorAttribute, faceIndex * 3);

            _face.b.fromBufferAttribute(this.colorAttribute, faceIndex * 3 + 1);

            _face.c.fromBufferAttribute(this.colorAttribute, faceIndex * 3 + 2);

            _color.set(0, 0, 0).addScaledVector(_face.a, u).addScaledVector(_face.b, v).addScaledVector(_face.c, 1 - (u + v));

            targetColor.r = _color.x;
            targetColor.g = _color.y;
            targetColor.b = _color.z;
          }
          return this;

        }

      }

      THREE.MeshSurfaceSampler = MeshSurfaceSampler;

    })();

  </script>
  <script>
    (function () {

      const _object_pattern = /^[og]\s*(.+)?/; // mtllib file_reference

      const _material_library_pattern = /^mtllib /; // usemtl material_name

      const _material_use_pattern = /^usemtl /; // usemap map_name

      const _map_use_pattern = /^usemap /;

      const _vA = new THREE.Vector3();

      const _vB = new THREE.Vector3();

      const _vC = new THREE.Vector3();

      const _ab = new THREE.Vector3();

      const _cb = new THREE.Vector3();

      function ParserState() {

        const state = {
          objects: [],
          object: {},
          vertices: [],
          normals: [],
          colors: [],
          uvs: [],
          materials: {},
          materialLibraries: [],
          startObject: function (name, fromDeclaration) {

            // If the current object (initial from reset) is not from a g/o declaration in the parsed
            // file. We need to use it for the first parsed g/o to keep things in sync.
            if (this.object && this.object.fromDeclaration === false) {

              this.object.name = name;
              this.object.fromDeclaration = fromDeclaration !== false;
              return;

            }

            const previousMaterial = this.object && typeof this.object.currentMaterial === 'function' ? this.object.currentMaterial() : undefined;

            if (this.object && typeof this.object._finalize === 'function') {

              this.object._finalize(true);

            }

            this.object = {
              name: name || '',
              fromDeclaration: fromDeclaration !== false,
              geometry: {
                vertices: [],
                normals: [],
                colors: [],
                uvs: [],
                hasUVIndices: false
              },
              materials: [],
              smooth: true,
              startMaterial: function (name, libraries) {

                const previous = this._finalize(false); // New usemtl declaration overwrites an inherited material, except if faces were declared
                // after the material, then it must be preserved for proper MultiMaterial continuation.


                if (previous && (previous.inherited || previous.groupCount <= 0)) {

                  this.materials.splice(previous.index, 1);

                }

                const material = {
                  index: this.materials.length,
                  name: name || '',
                  mtllib: Array.isArray(libraries) && libraries.length > 0 ? libraries[libraries.length - 1] : '',
                  smooth: previous !== undefined ? previous.smooth : this.smooth,
                  groupStart: previous !== undefined ? previous.groupEnd : 0,
                  groupEnd: - 1,
                  groupCount: - 1,
                  inherited: false,
                  clone: function (index) {

                    const cloned = {
                      index: typeof index === 'number' ? index : this.index,
                      name: this.name,
                      mtllib: this.mtllib,
                      smooth: this.smooth,
                      groupStart: 0,
                      groupEnd: - 1,
                      groupCount: - 1,
                      inherited: false
                    };
                    cloned.clone = this.clone.bind(cloned);
                    return cloned;

                  }
                };
                this.materials.push(material);
                return material;

              },
              currentMaterial: function () {

                if (this.materials.length > 0) {

                  return this.materials[this.materials.length - 1];

                }

                return undefined;

              },
              _finalize: function (end) {

                const lastMultiMaterial = this.currentMaterial();

                if (lastMultiMaterial && lastMultiMaterial.groupEnd === - 1) {

                  lastMultiMaterial.groupEnd = this.geometry.vertices.length / 3;
                  lastMultiMaterial.groupCount = lastMultiMaterial.groupEnd - lastMultiMaterial.groupStart;
                  lastMultiMaterial.inherited = false;

                } // Ignore objects tail materials if no face declarations followed them before a new o/g started.


                if (end && this.materials.length > 1) {

                  for (let mi = this.materials.length - 1; mi >= 0; mi--) {

                    if (this.materials[mi].groupCount <= 0) {

                      this.materials.splice(mi, 1);

                    }

                  }

                } // Guarantee at least one empty material, this makes the creation later more straight forward.


                if (end && this.materials.length === 0) {

                  this.materials.push({
                    name: '',
                    smooth: this.smooth
                  });

                }
.....
</body>

</html>


  1. 建立一個css文件
body {
  background: rgb(0, 0, 0);
  overflow: hidden;
  margin: 0;
  /* background-color: #000 !important; */
}

  1. 運(yùn)行html文件
    愛心代碼,前端,javascript,開發(fā)語言

獲取源碼直接運(yùn)行

愛心代碼,前端,javascript,開發(fā)語言文章來源地址http://www.zghlxwxcb.cn/news/detail-571110.html

關(guān)注微信公眾號「 ClassmateJie
更多驚喜等待你的發(fā)掘

到了這里,關(guān)于跳動的愛心代碼--李峋愛心代碼(完整源碼)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 【李峋】一分鐘就能學(xué)會的愛心代碼
  • 李峋同款愛心Python代碼版來了

    李峋同款愛心Python代碼版來了

    ???♂? 個人主頁@老虎也淘氣 個人主頁 ???作者簡介:Python學(xué)習(xí)者 ?? 希望大家多多支持我們一起進(jìn)步!?? 如果文章對你有幫助的話, 歡迎評論 ??點(diǎn)贊???? 收藏 ??加關(guān)注 init (self, generate_frame=20): 這是類的初始化方法,用于創(chuàng)建一個對象時進(jìn)行一些初始設(shè)置。 ge

    2024年02月06日
    瀏覽(25)
  • 用C++實(shí)現(xiàn)李峋同款愛心代碼

    好的,李峋同款愛心代碼是一個經(jīng)典的用 ASCII 碼繪制的愛心圖案,用 C 語言實(shí)現(xiàn)的話,需要使用 printf 函數(shù)和轉(zhuǎn)義字符。 代碼如下: ``` #include stdio.h int main() { printf(\\\"%c%c%c%c%c%c%cn\\\", \\\'/\\\', \\\'\\\', \\\'/\\\', \\\'\\\', \\\'/\\\', \\\'\\\', \\\'/\\\'); printf(\\\"%c%c%c%c%c%c%cn\\\", \\\'\\\', \\\'/\\\', \\\'\\\', \\\'/\\\', \\\'\\\', \\\'/\\\', \\\'\\\'); printf(\\\"%c%c%c%c%c%c%c%c

    2024年02月07日
    瀏覽(19)
  • 【Java】跳動愛心代碼,百分百還原跳動的愛心!

    【Java】跳動愛心代碼,百分百還原跳動的愛心!

    最近那個電視劇的C語言實(shí)現(xiàn)跳動愛心不是火了嗎,相信大家也都看過了,沒錯我也來蹭蹭熱度,話不多說直接上代碼。 下圖展示: 這個代碼看似簡單但寫起來其實(shí)并不輕松, 是一個比較考驗(yàn)對底層原理的理解的題目, 假設(shè)沒有較好的代碼功底或者理解不夠透徹, 得到的結(jié)

    2024年02月11日
    瀏覽(22)
  • Go語言實(shí)現(xiàn)跳動的愛心(附帶源碼)

    在 Go 語言中,你可以使用 github.com/fogleman/gg 包來實(shí)現(xiàn)動態(tài)的愛心效果。以下是一個簡單的例子: 在這個例子中,我們使用 github.com/fogleman/gg 包創(chuàng)建一個圖形上下文,并在一個無限循環(huán)中繪制一個動態(tài)的愛心。每一幀都會保存為 PNG 圖像文件,以便后續(xù)制作成動畫。 要運(yùn)行這

    2024年01月23日
    瀏覽(20)
  • Python制作愛心跳動代碼,你也是天才程序員

    Python制作愛心跳動代碼,你也是天才程序員

    前端時間電視劇《點(diǎn)燃我,溫暖你》正在熱播中,里面的天才程序員李峋制作的愛心跳動代碼是不是震撼了你的心,今天我們用Python來嘗試一下制作愛心跳動代碼吧! 怎么說呢,用這個表白也可以的,萬一她也看這個劇呢,萬一就成了呢 哈哈 沖啊,兄弟們 okok 話不多說,現(xiàn)

    2024年02月09日
    瀏覽(31)
  • 使用Python繪制跳動的愛心,讓你的代碼也充滿愛意!

    使用Python繪制跳動的愛心,讓你的代碼也充滿愛意!

    今天我要分享一個浪漫小技巧,使用Python中的HTML制作一個立體、動態(tài)的小愛心。通過成千上百個小愛心的組合,形成一個大愛心,從內(nèi)到外呈現(xiàn)出立體的效果,給人帶來強(qiáng)烈的視覺沖擊。這個小技巧非常浪漫,讓人感受到愛的力量。 一.粉色愛心 運(yùn)行結(jié)果: ?二.藍(lán)色動態(tài)

    2024年02月08日
    瀏覽(27)
  • 程序員教你用代碼制作3d愛心跳動特效,正好拿去送給女神給她個驚喜

    程序員教你用代碼制作3d愛心跳動特效,正好拿去送給女神給她個驚喜

    ? ????? 【晚安獨(dú)角獸】:hello你好我是獨(dú)角獸,很高興你能來閱讀,昵稱是希望自己能不斷精進(jìn),向著優(yōu)秀程序員前行! ????? 博客來源于項(xiàng)目以及編程中遇到的問題總結(jié),偶爾會有讀書分享,我會陸續(xù)更新Java前端、后臺、數(shù)據(jù)庫、項(xiàng)目案例等相關(guān)知識點(diǎn)總結(jié),感謝你

    2023年04月22日
    瀏覽(20)
  • 《點(diǎn)燃我,溫暖你》理工男神李峋同款C語言版本愛心

    《點(diǎn)燃我,溫暖你》理工男神李峋同款C語言版本愛心

    近期很火的《 點(diǎn)燃我,溫暖你 》很火,里面的 愛心代碼 也很驚艷,但是程序員看了覺得尬的扣腳, 網(wǎng)上也有他其他的語言愛心源碼,但都不是C語言的,用語言描述一下,就是好多愛心,然后從內(nèi)到外,從小到大的顯示。今天就給大家分享: 愛心代碼, 邊看邊用! 2.實(shí)現(xiàn) C語

    2024年02月21日
    瀏覽(18)
  • C/C++愛心代碼(完整代碼)

    C/C++愛心代碼(完整代碼)

    C/C++繪制一個愛心的完整代碼。 Dev-C++ :https://want595.blog.csdn.net/article/details/134649225

    2024年03月11日
    瀏覽(16)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包