Last active
December 19, 2022 05:36
-
-
Save dreamsmasher/1cc66f9cc0f069d648127ae285ea3730 to your computer and use it in GitHub Desktop.
Turns a string of text, such as a link, into a flag.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- | |
Usage: ./FlagObfuscate [string to obfuscate] | |
Gloss doesn't support image export unfortunately, and the library gloss-export doesn't compile at the moment. | |
You'll have to take a screenshot or rewrite this with better tooling. | |
Use this tool to promote any links you want, fuck Elon Musk. | |
-} | |
module Main where | |
import Numeric (showHex) | |
import Graphics.Gloss | |
import System.Environment (getArgs) | |
import Data.Char (ord) | |
import Data.Bifunctor (Bifunctor (..)) | |
colorize :: String -> ([Color], [Int]) | |
colorize = go . map ord where | |
go (x : y : z : xs) = first (makeColorI x y z 256 :) $ go xs | |
go xs = ([], xs) | |
makeFlag :: [Color] -> Picture | |
makeFlag colors = mconcat | |
$ zipWith color colors | |
$ map (\y -> translate 0 (y * rowHeight) $ rectangleSolid flagWidth rowHeight) [0..] where | |
rowHeight = fromIntegral $ flagHeight `div` length colors | |
flagHeight :: Int | |
flagHeight = 500 | |
flagWidth :: Float | |
flagWidth = 750 | |
extraText :: [Color] -> [Int] -> Picture | |
extraText colors extras = translate xDiff 0 $ color textColor vals where | |
xDiff = case extras of | |
[_] -> 90 | |
_ -> -50 | |
vals = text $ case extras of | |
[] -> "" | |
_ -> ('+' : concatMap (`showHex` "") extras) | |
(r, g, b, a) = rgbaOfColor $ last colors | |
textColor = if r + g + b + a <= 512 then white else black | |
renderFlag :: String -> Picture | |
renderFlag s = makeFlag colors <> extraText colors extras where | |
(colors, extras) = colorize s | |
showFlag :: String -> IO () | |
showFlag s = display (InWindow "flag" (2000, 2000) (0, 0)) white $ renderFlag s | |
main :: IO () | |
main = getArgs >>= showFlag . head |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment