![]() |
|
A little bit of fun for family and friends |
kingnoob
Member #18,984
January 2021
|
My RGB Birth Color is. 1// RGB Birth Color
2// By kingnoob (Michael Sherwin)
3
4#include <stdio.h>
5#include <stdlib.h>
6#include <allegro5/allegro5.h>
7#include <allegro5/allegro_font.h>
8#include <allegro5/allegro_ttf.h>
9#include <allegro5/allegro_primitives.h>
10
11#define BLACK al_map_rgb( 0, 0, 0)
12#define LIGHTSTEEL al_map_rgb(60, 120, 160)
13#define DARKSTEEL al_map_rgb(15, 30, 40)
14
15struct Input {
16 int key;
17 int mbu;
18 int mux;
19 int muy;
20};
21
22struct Input input;
23
24struct Date {
25 float month;
26 float day;
27 float year;
28};
29
30struct Date date;
31
32ALLEGRO_EVENT_QUEUE* queue;
33ALLEGRO_EVENT event;
34ALLEGRO_FONT* font25;
35ALLEGRO_DISPLAY* disp;
36ALLEGRO_COLOR c;
37
38void al_destroy() {
39 al_destroy_font(font25);
40 al_destroy_display(disp);
41 al_destroy_event_queue(queue);
42}
43
44void DrawFrame() {
45 char buf[10];
46 al_clear_to_color(BLACK);
47 al_draw_filled_rectangle(0, 0, 240, 270, DARKSTEEL);
48 al_draw_text(font25, LIGHTSTEEL, 120, 0, ALLEGRO_ALIGN_CENTER, "L or R click in field");
49 al_draw_text(font25, LIGHTSTEEL, 0, 68, 0, "Month");
50 al_draw_text(font25, LIGHTSTEEL, 0, 136, 0, "Day");
51 al_draw_text(font25, LIGHTSTEEL, 0, 204, 0, "Year");
52 al_draw_filled_rectangle(120, 68, 180, 98, LIGHTSTEEL);
53 al_draw_filled_rectangle(120, 136, 180, 166, LIGHTSTEEL);
54 al_draw_filled_rectangle(120, 204, 180, 234, LIGHTSTEEL);
55 _itoa_s(date.month, buf, 10, 10);
56 al_draw_text(font25, DARKSTEEL, 150, 68, ALLEGRO_ALIGN_CENTER, buf);
57 _itoa_s(date.day, buf, 10, 10);
58 al_draw_text(font25, DARKSTEEL, 150, 136, ALLEGRO_ALIGN_CENTER, buf);
59 _itoa_s(date.year, buf, 10, 10);
60 al_draw_text(font25, DARKSTEEL, 150, 204, ALLEGRO_ALIGN_CENTER, buf);
61 c = al_map_rgb(date.month * 21.25, date.day * 8.23, date.year * 2.55);
62 al_draw_filled_rectangle(240, 0, 479, 269, c);
63 al_flip_display();
64}
65
66void ProcessEvent() {
67 if (input.mbu) {
68 if (input.mux >= 120 && input.mux <= 180) {
69 if (input.muy >= 68 && input.muy <= 98) {
70 if (input.mbu == 1) {
71 date.month--;
72 if (date.month < 1) date.month = 12;
73 }
74 else if (input.mbu == 2) {
75 date.month++;
76 if (date.month > 12) date.month = 1;
77 }
78 }
79 else if (input.muy >= 136 && input.muy <= 166) {
80 if (input.mbu == 1) {
81 date.day--;
82 if (date.day < 1) date.day = 31;
83 }
84 else if (input.mbu == 2) {
85 date.day++;
86 if (date.day > 31) date.day = 1;
87 }
88 }
89 else if (input.muy >= 204 && input.muy <= 234) {
90 if (input.mbu == 1) {
91 date.year--;
92 if (date.year < 0) date.year = 99;
93 }
94 else if (input.mbu == 2) {
95 date.year++;
96 if (date.year > 99) date.year = 0;
97 }
98 }
99 }
100 }
101}
102
103bool GetEvent() {
104 input.mbu = false;
105 if (al_get_next_event(queue, &event)) {
106 switch (event.type) {
107 case ALLEGRO_EVENT_DISPLAY_CLOSE:
108 return false;
109 break;
110 case ALLEGRO_EVENT_KEY_DOWN:
111 input.key = event.keyboard.keycode;
112 switch (input.key) {
113 case ALLEGRO_KEY_ESCAPE:
114 return false;
115 break;
116 }
117 case ALLEGRO_EVENT_MOUSE_BUTTON_UP:
118 input.mbu = event.mouse.button;
119 input.mux = event.mouse.x;
120 input.muy = event.mouse.y;
121 break;
122 }
123 }
124 return true;
125}
126
127Initialize() {
128 al_init();
129 al_install_keyboard();
130 al_install_mouse();
131
132 queue = al_create_event_queue();
133
134 disp = al_create_display(480, 270);
135
136 al_init_font_addon();
137 al_init_ttf_addon();
138
139 font25 = al_load_font("DejaVuSans.ttf", 25, 0);
140
141 al_init_primitives_addon();
142
143 al_register_event_source(queue, al_get_keyboard_event_source());
144 al_register_event_source(queue, al_get_mouse_event_source());
145 al_register_event_source(queue, al_get_display_event_source(disp));
146
147 date.month = 1;
148 date.day = 1;
149 date.year = 0;
150}
151
152int main() {
153 bool run = true;
154
155 Initialize();
156
157 while (run) {
158 DrawFrame();
159 run = GetEvent();
160 ProcessEvent();
161 }
162 al_destroy();
163 return 0;
164}
|
bamccaig
Member #7,536
July 2006
![]() |
Neat idea. -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
DanielH
Member #934
January 2001
![]() |
The older you get the bluer you get. What about a normalization? R = (day/30)*255; // normalized 30 days right is original, left is normalized Also, I did day month year not month day year {"name":"612883","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/6\/d602fd8040a08f1b673af64678e2cd5f.png","w":411,"h":223,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/6\/d602fd8040a08f1b673af64678e2cd5f"} |
Eric Johnson
Member #14,841
January 2013
![]() |
RmBeer2
Member #16,660
April 2017
![]() |
a good idea. :3 🌈🌈🌈 🌟 BlackRook WebSite 🌟 C/C++ 🌟 GNU/Linux 🌟 IceCream/Cornet 🌟 🌈🌈🌈 Rm Beer for Emperor 2021! Rm Beer for Ruinous Slave Drained 2022! Rm Beer for Traveler From The Future Warning Not To Enter In 2023! Rm Beer are building a travel machine for Go Back from 2023! |
|