Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include "SwinGame.h"
- #define size 800
- srand(time(NULL));
- struct sample
- {
- int value;
- color clr;
- }
- color get_color(int num)
- {
- float hue = num / 700;
- clr = hsbcolor(hue,0.7,0.8)
- return clr;
- }
- void fill_array(struct sample data[size])
- {
- int i;
- for (i=0;i<size;i++){
- data[i].value = rand() % 700
- data[i].clr = get_color(data[i].value)
- }
- }
- void draw_bar(struct sample data[])
- {
- int i;
- float x;
- float y;
- float rectwidth = 1;
- for(i=0;i<800;i++){
- x = rectwidth * i;
- y = 700 - data[i].value;
- fill_rectangle (data[i].clr, x, y, rectwidth, data[i].value);
- }
- }
- int main()
- open_graphics_window(800, 700)
- {
- srand(time(NULL));
- fill_array(sample data[size]);
- do
- {
- process_events();
- clear_screen(color_white);
- draw_bar(data[i]);
- refresh (60);
- }while(!(window_close_requested() ) );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement