MrThoe

Maps in P5

Oct 6th, 2020
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. /** Draw a bunch of rectangles that are
  2. * different sizes (use a for loop)
  3. * and different color.
  4. */
  5. var r, g, b; //Color variables
  6. var num, w, h;
  7.  
  8. function setup() {
  9. createCanvas(700, 500);
  10. r = 0;
  11. g = 0;
  12. b = 0;
  13. num = 60;
  14. w = 0;
  15. h = 0;
  16. //noStroke();
  17. }
  18.  
  19. function draw() {
  20. background(220);
  21. fill(255);
  22. for(var i = num; i > 0; i--){
  23. //r = 5*i;
  24. r = map(i, 0, num, 0, 255);
  25. h = map(i, 0, num, 0, height);
  26. w = map(i, 0, num, 0, width);
  27. fill(r, 0, 0);
  28. rect(0, 0,w, h);
  29. }
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment