colormtx.py

Created by ews31415

Created on October 18, 2021

476 Bytes

This script generates a color matrix of random integers 1 through 9, each entry its own colors. Numbers and colors can repeat.


from math import *
from random import *
from kandinsky import *

# 2020-08-25 EWS

# color matrices
# red
mr=[0,21,0,75,255,255,101,255,255]
# green
mg=[158,96,0,0,0,0,67,127,223]
# blue
mb=[96,189,128,130,0,127,33,39,0]

# set up matrix
mat=[[0,0,0],[0,0,0],[0,0,0]]

# random numbers
for r in range(3):
  for c in range(3):
    mat[r][c]=randint(1,9)
    x=80+80*c
    y=60+60*r
    s=mat[r][c]
    draw_string(str(s),x,y,color(mr[s-1],mg[s-1],mb[s-1]))

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our <a href="https://www.numworks.com/legal/cookies-policy/">cookies policy</a>.