Advertisement
Guest User

Untitled

a guest
May 20th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include "SwinGame.h"
  5. #define size 800
  6. srand(time(NULL));
  7. struct sample
  8. {
  9. int value;
  10. color clr;
  11. }
  12.  
  13. color get_color(int num)
  14. {
  15. float hue = num / 700;
  16. clr = hsbcolor(hue,0.7,0.8)
  17. return clr;
  18. }
  19.  
  20. void fill_array(struct sample data[size])
  21. {
  22. int i;
  23. for (i=0;i<size;i++){
  24. data[i].value = rand() % 700
  25. data[i].clr = get_color(data[i].value)
  26. }
  27. }
  28.  
  29. void draw_bar(struct sample data[])
  30. {
  31. int i;
  32. float x;
  33. float y;
  34. float rectwidth = 1;
  35. for(i=0;i<800;i++){
  36. x = rectwidth * i;
  37. y = 700 - data[i].value;
  38. fill_rectangle (data[i].clr, x, y, rectwidth, data[i].value);
  39. }
  40.  
  41. }
  42.  
  43.  
  44. int main()
  45. open_graphics_window(800, 700)
  46. {
  47. srand(time(NULL));
  48. fill_array(sample data[size]);
  49. do
  50. {
  51. process_events();
  52. clear_screen(color_white);
  53. draw_bar(data[i]);
  54. refresh (60);
  55. }while(!(window_close_requested() ) );
  56.  
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement