0


我让ChatGPT用CSS3画一个皮卡丘,还是自己画的可爱

突然想到了小时候看过的动画片《皮卡丘》,于是突然就想,ChatGPT肯定也看过,他哪有不知道的东西啊,于是就想着让他帮我画一个,他画出来之后,我笑了,这啥玩意儿啊。

一、第一次尝试让ChatGPT用CSS3画皮卡丘

很抱歉,作为一名语言模型,我无法直接向您呈现一个用CSS3画皮卡丘的过程。不过,我可以提供一些指导和思路,帮助您开始这个项目。

首先,您需要了解如何使用CSS3来绘制基本的形状和动画。以下是一些您可能需要用到的基本属性:

  1. border-radius:用于创建圆角矩形。
  2. transform:用于旋转、缩放和平移元素。
  3. animation:用于创建动画效果。
  4. box-shadow:用于添加阴影效果。

绘制皮卡丘的关键在于绘制它的耳朵、眼睛、嘴巴和尾巴等特征。以下是一些可能有用的CSS3代码片段:

1. 绘制皮卡丘的耳朵:

  1. .ear {
  2. width: 50px;
  3. height: 80px;
  4. background-color: #FEE440;
  5. border-radius: 50% 50% 0 0;
  6. transform: rotate(-45deg);
  7. }

2. 绘制皮卡丘的眼睛:

  1. .eye {
  2. width: 30px;
  3. height: 30px;
  4. background-color: #000000;
  5. border-radius: 50%;
  6. position: relative;
  7. animation: blink 5s infinite;
  8. }
  9. .eye::before {
  10. content: "";
  11. width: 12px;
  12. height: 12px;
  13. background-color: #FFFFFF;
  14. border-radius: 50%;
  15. position: absolute;
  16. top: 5px;
  17. left: 5px;
  18. }

3. 绘制皮卡丘的嘴巴:

  1. .mouth {
  2. width: 60px;
  3. height: 30px;
  4. border: 2px solid #000000;
  5. border-top: none;
  6. border-radius: 0 0 50px 50px;
  7. position: relative;
  8. top: 20px;
  9. }
  10. .tongue {
  11. width: 30px;
  12. height: 30px;
  13. background-color: #FF4F6F;
  14. border-radius: 50%;
  15. position: absolute;
  16. bottom: -15px;
  17. left: 15px;
  18. }

4. 绘制皮卡丘的尾巴:

  1. .tail {
  2. width: 120px;
  3. height: 30px;
  4. background-color: #FEE440;
  5. border-radius: 15px;
  6. transform: rotate(-30deg);
  7. position: relative;
  8. top: -40px;
  9. left: 50px;
  10. }
  11. .tail::before {
  12. content: "";
  13. width: 20px;
  14. height: 20px;
  15. background-color: #000000;
  16. border-radius: 50%;
  17. position: absolute;
  18. top: 5px;
  19. left: 90px;
  20. }

以上代码片段只是皮卡丘的一部分,您需要自己根据需要进行修改和调整。希望这些代码片段能够帮助您开始这个有趣的项目!

刚开始他并没有给出我HTML代码,我就自己试着写了几个DIV,于是效果是这样子的,请看

二、第二次尝试ChatGPT完整版皮卡丘

我想着肯定是我HTML元素弄得不对,处于开发人员自己不动手,靠工具去创造的精神,我跟ChatGPT说,你把这些代码片段组合起来,给我形成一个完整的皮卡丘。于是,

将这些代码片段组合在一起,形成一个完整的皮卡丘需要以下步骤:

  1. 在 HTML 文件中创建一个 <div> 元素,作为皮卡丘的容器,设置它的样式,例如 position: relative;
  2. 在容器中创建一个 <div> 元素,作为皮卡丘的身体,设置它的样式,例如 width: 200px; height: 200px; background-color: #FEE440; border-radius: 50%;
  3. 在身体中创建两个 <div> 元素,作为皮卡丘的耳朵,设置它们的样式,例如根据上面的代码片段设置。
  4. 在身体中创建两个 <div> 元素,作为皮卡丘的眼睛,设置它们的样式,例如根据上面的代码片段设置。
  5. 在身体中创建一个 <div> 元素,作为皮卡丘的鼻子,设置它的样式,例如 width: 30px; height: 30px; background-color: #FFA200; border-radius: 50%; position: absolute; top: 70px; left: 85px;
  6. 在身体中创建一个 <div> 元素,作为皮卡丘的嘴巴,设置它的样式,例如根据上面的代码片段设置。
  7. 在嘴巴中创建一个 <div> 元素,作为皮卡丘的舌头,设置它的样式,例如根据上面的代码片段设置。
  8. 在身体中创建一个 <div> 元素,作为皮卡丘的尾巴,设置它的样式,例如根据上面的代码片段设置。
  9. 根据需要调整各元素的位置和大小,以形成一个完整的皮卡丘。

以下是一个简单的示例代码,可以帮助您更好地理解:

HTML代码如下

  1. <div class="pikachu">
  2. <div class="body"></div>
  3. <div class="ear left"></div>
  4. <div class="ear right"></div>
  5. <div class="eye left"></div>
  6. <div class="eye right"></div>
  7. <div class="nose"></div>
  8. <div class="mouth">
  9. <div class="tongue"></div>
  10. </div>
  11. <div class="tail"></div>
  12. </div>

CSS3代码如下

  1. .pikachu {
  2. position: relative;
  3. width: 200px;
  4. height: 200px;
  5. }
  6. .body {
  7. width: 200px;
  8. height: 200px;
  9. background-color: #FEE440;
  10. border-radius: 50%;
  11. }
  12. .ear {
  13. width: 50px;
  14. height: 80px;
  15. background-color: #FEE440;
  16. border-radius: 50% 50% 0 0;
  17. transform: rotate(-45deg);
  18. position: absolute;
  19. top: -30px;
  20. }
  21. .left {
  22. left: 40px;
  23. }
  24. .right {
  25. right: 40px;
  26. }
  27. .eye {
  28. width: 30px;
  29. height: 30px;
  30. background-color: #000000;
  31. border-radius: 50%;
  32. position: absolute;
  33. top: 40px;
  34. animation: blink 5s infinite;
  35. }
  36. .nose {
  37. width: 30px;
  38. height: 30px;
  39. background-color: #FFA200;
  40. border-radius: 50%;
  41. position: absolute;
  42. top: 70px;
  43. left: 85px;
  44. }
  45. .mouth {
  46. width: 60px;
  47. height: 30px;
  48. border: 2px solid #000000;
  49. border-top: none;
  50. border-radius: 0 0 50px 50px;
  51. position: absolute;
  52. top: 90px;
  53. left: 70px;
  54. }
  55. .tongue {
  56. width: 30px;
  57. height: 30px;
  58. background-color: #FF4F6F;
  59. border-radius: 50%;
  60. position: absolute;
  61. bottom: -15px;
  62. left: 15px;
  63. }
  64. .tail {
  65. width: 120px;
  66. height: 30px;
  67. background-color: #FEE440;
  68. border-radius: 15px;
  69. transform: rotate(-30deg);
  70. position: absolute;
  71. top: 130px;
  72. left: -10px;
  73. }
  74. .tail::before {
  75. content: "";
  76. width: 20px;
  77. height: 20px;
  78. background-color: #000000;
  79. border-radius: 50%;
  80. position: absolute;
  81. top: 5px;
  82. left: 90px;
  83. }

** 请看结果:这是皮卡丘?莫非他进化了?**

三、自己动手用CSS3画皮卡丘吧

1. 实现思路

耳朵,耳朵尖,头部,脸夹,眼睛,眼珠子,鼻子,可爱的小嘴,舌头

涉及到的CSS3属性,radial-gradient 的背景填充,animation 的耳朵尖动画,头部border-radius的圆角边框,右下角box-shadow的阴影显示,眼睛和眼珠子的定位,这里采用了::before,鼻子类似于用css实现一个三角形的写法,15px solid transparent ,脸夹是背景颜色的设置,圆角边框的实现,以及定位,小嘴巴涉及到了 box-shadow : inset 0px -4px 0 #1b1919 的阴影,或者做一个圆角也可以实现

2. HTML部分源代码

  1. <div class="pikachu">
  2. <div class="left-ear"></div>
  3. <div class="right-ear"></div>
  4. <div class="head">
  5. <div class="left-eye"></div>
  6. <div class="right-eye"></div>
  7. <div class="nose"></div>
  8. <div class="left-cheek"></div>
  9. <div class="right-cheek"></div>
  10. <div class="lips"></div>
  11. <div class="mouth"></div>
  12. </div>
  13. </div>

3. CSS3部分源代码

  1. <style>
  2. body {
  3. display: flex;
  4. height: 100vh;
  5. width: 100vw;
  6. align-items: center;
  7. justify-content: center;
  8. background: linear-gradient(#f2fcff, #b9e4f7);
  9. overflow:hidden;
  10. }
  11. .pikachu {
  12. position: relative;
  13. }
  14. @media (max-width: 600px) {
  15. .pikachu {
  16. transform: scale(0.5);
  17. }
  18. }
  19. .head {
  20. position: relative;
  21. margin-top: 200px;
  22. width: 370px;
  23. height: 330px;
  24. background: #ffd01c;
  25. border: 4px solid #1b1919;
  26. border-radius: 45%;
  27. overflow: hidden;
  28. box-shadow: inset -10px -8px 0 #d8851c;
  29. }
  30. .left-eye,
  31. .right-eye {
  32. position: absolute;
  33. width: 70px;
  34. height: 70px;
  35. background-color: #1b1919;
  36. border-radius: 50%;
  37. top: 40%;
  38. }
  39. .left-eye::before,
  40. .right-eye::before {
  41. content: "";
  42. position: absolute;
  43. width: 30px;
  44. height: 30px;
  45. background-color: white;
  46. border-radius: 50%;
  47. top: 10%;
  48. animation: 0.2s infinite shaking;
  49. }
  50. .left-eye {
  51. left: 20%;
  52. }
  53. .left-eye::before {
  54. left: 40%;
  55. }
  56. .right-eye {
  57. right: 20%;
  58. }
  59. .right-eye::before {
  60. right: 40%;
  61. }
  62. .nose {
  63. position: relative;
  64. width: 0;
  65. height: 0;
  66. border-top: 10px solid #1b1919;
  67. border-left: 15px solid transparent;
  68. border-right: 15px solid transparent;
  69. border-bottom: 10px solid transparent;
  70. border-radius: 8px;
  71. margin: auto;
  72. top: 60%;
  73. }
  74. .left-cheek,
  75. .right-cheek {
  76. position: absolute;
  77. width: 80px;
  78. height: 80px;
  79. background-color: #fb1412;
  80. border: 4px solid #1b1919;
  81. border-radius: 50%;
  82. top: 60%;
  83. }
  84. .left-cheek {
  85. left: -5%;
  86. }
  87. .right-cheek {
  88. right: -5%;
  89. }
  90. .lips {
  91. display: block;
  92. position: relative;
  93. margin: auto;
  94. width: 1px;
  95. height: 1px;
  96. top: 60%;
  97. z-index: 2;
  98. }
  99. .lips::after, .lips::before {
  100. position: absolute;
  101. content: "";
  102. top: -20px;
  103. width: 50px;
  104. height: 40px;
  105. border-radius: 50%;
  106. box-shadow: inset 0px -4px 0 #1b1919;
  107. background-color: #ffd01c;
  108. }
  109. .lips::before {
  110. right: 0px;
  111. }
  112. .lips::after {
  113. left: 0px;
  114. }
  115. .mouth {
  116. position: relative;
  117. height: 60px;
  118. width: 60px;
  119. margin: auto;
  120. top: 60%;
  121. border: 4px solid #1b1919;
  122. border-radius: 0 0 50% 50%;
  123. z-index: 1;
  124. background-image: radial-gradient(circle at center 80%, #e93c4e 0%, #e93c4e 50%, #9e2d38 50%, #9e2d38 60%, #1b1919 60%, #1b1919 65%, #5c0009 65%);
  125. background-position: 80% center;
  126. }
  127. .left-ear,
  128. .right-ear {
  129. position: absolute;
  130. height: 450px;
  131. width: 70px;
  132. background: #ffd01c;
  133. border-radius: 50%;
  134. border: 4px solid #1b1919;
  135. box-shadow: inset -4px -120px 0 #d8851c;
  136. }
  137. .right-ear {
  138. right: 10px;
  139. transform: rotate(12deg);
  140. background-image: radial-gradient(circle at -100% 45%, #ffd01c 0%, #ffd01c 60%, black 60%);
  141. }
  142. .left-ear {
  143. left: 10px;
  144. transform: rotate(-50deg);
  145. background-image: radial-gradient(circle at 200% 45%, #ffd01c 0%, #ffd01c 60%, black 60%);
  146. animation: 5s 5s infinite wiggle;
  147. animation-fill-mode: forwards;
  148. animation-direction: alternate;
  149. }
  150. @keyframes shaking {
  151. from {
  152. transform: translateX(0%);
  153. }
  154. to {
  155. transform: translateX(2%);
  156. }
  157. }
  158. @keyframes wiggle {
  159. 0% {
  160. transform: rotate(-50deg);
  161. }
  162. 5% {
  163. transform: rotate(-60deg);
  164. }
  165. 10% {
  166. transform: rotate(-50deg);
  167. }
  168. 12% {
  169. transform: rotate(-55deg);
  170. }
  171. 15% {
  172. transform: rotate(-50deg);
  173. }
  174. 100% {
  175. transform: rotate(-50deg);
  176. }
  177. }</style>

最终画出了可爱的皮卡丘,快拿到代码去感受一下吧。

标签: css3 前端 css

本文转载自: https://blog.csdn.net/xingyu_qie/article/details/130623708
版权归原作者 经海路大白狗 所有, 如有侵权,请联系我们删除。

“我让ChatGPT用CSS3画一个皮卡丘,还是自己画的可爱”的评论:

还没有评论