BriocheWindows

Random Character Generator Code

Apr 9th, 2022
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. <html>
  2.  
  3. <head>
  4.  
  5. <title>Avatar Maker</title>
  6.  
  7. <script>
  8.  
  9. window.onload = function ()
  10. {
  11. //head
  12. var robothead = new Image();
  13. var robotheadnum=Math.floor(Math.random()*6)+1; //Change "3" to whatever number of head files you have
  14. var robotheadname="head" + robotheadnum + ".png";
  15. robothead.src=robotheadname;
  16.  
  17. //eyes
  18. var roboteyes = new Image();
  19. var roboteyesnum=Math.floor(Math.random()*4)+1; //Change "3" to whatever number of head files you have
  20. var roboteyesname="eyes" + roboteyesnum + ".png";
  21. roboteyes.src=roboteyesname;
  22.  
  23. //mouth
  24. var robotmouth = new Image();
  25. var robotmouthnum=Math.floor(Math.random()*6)+1; //Change "3" to whatever number of head files you have
  26. var robotmouthname="mouth" + robotmouthnum + ".png";
  27. robotmouth.src=robotmouthname;
  28.  
  29. //body
  30. var robotbody = new Image();
  31. var robotbodynum=Math.floor(Math.random()*4)+1; //Change "3" to whatever number of head files you have
  32. var robotbodyname="body" + robotbodynum + ".png";
  33. robotbody.src=robotbodyname;
  34.  
  35. //background
  36. var robotbackground = new Image();
  37. var robotbackgroundnum=Math.floor(Math.random()*36)+1; //Change "3" to whatever number of head files you have
  38. var robotbackgroundname="background" + robotbackgroundnum + ".png";
  39. robotbackground.src=robotbackgroundname;
  40.  
  41. //hue overlay - THIS PART NEEDS TO CHANGE BUT I DON'T KNOW HOW TO FIX IT
  42. var robothue = new Image();
  43. var robothuename = "hue";
  44. robothue.src = robothuename;
  45. robothue.style.filter =
  46.  
  47. //head loaded
  48. robothead.onload=function()
  49. {
  50. buildrobot();
  51. }
  52.  
  53. //eyes loaded
  54. roboteyes.onload=function()
  55. {
  56. buildrobot();
  57. }
  58.  
  59. //mouth loaded
  60. robotmouth.onload=function()
  61. {
  62. buildrobot();
  63. }
  64.  
  65. //body loaded
  66. robotbody.onload=function()
  67. {
  68. buildrobot();
  69. }
  70.  
  71. //body loaded
  72. robotbackground.onload=function()
  73. {
  74. buildrobot();
  75. }
  76.  
  77. //hue loaded
  78. robothue.onload=function()
  79. {
  80. buildrobot();
  81. }
  82.  
  83. function buildrobot()
  84. {
  85. var canvas=document.getElementById('canvas');
  86. var ctx = canvas.getContext('2d');
  87. canvas.width=1120;
  88. canvas.height=1120;
  89.  
  90. //draw body
  91. ctx.drawImage(robotbackground,((1120-robotbody.width)/2),0);
  92. //draw body
  93. ctx.drawImage(robotbody,((1120-robotbody.width)/2),0);
  94. //draw eyes
  95. ctx.drawImage(roboteyes,((1120-roboteyes.width)/2),0);
  96. //draw mouth
  97. ctx.drawImage(robotmouth,((1120-robotmouth.width)/2),0);
  98. //draw head
  99. ctx.drawImage(robothead,((1120-robothead.width)/2),0);
  100. //draw hue
  101. ctx.drawImage(robothue,((1120-robothue.width)/2),0);
  102. }
  103. }
  104.  
  105. </script>
  106.  
  107. </head>
  108.  
  109. <body>
  110.  
  111. <div align="center">
  112. <canvas id="canvas" style="border:5px solid #000000;"></canvas>
  113. <br><br>
  114. <button onClick="window.location.reload();"> Generate! </button>
  115. </div>
  116.  
  117. </body>
  118.  
  119. </html>
Advertisement
Add Comment
Please, Sign In to add comment