Guest User

Untitled

a guest
Oct 25th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.24 KB | None | 0 0
  1.  
  2. var width = 1920;
  3. var height = 1080;
  4. var t = 5;
  5.  
  6. var colours = [ [],[],[],[],[],[] ];//hue1, hue2, sat1,sat2, value1, value2
  7. for(n=0;n<41;n++){
  8. colours[0][n] = 1+Math.random();
  9. colours[1][n] = colours[0][n]+0.5-Math.random();
  10. colours[2][n] = 0.5+0.5*Math.random();
  11. colours[3][n] = 0.5+0.5*Math.random();
  12. colours[4][n] = 0.75+0.25*Math.random();
  13. colours[5][n] = 0.75+0.25*Math.random();
  14. };
  15. colours[4][0] = 0.2*Math.random();
  16. colours[5][0] = 0.2*Math.random();
  17.  
  18. var pixels0 = [];
  19. for(ax=0;ax<width;ax++){
  20. pixels0[ax] = [];
  21. for(ay=0;ay<height;ay++){
  22. pixels0[ax][ay] = pickcolour(ax,ay,0);
  23. };
  24. };
  25.  
  26. for(bx=0;bx<8;bx++){
  27. for(by=0;by<5;by++){
  28. for(ax=Math.max(0,(bx-1)*width/8);ax<Math.min(width,(bx+2)*width/8);ax++){
  29. for(ay=by*height/5;ay<(by+1)*height/5;ay++){
  30. if( isshape(6-by,(2*bx+1)*width*19/320+(4-by)*width/80,(2*by+1)*height/10,height/12,2+(bx+1)*2+(4-by)*(5-by),0,ax,ay) ){//isshape(n,x,y,r,p,theta,ax,ay) axis, center x, center y, radius, power, rotation, actual x, actual y
  31. pixels0[ax][ay] = pickcolour(ax,ay,1+5*bx+by);
  32. };
  33. };
  34. };
  35. };
  36. };
  37.  
  38. function pickcolour(ax,ay,n){
  39. var w = (ax/2+ay)/(width/2+height);
  40. return(rgbtohex(hsvtorgb([], (w*colours[0][n]+(1-w)*colours[1][n])%1, w*colours[2][n]+(1-w)*colours[3][n], w*colours[4][n]+(1-w)*colours[5][n] )));
  41. };
  42.  
  43. draw(t,pixels0);
  44.  
  45.  
  46.  
  47. function isshape(n,x,y,r,p,theta,ax,ay){//axis, center x, center y, radius, power, rotation, actual x, actual y
  48. var sum = 0;
  49. for(nn=0;nn<n;nn++){
  50. sum+= Math.pow(Math.sin(theta+Math.PI*nn/n)*(x-ax)+Math.sin(theta+Math.PI*(nn/n+1/2))*(y-ay),p)
  51. };
  52. if(sum<Math.pow(r,p)){
  53. return(true);
  54. }else{
  55. return(false);
  56. };
  57. };
  58.  
  59. function blankpixelmap(bd){//bd is value for every pixel
  60. var ba = [];
  61. for(bb=0;bb<width;bb++){
  62. ba[bb] = [];
  63. for(bc=0;bc<height;bc++){
  64. ba[bb][bc] = bd;
  65. };
  66. };
  67. return(ba);
  68. };
  69.  
  70. function hsvtorgb(peaks,h,s,v){
  71. if(peaks.length<2){
  72. peaks = [ [0,1,0,0],[1/6,1,1,0],[2/6,0,1,0],[3/6,0,1,1],[4/6,0,0,1],[5/6,1,0,1] ];
  73. };
  74. if(h<peaks[0][0]){
  75. var h2 = (h+1-peaks[peaks.length-1][0])/(peaks[0][0]+1-peaks[peaks.length-1][0]);
  76. return([ v*(1-s)+v*s*(peaks[peaks.length-1][1]+h2*(peaks[0][1]-peaks[peaks.length-1][1])) , v*(1-s)+v*s*(peaks[peaks.length-1][2]+h2*(peaks[0][2]-peaks[peaks.length-1][2])) , v*(1-s)+v*s*(peaks[peaks.length-1][3]+h2*(peaks[0][3]-peaks[peaks.length-1][3])) ]);
  77. };
  78. for(ba=1;ba<peaks.length;ba++){
  79. if(h<peaks[ba][0]){
  80. var h2 = (h-peaks[ba-1][0])/(peaks[ba][0]-peaks[ba-1][0]);
  81. return([ v*(1-s)+v*s*(peaks[ba-1][1]+h2*(peaks[ba][1]-peaks[ba-1][1])) , v*(1-s)+v*s*(peaks[ba-1][2]+h2*(peaks[ba][2]-peaks[ba-1][2])) , v*(1-s)+v*s*(peaks[ba-1][3]+h2*(peaks[ba][3]-peaks[ba-1][3])) ]);
  82. };
  83. };
  84. var h2 = (h-peaks[peaks.length-1][0])/(peaks[0][0]+1-peaks[peaks.length-1][0]);
  85. return([ v*(1-s)+v*s*(peaks[peaks.length-1][1]+h2*(peaks[0][1]-peaks[peaks.length-1][1])) , v*(1-s)+v*s*(peaks[peaks.length-1][2]+h2*(peaks[0][2]-peaks[peaks.length-1][2])) , v*(1-s)+v*s*(peaks[peaks.length-1][3]+h2*(peaks[0][3]-peaks[peaks.length-1][3])) ]);
  86. };
  87.  
  88. function rgbtohex(rgb){//rgb in array
  89. var hext = ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","f"];
  90. var aa="";
  91. aa+=hext[ Math.floor( rgb[2]*255.99/16 ) ];
  92. aa+=hext[ Math.floor( (rgb[2]*255.99)%16 ) ];
  93. aa+=hext[ Math.floor( rgb[1]*255.99/16 ) ];
  94. aa+=hext[ Math.floor( (rgb[1]*255.99)%16 ) ];
  95. aa+=hext[ Math.floor( rgb[0]*255.99/16 ) ];
  96. aa+=hext[ Math.floor( (rgb[0]*255.99)%16 ) ];
  97. return(aa);
  98. };
  99.  
  100. function draw(frame,hexmap){
  101. /*640x360 header*///var mytext = "424D368C0A0000000000360000002800000080020000680100000100180000000000008C0A0000000000000000000000000000000000";
  102. /*1920x1080 header*/ var mytext = "424D36EC5E000000000036000000280000008007000038040000010018000000000000EC5E0000000000000000000000000000000000";
  103. /*3840x2160 header*/// var mytext = "424D36B07B01000000003600000028000000000F000070080000010018000000000000B07B0100000000000000000000000000000000";
  104. for(ay=0;ay<hexmap[0].length;ay++){
  105. for(ax=0;ax<hexmap.length;ax++){
  106. mytext+=hexmap[ax][ay];
  107. };
  108. };
  109. var fs = require('fs');
  110. var buf = new Buffer.from(mytext, 'hex');
  111. var pad = ["000","00","0",""];
  112. fs.writeFile('img-'+pad[(""+frame).length-1]+frame+'.bmp', buf, (err) => { if (err) throw err; });
  113. };
Advertisement
Add Comment
Please, Sign In to add comment