如何用百分比制作随机图像生成器

How to make random image generator with percent?

本文关键字:图像 随机 何用 百分比      更新时间:2023-09-26

首先,我对我的英语不好感到非常抱歉。我想问这个脚本怎么做,我想放百分比?我的意思是每个图像都有他们的百分比,比如 uma image1 有 5% 显示图像 2 有 10% 显示出来,就像那样?

<!DOCTYPE html>
<html>
<body>
<input class="randombutton" type="button" value="Randomize" onclick="randomImg1()"/>
<script type="text/javascript">
    function randomImg1() {
      myImages1 = new Array();
      myImages1[0] = "images/1.gif";
      myImages1[1] = "images/2.gif";
	  myImages1[2] = "images/1.gif";
      myImages1[3] = "images/2.gif";
	  myImages1[4] = "images/1.gif";
      myImages1[5] = "images/2.gif";
	  myImages1[6] = "images/1.gif";
      myImages1[7] = "images/2.gif";
	  myImages1[8] = "images/1.gif";
      myImages1[9] = "images/2.gif";
	  myImages1[10] = "images/1.gif";
      myImages1[11] = "images/2.gif";
	  myImages1[12] = "images/1.gif";
      myImages1[13] = "images/2.gif";
	  myImages1[14] = "images/1.gif";
      myImages1[15] = "images/2.gif";
	  myImages1[16] = "images/1.gif";
      myImages1[17] = "images/2.gif";
	  myImages1[18] = "images/1.gif";
      myImages1[19] = "images/2.gif";
      var rnd = Math.floor( Math.random() * myImages1.length ); //incorporated other solution
      document.getElementById("image").innerHTML = "<img src='" + myImages1[rnd] + "' alt='image'></img>";
    }
</script>
<div id="image"></div>
</body>
</html>

创建一个数组,为每张图片单独保存 pnear。这意味着你有myImages1,这是一个在每个单元格图像中都有的数组。每个单元格都有一个数字。您创建另一个称为 pTea 的数组,在其单元格编号上,它包含相同单元格编号中另一个数组中的图像的 PPree。

function randomImg1() {
  var precent = new Array();
  myImages1 = new Array();
  myImages1[0] = "images/1.gif";
  precent[0] = 5;
  myImages1[1] = "images/2.gif";
  precent[1] = 10;
  myImages1[2] = "images/1.gif";
  precent[2] = 20;
  myImages1[3] = "images/2.gif";
  precent[3] = 30;
  myImages1[4] = "images/1.gif";
  precent[4] = 40;
  myImages1[5] = "images/2.gif";
  precent[5] = 70;
  myImages1[6] = "images/1.gif";
  precent[6] = 90;
  myImages1[7] = "images/2.gif";
  precent[7] = 45;
  myImages1[8] = "images/1.gif";
  precent[8] = 93;
  myImages1[9] = "images/2.gif";
  precent[9] = 21;
  myImages1[10] = "images/1.gif";
  precent[10] = 20;
  myImages1[11] = "images/2.gif";
  precent[11] = 34;
  myImages1[12] = "images/1.gif";
  precent[12] = 66;
  myImages1[13] = "images/2.gif";
  precent[13] = 94;
  myImages1[14] = "images/1.gif";
  precent[14] = 56;
  myImages1[15] = "images/2.gif";
  precent[15] = 87;
  myImages1[16] = "images/1.gif";
  precent[16] = 12;
  myImages1[17] = "images/2.gif";
  precent[17] = 44;
  myImages1[18] = "images/1.gif";
  precent[18] = 76;
  myImages1[19] = "images/2.gif";
  precent[19] = 89;
  var rnd = Math.floor( Math.random() * myImages1.length ); //incorporated other solution
   document.getElementById("image").innerHTML = "<img src='" + myImages1[rnd] + "' alt='image' width='"+precent[rnd]+"%' height='"+precent[rnd]+"%'></img>";
}

根据需要更改每张图片的百分点。