avatarJim McAulay🍁 I'm nobody. Are you a nobody too?

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

1659

Abstract

(<span class="hljs-number">255</span>)</pre></div><div id="dbdb"><pre><span class="hljs-keyword">for</span> <span class="hljs-selector-tag">i</span> <span class="hljs-keyword">in</span> range (<span class="hljs-number">6</span>): X = random<span class="hljs-selector-class">.randrange</span> (-<span class="hljs-number">250</span>,<span class="hljs-number">250</span>) Y = random<span class="hljs-selector-class">.randrange</span> (-<span class="hljs-number">250</span>,<span class="hljs-number">250</span>) T<span class="hljs-selector-class">.penup</span> () T<span class="hljs-selector-class">.goto</span> (X,Y) T<span class="hljs-selector-class">.pendown</span> () R= random<span class="hljs-selector-class">.randrange</span>(<span class="hljs-number">256</span>) G= random<span class="hljs-selector-class">.randrange</span>(<span class="hljs-number">256</span>) B= random<span class="hljs-selector-class">.randrange</span>(<span class="hljs-number">256</span>) total = (R+B+G)</pre></div><div id="64b3"><pre> <span class="hljs-keyword">if</span> G > R: R1 = <span class="hljs-type">G</span> <span class="hljs-variable">B1</span> <span class="hljs-operator">=</span> <span class="hljs-type">G</span> <span class="hljs-variable">G1</span> <span class="hljs-operator">=</span> R <span class="hljs-keyword">if</span> G > B: R1 = <span class="hljs-type">G</span> <span class="hljs-variable">B1</span> <span class="hljs-operator">=</span> <span class="hljs-type">G</span> <span class="hljs-variable">G1</span> <span class="hljs-operator">=</span> B <span cla

Options

ss="hljs-keyword">else</span>: R1 = <span class="hljs-type">B</span> <span class="hljs-variable">B1</span> <span class="hljs-operator">=</span> <span class="hljs-type">R</span> <span class="hljs-variable">G1</span> <span class="hljs-operator">=</span> G <span class="hljs-keyword">if</span> total <<span class="hljs-number">200</span>: R1 = <span class="hljs-type">R</span> <span class="hljs-variable">B1</span> <span class="hljs-operator">=</span> <span class="hljs-type">B</span> <span class="hljs-variable">G1</span> <span class="hljs-operator">=</span> <span class="hljs-type">G</span> <span class="hljs-variable">R</span> <span class="hljs-operator">=</span> B = G = <span class="hljs-number">0</span> <span class="hljs-keyword">if</span> total > <span class="hljs-number">600</span>: R1 = B1 = G1 = <span class="hljs-number">255</span></pre></div><div id="93f5"><pre> T.color <span class="hljs-comment">(R,G,B)</span> T.dot <span class="hljs-comment">(60)</span> T.color <span class="hljs-comment">(R1,G1,B1)</span></pre></div><div id="0e1c"><pre> <span class="hljs-attribute">T</span>.dot (<span class="hljs-number">30</span>)</pre></div><p id="a341"><a href="https://readmedium.com/c4d5fe0b9b6c?source=post_page-----acf8106ab83d----------------------">Jim McAulay🍁</a> says “I’ve been shopping and bought a pair of winter socks. Now I can wash the summer ones.”</p><figure id="eef9"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*NXV_Lh2xjTufB3qQ.png"><figcaption>Buy me a cofee</figcaption></figure><p id="a528">89–88</p></article></body>

Complementary Colors With Python Turtle

A random generator

Source screenshot my computer

In this lesson the challenge is to produce complementary color pairs. That is pairs of colors randomly taken from the full range available in the turtle module that produce the strongest contrast when place together.

If red is the predominant color it will be paired with blue and vice versa.

If green is the predominant color it will be paired with an appropriate red blue combination.

Very dark colors will be paired with white and very light colors will be paired with black.

The code builds on on concepts from previous lessons. A new concept introduce here is the ability, unique to Python, to string together variables.

R = B = G = 0

R1 = B1 = G1 = 255

The full code:

import turtle as T 
import random
T.colormode (255)
for i in range (6):
    X = random.randrange (-250,250)
    Y = random.randrange (-250,250)
    T.penup ()
    T.goto (X,Y)
    T.pendown () 
    R= random.randrange(256)
    G= random.randrange(256)
    B= random.randrange(256)
    total = (R+B+G)
   if  G > R:
        R1 = G
        B1 = G
        G1 = R
    if G > B:
        R1 = G
        B1 = G
        G1 = B
    else:
        R1 = B
        B1 = R
        G1 = G
    if total <200:
        R1 = R
        B1 = B
        G1 = G
        R = B = G = 0
    if total > 600:
        R1 = B1 = G1 = 255
    T.color (R,G,B)
    T.dot (60)
    T.color  (R1,G1,B1)
    T.dot (30)

Jim McAulay🍁 says “I’ve been shopping and bought a pair of winter socks. Now I can wash the summer ones.”

Buy me a cofee

89–88

Technology
Python
Jim Mcaulay
Illumination
Python Turtle
Recommended from ReadMedium