Skip to content

Instantly share code, notes, and snippets.

@GrAndSE
Created August 15, 2012 17:02
Show Gist options
  • Save GrAndSE/3361621 to your computer and use it in GitHub Desktop.
Save GrAndSE/3361621 to your computer and use it in GitHub Desktop.
soy.widgets.Canvas example
#!/usr/bin/env python3
from random import randint, random
from time import sleep
import soy
client = soy.Client()
tex = soy.textures.Texture()
tex.size = soy.atoms.Size((16, 16))
tex.smooth = False
can = soy.widgets.Canvas(client.window, tex)
colors = (
soy.atoms.Color('blue'),
soy.atoms.Color('cyan'),
soy.atoms.Color('green'),
soy.atoms.Color('white'),
soy.atoms.Color('yellow'),
soy.atoms.Color('red'),
soy.atoms.Color('pink'),
soy.atoms.Color('grey')
)
for i in range(256):
tex[i] = colors[randint(0, len(colors) - 1)]
while True:
colors[randint(0, len(colors) - 1)].red += int(random() * 2) + 1
colors[randint(0, len(colors) - 1)].green += int(random() * 2) + 1
colors[randint(0, len(colors) - 1)].blue += int(random() * 2) + 1
pos = randint(0, 255)
tex[pos] = colors[randint(0, len(colors) - 1)]
print(tex[pos])
can = soy.widgets.Canvas(client.window, tex)
sleep(.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment