Dados digitales [ESP/ENG] | C++

cover by gab.jpg

Programación c++.png

¡Buenas tardes! Acá les traigo un programa un poco más largo que lo habitual... Aunque, conforme lo vean verán muchas cosas conocidas en comparación a los anteriores y eso es porque reciclé bastante código para este programa. Esto debido a que para graficar los números en los dados decidí usar lo expuesto en la serie "Graficando números en consola" (Al final del post están los links si quieres pasarte por allá), también usé un selector que he repetido en varios conversores y también un clásico "do-while" para mantener el proceso hasta que el usuario lo decida.

En cuanto a las librerías usadas hay poco que contar que no haya dicho antes, solo acotaría que "time.h" no es necesaria, me sobró mientras hacía unas pruebas en una lluvia de ideas en busca de qué programa debía hacer. Ahora bien las funciones one,two,three,four,five,six,seven,eight,nine,zero, son para graficar los números en pantalla, como bien dije, este código no es nuevo por acá. Para el "fondo", es decir, el recuadro que rodea el número para representar mejor el dado fue hecho con ceros más grandes, pues lo cierto es que las dimensiones del cero que grafico son cuatro líneas iguales, es decir, un cuadro.

La función "filter" la he colocado para que según sea el número obtenido por la función "random", se grafique correctamente lo que se quiere en pantalla. Como cada función es individual en las graficas, es necesario una condición diferente para cada caso y como son dos dados pues se duplican los casos. Cabe recordar que la primera condición se refiere al eje x, la segunda al eje y, finalmente la tercera al tamaño del número a grafica. Ej: one(x,y,n).

Por tanto para el uno varía un poco al ser pequeño en comparación al espacio ocupado por el resto de los números. Y para el segundo dado es lógico que la distancia en "x" sea mayor pero en "y" se vea cierto patrón y en "n" se mantenga. La función exit solo es el texto que uso a modo de mensaje para informar al usuario que toque un botón para volver al menú, y una pausa. La función "selector" contiene el centro de mando, pues es donde se recibe la elección del usuario en cuanto a como quiere el dado, ya sea de 4,6,8 o 9 lados. Posteriormente usa la función random empezando desde 1 para generar dos número aleatorios y asignarlos a una variable que será considerada por la función filter para graficar. Según sea la configuración de dados elegida, la función random es diferente, pues lógicamente necesitamos que no aparezca un 9 en un dado que se supone va del 1 al 4.

Good afternoon! Here I bring you a program a little bit longer than usual... Although, as you see it you will see many familiar things compared to the previous ones and that's because I recycled a lot of code for this program. This is because to plot the numbers on the dice I decided to use what was exposed in the series "Plotting numbers in console" (At the end of the post are the links if you want to go there), I also used a selector that I have repeated in several converters and also a classic "do-while" to keep the process until the user decides.

As for the libraries used there is little to tell that I haven't said before, I would only point out that "time.h" is not necessary, it was left over while I was doing some brainstorming tests in search of what program I should do. Now the functions one,two,three,four,five,six,seven,eight,nine,zero, are to plot the numbers on the screen, as I said, this code is not new around here. For the "background", that is to say, the box that surrounds the number to better represent the die was made with bigger zeros, because the truth is that the dimensions of the zero that I graph are four equal lines, that is to say, a square.

I have placed the "filter" function so that, depending on the number obtained by the "random" function, the desired number is plotted correctly on the screen. As each function is individual in the graphs, a different condition is necessary for each case, and as there are two dice, the cases are duplicated. Remember that the first condition refers to the x-axis, the second to the y-axis, and finally the third to the size of the number to be plotted. Ex: one(x,y,n).

So for the one it varies a little as it is small compared to the space occupied by the rest of the numbers. And for the second one it is logical that the distance in "x" is bigger but in "y" a certain pattern is seen and in "n" it remains the same. The exit function is just the text I use as a message to inform the user to touch a button to return to the menu, and a pause. The "selector" function contains the command centre, as this is where you receive the user's choice of how they want the die to look, be it 4,6,8 or 9 sided. It then uses the random function starting from 1 to generate two random numbers and assign them to a variable that will be considered by the filter function for plotting. Depending on the dice configuration chosen, the random function is different, as logically we need a 9 not to appear on a die that is supposed to go from 1 to 4.

1.JPG

2.JPG

3.JPG

4.JPG

5.JPG

6.JPG

7.JPG

8.JPG

9.JPG

10.JPG

11.JPG

12.JPG

Programación c++.png

Había olvidado como usar el random pero investigando un poco recordé que la función se llama rand() y para generar a partir de un número en concreto debe iniciar así " n + rand() % l ", siendo "n" el número inicial y "l" el final, entonces "1+ rand() % 9" generará números del 1 al nueve. El main quedó bastante cortito porque ya todo estaba preparado, como bien me han aconsejado en la universidad.

I had forgotten how to use random, but after some research I remembered that the function is called rand() and to generate from a specific number it must start like this " n + rand() % l ", being "n" the initial number and "l" the final one, so "1+ rand() % 9" will generate numbers from 1 to nine. The main was quite short because everything was already prepared, as I have been advised at the university.

13.JPG

14.JPG

15.JPG

Programación c++.png

16.JPG

17.JPG

18.JPG

19.JPG

20.JPG

21.JPG


From Giphy

Programación c++.png

¡Y bueno... Eso es todo por hoy! Estaba pensando que seguro quedaban más coquetos los dados si usaba puntos para representar los números, pero la verdad me emocionaba usar las graficas expuestas antes. Quizás para una versión 2.0 añada más distribuciones de dados y las de pocos "lados" aplique esa idea. Otra cosa que pensaba es que añadir opciones para dados individuales también sería prudente, aunque eso necesitaría un menú algo distinto.

Si te interesa otro tutorial de programación acá te dejo los links a los que he realizado hasta ahora:

And well... That's all for today! I was thinking that for sure the dice would be prettier if I used dots to represent the numbers, but the truth is that I was excited to use the graphs exposed before. Maybe for a 2.0 version I'll add more dice distributions and the ones with few "sides" I'll apply that idea. Another thing I was thinking is that adding options for individual dice would also be prudent, although that would require a slightly different menu.

If you are interested in another programming tutorial here are the links to the ones I have done until now:


Nombre de la publicación / Name of the postLINK
Calculador de datos para un triángulo rectángulo en C++1
Concecionario de autos, ejercicio en JAVA2
Calculador de edad básico C++3
Inversor de números de tres cifras4
¿Cuántos números de 3 cifras existen cuya suma sea 10? - ¡Respondiendo a otro usuario! C++6
Calculadora simple, cifra menos significativa y portada simple C++7
¡Vistazo a BeatUDO! [ESP-ENG] JAVA9
Comprobar si un número de dos cifras es primo C++10
Conversor de pulgadas a 7 unidades distintas C++11
Comprobar si un número es capicúa (Máx 5 cifras) C++12
Comprobador de caracteres C++13
Calculadora de índice de masa corporal C++14
Calculadora de factoriales C++15
Conversor (Grados Celsius - Fahrenheit - Kelvin) C++16
Calculadora de longitud, diametro y área de una circunferencia C++17
Graficando números en consola (0-3) C++18
Graficando números en consola II (4-6) C++19
Graficando números en consola III (7-9) C++20
Calculadora de ecuaciones cuadráticas C++21

Programación c++.png

Puedes seguirme por acá si lo deseas:
You can follow me here if you want:

Diseño sin título.gif

Cuenta secundaria
(Dibujos, edición y juegos) | Secondary account (Drawings, editing and games)



0
0
0.000
5 comments
avatar

Congratulations @gabrielr29! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s) :

You published more than 250 posts.
Your next target is to reach 300 posts.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

To support your work, I also upvoted your post!

Check out the last post from @hivebuzz:

Feedback from the October 1st Hive Power Up Day
Hive Power Up Month Challenge - Winners List
0
0
0.000
avatar

Hola @gabrielr29, Gracias por estar presente en Curaciones Matutinas asiste el próximo Martes a las 10:00 AM.

0
0
0.000