#include #include "Graphics.h" Graphics graphics; float blue_color = 230; float speed_cloud = 30; float speed_sun = 60; float ray_of_light = 0; int sun_light_direction = 1; typedef struct{ float x; float y; int radius; } position; position sun; position cloud; void refresh_sun_light(){ float factor_sun = graphics.GetElapsedTime() * speed_sun; ray_of_light += (sun_light_direction * factor_sun); if(ray_of_light <= -10) sun_light_direction = 1; else if(ray_of_light >= 10) sun_light_direction = -1; } void refresh_sky_color(){ float factor_cloud = graphics.GetElapsedTime() * speed_cloud; if((sun.x + sun.radius) > cloud.x && cloud.x > (sun.x - sun.radius) && blue_color > 50) blue_color -= factor_cloud; else if((sun.x + sun.radius) > (cloud.x + 150) && blue_color <230) blue_color += factor_cloud; cloud.x -= factor_cloud; if(cloud.x <= -150) cloud.x = 800; } void MainLoop() { refresh_sun_light(); refresh_sky_color(); //Set Sky Color graphics.SetBackgroundColor(0, blue_color - 10, blue_color); // Rays of Light graphics.SetColor(255, 255, 0); // set color yellow - sun graphics.SetLineWidth(5); graphics.DrawLine2D(50, 500, 250, 500); // sun light horizontal graphics.DrawLine2D(150, 400, 150, 600); // sun light vertical graphics.DrawLine2D(100 - ray_of_light, 450 - ray_of_light, 200+ ray_of_light, 550 + ray_of_light); graphics.DrawLine2D(100 - ray_of_light, 550 + ray_of_light, 200+ ray_of_light, 450 - ray_of_light); // Sun graphics.FillCircle2D(sun.x, sun.y, sun.radius, 100); // Tree graphics.SetColor(120, 93, 5); // Tree - Brown graphics.FillRectangle2D(650,100,675,210); graphics.SetColor(61, 166, 23); // Tree - Dark Green graphics.FillCircle2D(663, 270, 70, 100); // Home graphics.SetColor(145, 147, 148); // Home - Gray graphics.FillRectangle2D(200,100,400,300); graphics.SetColor(120, 93, 5); // Door - Brown graphics.FillRectangle2D(325,100,375,250); graphics.SetColor(0, 0, 0); // Door handle - Brown graphics.FillCircle2D(330, 175, 5, 30); graphics.SetColor(24, 5, 120); // Window - Dark Blue graphics.FillRectangle2D(220,170,280,250); graphics.SetColor(255, 191, 0); // Roof - Orange graphics.FillTriangle2D(200,300,400,300,300,430); // Cloud graphics.SetColor(255,255,255); // Cloud - White graphics.FillCircle2D(cloud.x, cloud.y, cloud.radius, 100); graphics.FillCircle2D(cloud.x + 40, cloud.y, cloud.radius, 100); graphics.FillCircle2D(cloud.x + 80, cloud.y, cloud.radius, 100); graphics.FillCircle2D(cloud.x + 120, cloud.y, cloud.radius, 100); // Glass graphics.SetColor(61, 166, 23); // Glass - Green graphics.FillRectangle2D(0,0,800,100); } void Lista05(){ sun.x = 150; sun.y = 500; sun.radius = 50; cloud.x = 600; cloud.y = 500; cloud.radius = 30; graphics.CreateMainWindow(800, 600, "Ex. 05"); graphics.SetMainLoop(MainLoop); graphics.StartMainLoop(); } int main (void) { Lista05(); return 0; }