From 3f6b46ad8f0b1e5f8069554461dbca058d9c7911 Mon Sep 17 00:00:00 2001 From: Hunter Zhuang Date: Wed, 11 Oct 2023 20:42:41 -0700 Subject: [PATCH 1/9] feat(RandColorGen): coded base code --- Random Color Generator/RandColorGen.py | 53 ++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Random Color Generator/RandColorGen.py diff --git a/Random Color Generator/RandColorGen.py b/Random Color Generator/RandColorGen.py new file mode 100644 index 0000000..24bcb5f --- /dev/null +++ b/Random Color Generator/RandColorGen.py @@ -0,0 +1,53 @@ +import pygame +import random + + +def GenerateRandomColorValue(): + r = random.randint(0, 255) + g = random.randint(0, 255) + b = random.randint(0, 255) + return (r, g, b) + + +pygame.init() + +height = 750 +width = 750 + +canvas = pygame.display.set_mode((width, height)) +pygame.display.set_caption("Random Color Generator!") +isExit = False +canvas.fill((255, 255, 255)) + +font = pygame.font.Font(pygame.font.get_default_font(), 32) + +# RGB Value +RGBText = font.render("RGB Value: (255 ,255 ,255)", True, (0, 0, 0)) +RGBTextRect = RGBText.get_rect() +RGBTextRect.center = (width // 2, height // 2 - 20) + +# Hex Value +hexText = font.render("Hex Value: #ffffff", True, (0, 0, 0)) +hexTextRect = hexText.get_rect() +hexTextRect.center = (width // 2, height // 2 + 20) +hexTextRect.left = RGBTextRect.left + + +while not isExit: + canvas.blit(RGBText, RGBTextRect) + canvas.blit(hexText, hexTextRect) + + for event in pygame.event.get(): + if event.type == pygame.QUIT: + isExit = True + if event.type == pygame.MOUSEBUTTONUP: + color = GenerateRandomColorValue() + RGBString = "RGB Value: " + str(color) + hexString = "Hex Value: " + str("#%02x%02x%02x" % color) + RGBText = font.render(RGBString, True, (0, 0, 0)) + hexText = font.render(hexString, True, (0, 0, 0)) + print(RGBString + "; " + hexString) + + canvas.fill(color) + + pygame.display.flip() From 25f71a3a5c540eda44207afe4111dc48612cf724 Mon Sep 17 00:00:00 2001 From: Hunter Zhuang Date: Wed, 11 Oct 2023 21:07:12 -0700 Subject: [PATCH 2/9] feat: Determines text color based in luminance --- Random Color Generator/RandColorGen.py | 49 ++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/Random Color Generator/RandColorGen.py b/Random Color Generator/RandColorGen.py index 24bcb5f..0228435 100644 --- a/Random Color Generator/RandColorGen.py +++ b/Random Color Generator/RandColorGen.py @@ -1,14 +1,50 @@ import pygame import random +import math def GenerateRandomColorValue(): - r = random.randint(0, 255) - g = random.randint(0, 255) - b = random.randint(0, 255) + # r = random.randint(0, 255) + # g = random.randint(0, 255) + # b = random.randint(0, 255) + r = 255 + g = 255 + b = 255 + return (r, g, b) +def ReturnTextColor(colorValue): + r = colorValue[0] + g = colorValue[1] + b = colorValue[2] + colors = [r, g, b] + + i = 0 + for c in colors: + c = c / 255.0 + if c <= 0.04045: + c = c / 12.92 + else: + c = math.pow(((c + 0.055) / 1.055), 2.4) + colors[i] = c + i += 1 + + r = colors[0] + g = colors[1] + b = colors[2] + + L = 0.2126 * r + 0.7152 * g + 0.0722 * b + + shouldBeWhite = L > 0.179 + + # shouldBeWhite = (r * 0.299 + g * 0.587 + b * 0.114) > 186 + if shouldBeWhite: + return (0, 0, 0) + else: + return (255, 255, 255) + + pygame.init() height = 750 @@ -22,7 +58,7 @@ def GenerateRandomColorValue(): font = pygame.font.Font(pygame.font.get_default_font(), 32) # RGB Value -RGBText = font.render("RGB Value: (255 ,255 ,255)", True, (0, 0, 0)) +RGBText = font.render("RGB Value: (255, 255, 255)", True, (0, 0, 0)) RGBTextRect = RGBText.get_rect() RGBTextRect.center = (width // 2, height // 2 - 20) @@ -44,8 +80,9 @@ def GenerateRandomColorValue(): color = GenerateRandomColorValue() RGBString = "RGB Value: " + str(color) hexString = "Hex Value: " + str("#%02x%02x%02x" % color) - RGBText = font.render(RGBString, True, (0, 0, 0)) - hexText = font.render(hexString, True, (0, 0, 0)) + TextColor = ReturnTextColor(color) + RGBText = font.render(RGBString, True, TextColor) + hexText = font.render(hexString, True, TextColor) print(RGBString + "; " + hexString) canvas.fill(color) From 002cc97e7c941621a5b16e03370e529374ac61c7 Mon Sep 17 00:00:00 2001 From: Hunter Zhuang Date: Wed, 11 Oct 2023 21:09:21 -0700 Subject: [PATCH 3/9] test: bug tested --- Random Color Generator/RandColorGen.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/Random Color Generator/RandColorGen.py b/Random Color Generator/RandColorGen.py index 0228435..4b8d35b 100644 --- a/Random Color Generator/RandColorGen.py +++ b/Random Color Generator/RandColorGen.py @@ -4,12 +4,9 @@ def GenerateRandomColorValue(): - # r = random.randint(0, 255) - # g = random.randint(0, 255) - # b = random.randint(0, 255) - r = 255 - g = 255 - b = 255 + r = random.randint(0, 255) + g = random.randint(0, 255) + b = random.randint(0, 255) return (r, g, b) @@ -37,8 +34,8 @@ def ReturnTextColor(colorValue): L = 0.2126 * r + 0.7152 * g + 0.0722 * b shouldBeWhite = L > 0.179 - # shouldBeWhite = (r * 0.299 + g * 0.587 + b * 0.114) > 186 + if shouldBeWhite: return (0, 0, 0) else: @@ -47,8 +44,8 @@ def ReturnTextColor(colorValue): pygame.init() -height = 750 -width = 750 +height = 500 +width = 500 canvas = pygame.display.set_mode((width, height)) pygame.display.set_caption("Random Color Generator!") From 1e3ab5c2ac6f125a7bdf078312825169b533446d Mon Sep 17 00:00:00 2001 From: 101zh <67253838+101zh@users.noreply.github.com> Date: Thu, 12 Oct 2023 12:19:02 -0700 Subject: [PATCH 4/9] feat: created README.md --- Random Color Generator/README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Random Color Generator/README.md diff --git a/Random Color Generator/README.md b/Random Color Generator/README.md new file mode 100644 index 0000000..aee2269 --- /dev/null +++ b/Random Color Generator/README.md @@ -0,0 +1,21 @@ +# How to Run +- Make sure you have python 3.8.10 installed +- Make sure you have pygame installed \(How to install [Pygame](#how-to-install-pygame)\) +- Extract Random Color Generator.zip +- Run the program with +```markdown +./Random Color Generator> python RandColorGen.py +``` + +# How to Install Pygame +- After installing python +- Use pip to install Pygame +```markdown +./wherever> pip install pygame +``` + +## Dependencies: +- random library +- math library +- pygame library + From 27f08240a77a109998e1d83cef5d05801bff5a0b Mon Sep 17 00:00:00 2001 From: 101zh <67253838+101zh@users.noreply.github.com> Date: Thu, 12 Oct 2023 12:21:21 -0700 Subject: [PATCH 5/9] feat: uploaded Random Color Generator.zip --- .../Random Color Generator.zip | Bin 0 -> 1264 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Random Color Generator/Random Color Generator.zip diff --git a/Random Color Generator/Random Color Generator.zip b/Random Color Generator/Random Color Generator.zip new file mode 100644 index 0000000000000000000000000000000000000000..a6d0ff66024b03085433fb115df0220456966ae8 GIT binary patch literal 1264 zcmWIWW@Zs#U|`^2C{6MSmp96oFUrio;LO3mzz-A+O3X`f&d-DSFR%TDLSM!gO=GA&g%ljXX}QX7$yHB9@`Jdf44pKKHQ zeTM0e#T@Ak+W$9(2%K+BFxYVQ%d4+1f9_viTBc=Y!+JNx4e4vu?Q3@~TxdM6D%xC-3#u zdvu(hr?c#iyZ@U1)d#gB{C5Ha&R$ru;CJDtf;%?VYAreo)ITqb5n9c*V&3iT*?L{K znP;D5&C7@09vocmEjAzn7hdUN?8% zip+X=O6kz4N%m25wrxx0kejKse-oSTT~$5rnF<-lr>sqCWMQ9|Zo7GD$JrZEEiZ#L zULRGMw&uj-4@Y%ZRK%ovdv$P?J1pOj``Y1w(izs%L6EVd*ZZ)8z~1-kB~C20Rndw&(yXBM%5g%I zx^_zLu{W3AoHM#G$y7z;e z@CuH@8ev+q?LW;B@^5_l;H$gKyzYp2b!o@AsLsU0iRYL6n!Vio#E!#;jT_Rlek?ro zl_$?|!TJmNI@_ivoeS jse`N;TM&b^Kr}l6i!OM82Y9oxfuxv#umnh_v4D60hKDZq literal 0 HcmV?d00001 From a46f47eb68a672dfc86df0d9c2e08e361c423bc1 Mon Sep 17 00:00:00 2001 From: 101zh <67253838+101zh@users.noreply.github.com> Date: Thu, 12 Oct 2023 13:03:27 -0700 Subject: [PATCH 6/9] feat: added how to use section --- Random Color Generator/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Random Color Generator/README.md b/Random Color Generator/README.md index aee2269..0a632e2 100644 --- a/Random Color Generator/README.md +++ b/Random Color Generator/README.md @@ -7,6 +7,10 @@ ./Random Color Generator> python RandColorGen.py ``` +# How to use +- Click on the window to change colors +- The color values are logged in the console and shown on screen + # How to Install Pygame - After installing python - Use pip to install Pygame From 5ece05928a35573a102574bf3ccc1562ae66e56c Mon Sep 17 00:00:00 2001 From: 101zh <67253838+101zh@users.noreply.github.com> Date: Thu, 12 Oct 2023 13:04:59 -0700 Subject: [PATCH 7/9] feat: update zip file --- .../Random Color Generator.zip | Bin 1264 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 Random Color Generator/Random Color Generator.zip diff --git a/Random Color Generator/Random Color Generator.zip b/Random Color Generator/Random Color Generator.zip deleted file mode 100644 index a6d0ff66024b03085433fb115df0220456966ae8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1264 zcmWIWW@Zs#U|`^2C{6MSmp96oFUrio;LO3mzz-A+O3X`f&d-DSFR%TDLSM!gO=GA&g%ljXX}QX7$yHB9@`Jdf44pKKHQ zeTM0e#T@Ak+W$9(2%K+BFxYVQ%d4+1f9_viTBc=Y!+JNx4e4vu?Q3@~TxdM6D%xC-3#u zdvu(hr?c#iyZ@U1)d#gB{C5Ha&R$ru;CJDtf;%?VYAreo)ITqb5n9c*V&3iT*?L{K znP;D5&C7@09vocmEjAzn7hdUN?8% zip+X=O6kz4N%m25wrxx0kejKse-oSTT~$5rnF<-lr>sqCWMQ9|Zo7GD$JrZEEiZ#L zULRGMw&uj-4@Y%ZRK%ovdv$P?J1pOj``Y1w(izs%L6EVd*ZZ)8z~1-kB~C20Rndw&(yXBM%5g%I zx^_zLu{W3AoHM#G$y7z;e z@CuH@8ev+q?LW;B@^5_l;H$gKyzYp2b!o@AsLsU0iRYL6n!Vio#E!#;jT_Rlek?ro zl_$?|!TJmNI@_ivoeS jse`N;TM&b^Kr}l6i!OM82Y9oxfuxv#umnh_v4D60hKDZq From 1bf40e7a8f83ad2755e4f00c6894170933c5b60c Mon Sep 17 00:00:00 2001 From: 101zh <67253838+101zh@users.noreply.github.com> Date: Thu, 12 Oct 2023 13:05:58 -0700 Subject: [PATCH 8/9] feat: update zip file --- .../Random Color Generator.zip | Bin 0 -> 1322 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Random Color Generator/Random Color Generator.zip diff --git a/Random Color Generator/Random Color Generator.zip b/Random Color Generator/Random Color Generator.zip new file mode 100644 index 0000000000000000000000000000000000000000..b4a7389547d303f518484fe54b30d55446d363bb GIT binary patch literal 1322 zcmWIWW@Zs#U|`^2D9`W-mp96oFUrio;LO3mzz-A+O3X`f&d-DSFR%TDLSM!gO=GA&g%ljXX}QX7$yHB9@`Jdf44pKKHQ zeTM0e#T@Ak+W$9(2%K+BFxYVQ%d4+1f9_viTBc=Y!+JNx4e4vu?Q3@~TxdM6D%xC-3#u zdvu(hr?c#iyZ@U1)d#gB{C5Ha&R$ru;CJDtf;%?VYAreo)ITqb5n9c*V&3iT*?L{K znP;D5&C7@09vocmEjAzn7hdUN?8% zip+X=O6kz4N%m25wrxx0kejKse-oSTT~$5rnF<-lr>sqCWMQ9|Zo7GD$JrZEEiZ#L zULRGMw&uj-4@Y%ZRK%ovdv$P?J1pOj``Y1w(izs%L6gu{K~#)t<;~ygH;p%T;_V=L*Mff7@_($*;Rk`4bA; zAKyJRZ{=I_&`ZTTj)~Q_#zpfyPdXP|dT!swM~-a0UC$oOtgDhsi4X8*WD;S(T|xna sn1PW&0Ym`-T6u-68C&Flv_LdF0Si5NR0VjmvVo+SfUpEeFJJ-j057{rDgXcg literal 0 HcmV?d00001 From 95342b901d3e2026cbd7c3b8fb870eb867c0d9c0 Mon Sep 17 00:00:00 2001 From: 101zh <67253838+101zh@users.noreply.github.com> Date: Thu, 12 Oct 2023 13:15:35 -0700 Subject: [PATCH 9/9] feat: added Random Color Generator to list of contents --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 59738ad..9688f7c 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,7 @@ More information on contributing and the general code of conduct for discussion | Planet Simulation | [Planet Simulation](https://github.com/DhanushNehru/Python-Scripts/tree/master/planetSimulation) | A simulation of several planets rotating around the sun. | | Remove Background | [Remove Background](https://github.com/DhanushNehru/Python-Scripts/tree/master/Remove%20Background) | Removes the background of images. | | ROCK-PAPER-SCISSOR | [ROCK-PAPER-SCISSOR](https://github.com/DhanushNehru/Python-Scripts/tree/master/ROCK-PAPER-SCISSOR) | A game of Rock Paper Scissors. | +| Random Color Generator | [Random Color Generator](https://github.com/DhanushNehru/Python-Scripts/tree/master/Random%20Color%20Generator) | A random color generator that will show you the color and values! | Run Then Notify | [Run Then Notify](https://github.com/DhanushNehru/Python-Scripts/tree/master/Run%20Then%20Notify) | Runs a slow command and mails you when it completes execution. | | Selfie with Python | [Selfie_with_Python](https://github.com/DhanushNehru/Python-Scripts/tree/master/Selfie_with_Python) | Take your selfie with python . | | Simple TCP Chat Server | [Simple TCP Chat Server](https://github.com/DhanushNehru/Python-Scripts/tree/master/TCP%20Chat%20Server) | Creates a local server on your LAN for receiving and sending messages! |