From 7bb0bb513bf6929773d5dae4d466037d7ca8525c Mon Sep 17 00:00:00 2001 From: Xevion Date: Mon, 21 Oct 2019 13:43:16 -0500 Subject: [PATCH] Gradients project --- visuals/Gradients/Gradients.pyde | 50 +++++++++++++++++++++++++++++ visuals/Gradients/sketch.properties | 2 ++ visuals/README.md | 4 ++- 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 visuals/Gradients/Gradients.pyde create mode 100644 visuals/Gradients/sketch.properties diff --git a/visuals/Gradients/Gradients.pyde b/visuals/Gradients/Gradients.pyde new file mode 100644 index 0000000..7d8b891 --- /dev/null +++ b/visuals/Gradients/Gradients.pyde @@ -0,0 +1,50 @@ +import pprint, random, colorsys + +def blend(fromRGB, toRGB, midpoints=10): + arr = [] + R1, G1, B1 = fromRGB + R2, G2, B2 = toRGB + Rdiv = (R1 - R2) / float(midpoints) + Gdiv = (G1 - G2) / float(midpoints) + Bdiv = (B1 - B2) / float(midpoints) + for x in range(floor(midpoints+1)): + R = R1 - (Rdiv * x) + G = G1 - (Gdiv * x) + B = B1 - (Bdiv * x) + arr.append((R, G, B)) + return arr + +def rndTuple(n): + return random.randint(0, n), random.randint(0, n), random.randint(0, n) + +def HSVtuple(): + preH, preS, preV = random.randint(0, 360) / 360.0, 1, 1 + preR, preG, preB = colorsys.hsv_to_rgb(preH, preS, preV) + return preR * 255, preG * 255, preB * 255 + +def regen(): + global arr, precision + precision = 1000.0 + # Generated via RGB randomization + RGB1, RGB2 = rndTuple(255), rndTuple(255) + + # Generated via HSV to RGB randomization + RGB1, RGB2 = HSVtuple(), HSVtuple() + arr = blend(RGB1, RGB2, midpoints=precision) + +def setup(): + size(1000, 1000) + regen() + +pp = pprint.PrettyPrinter() + +def draw(): + global arr, precision + xDiv = width/precision + for x in range(floor(precision)): + fill(*arr[x]) + stroke(0, 0, 0, 0) + rect(0, x * xDiv, width, (x + 1) * xDiv) + +def mouseClicked(): + regen() diff --git a/visuals/Gradients/sketch.properties b/visuals/Gradients/sketch.properties new file mode 100644 index 0000000..2456b0a --- /dev/null +++ b/visuals/Gradients/sketch.properties @@ -0,0 +1,2 @@ +mode=Python +mode.id=jycessing.mode.PythonMode diff --git a/visuals/README.md b/visuals/README.md index 559a85e..2555e44 100644 --- a/visuals/README.md +++ b/visuals/README.md @@ -8,4 +8,6 @@ All my projects attempting to create vivid or interesting visuals using the Proc - **CircleIntersection** Plots circles in places where others aren't, expoonentially becoming slower and slower with each successfully located spot. Somewhat buggy and needs tuning to become much faster using a better algorithm, and probably better methods for deciding where spots are (less random, more organized manner). -- **EquilateralTriangle** Places squares in increasing size whilst rotating. \ No newline at end of file +- **EquilateralTriangle** Places squares in increasing size whilst rotating. + +- **Gradients** Builds simple linear RGB gradients from 1 random color to another. \ No newline at end of file