Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. var lastkey
  2. var isPlaying
  3. var pressedKey
  4. var lastKey
  5. let input, button, greeting;
  6.  
  7. function drawImage(url) {
  8. console.log("drawing " + url)
  9. img_src = url.hits[0].previewURL
  10. console.log(img_src) // .webformatURL for better qual
  11. img = createImg(img_src);
  12. // img.hide();
  13. translate(random(width/2), random(height/2));
  14. image(img, 0,0, 200,200)
  15.  
  16. }
  17.  
  18. function removebg(img_url) {
  19. api_key = "91qzrM9BMwn75yBVsNDwdpyD"
  20. ops = {
  21. formData: {
  22. image_url: img_url,
  23. size: 'auto',
  24. },
  25. headers: {
  26. 'X-Api-Key': api_key
  27. },
  28. }
  29. fetch('https://api.remove.bg/v1.0/removebg', {
  30. method: 'post',
  31. body: JSON.stringify(opts)
  32. }).then(function(response) {
  33. return response.json();
  34. }).then(function(data) {
  35. console.log(data)
  36. });
  37. }
  38.  
  39. function greet() {
  40.  
  41. const words_str = input.value();
  42. const words = words_str.split(" ")
  43. input.value('');
  44. // console.log(words)
  45. words.forEach( (word) =>{
  46. console.log(word)
  47. img_url = "https://pixabay.com/api/?key=15410647-429fc66d6350cf8659ace2110&q="+word+"&image_type=photo"
  48. img_json = loadJSON(img_url, drawImage)
  49. fill(random(255), 255, 255);
  50. translate(random(width), random(height));
  51. rotate(random(2 * PI));
  52. text(name, 0, 0);
  53.  
  54. } )
  55.  
  56. for (let i = 0; i < 200; i++) {
  57. push();
  58. fill(random(255), 255, 255);
  59. translate(random(width), random(height));
  60. rotate(random(2 * PI));
  61. text(name, 0, 0);
  62. pop();
  63. }
  64. }
  65.  
  66. function preload() {
  67. }
  68.  
  69. function setup() {
  70. createCanvas(windowWidth, windowHeight);
  71. background("black")
  72. // fill("black")
  73. isPlaying = false;
  74. lastKey = ""
  75. input = createInput();
  76. input.position(20, 65);
  77.  
  78. button = createButton('submit');
  79. button.position(input.x + input.width, 65);
  80. button.mousePressed(greet);
  81.  
  82. greeting = createElement('h2', 'what is your name?');
  83. greeting.position(20, 5);
  84.  
  85. textAlign(CENTER);
  86. textSize(50);
  87. }
  88.  
  89.  
  90. function draw() {
  91. pressedKey = key
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement