snt_images.py

Created by gilles-dhaussy

Created on May 06, 2024

1.88 KB


from kandinsky import *

maDisposition=[
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,1,1,0,0,2,0,0,2,0,3,3,3,3,3],
[0,1,0,0,1,0,2,2,0,2,0,0,0,3,0,0],
[0,1,0,0,0,0,2,2,0,2,0,0,0,3,0,0],
[0,0,1,1,0,0,2,2,2,2,0,0,0,3,0,0],
[0,0,0,0,1,0,2,0,2,2,0,0,0,3,0,0],
[0,1,0,0,1,0,2,0,2,2,0,0,0,3,0,0],
[0,0,1,1,0,0,2,0,0,2,0,0,0,3,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,4,4,0,0,0,0,0,5,0,0,6,6,0,0],
[0,4,0,0,4,0,0,0,0,5,0,6,0,0,6,0],
[0,0,0,0,4,0,0,0,0,5,0,6,0,0,6,0],
[0,0,0,4,0,0,0,5,5,5,0,6,6,6,0,0],
[0,0,4,4,0,0,5,0,0,5,0,6,0,0,0,0],
[0,4,4,0,0,0,5,0,0,5,0,6,0,0,6,0],
[0,4,4,4,4,0,0,5,5,5,0,0,6,6,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]

maPalette=[(0,0,0),(255,0,0),
(0,255,0),(0,0,255),(0,255,255),
(255,0,255),(255,255,0)]

monImage=(maDisposition,maPalette)

def affichage(imageModif=None):
  x0,y0=0,0
  t=10
  h=len(maDisposition)
  l=len(maDisposition[0])
  y=y0
  for ligne in maDisposition:
    x=x0
    for nCouleur in ligne:
      fill_rect(x,y,t,t,
            maPalette[nCouleur])
      x+=t
    y+=t
  draw_string("IMAGE D'ORIGINE",
              x0,y)
  if imageModif:
    x1=x0+l*t
    y1=y0
    dispositionModif=imageModif[0]
    paletteModif=imageModif[1]
    y=y1
    for ligne in dispositionModif:
      x=x1
      for nCouleur in ligne:
        fill_rect(x,y,t,t,
        paletteModif[nCouleur])
        x+=t
      y+=t
    draw_string("IMAGE MODIFIEE",
                x1,y)

def compR(image=monImage):
  disposition,palette=image
  paletteModif=[]
  for couleur in palette:
    R,V,B=couleur
    paletteModif.append((R,0,0))
  return (disposition,paletteModif)

def retournH(image=monImage):
  disposition,palette=image
  h=len(disposition)
  l=len(disposition[0])
  dispositionModif=[
    [0 for j in range(l)]
    for i in range(h)]
  for i in range(h):
    for j in range(l):
      dispositionModif[i][j]=\
      disposition[i][l-1-j]
  return (dispositionModif,palette)

affichage()

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 cookies policy.