| Sane |
Sep 27th, 2005 6:52 PM |
I'm ignorant!
For Comp Science class, we had to draw a picture using drawfillbox, drawstar, drawfilloval, etc... in Turing (Pic.FileNew is banned).
Well that's just complete n00b right?
So I made this program in Python:
:
a = raw_input("Enter Image Name: ")
b = raw_input("Enter Output Name: ")
c = input("Reduce Size By What Degree: ")
d = raw_input("Transparency? ")
import pygame
pygame.init()
print "Initialized Program"
palette = [(255, 255, 255), (0, 0, 128), (0, 128, 0), (0, 128, 128), (128, 0, 0),
(128, 0, 128), (128, 128, 0), (0, 0, 0), (192, 192, 192), (0, 0, 255),
(0, 255, 0), (0, 255, 255), (255, 0, 0), (255, 0, 255), (255, 255, 0),
(128, 128, 128), (0, 0, 0), (20, 20, 20), (32, 32, 32), (44, 44, 44),
(56, 56, 56), (69, 69, 69), (81, 81, 81), (97, 97, 97), (113, 113, 113),
(130, 130, 130), (146, 146, 146), (162, 162, 162), (182, 182, 182), (203, 203, 203),
(227, 227, 227), (255, 255, 255), (0, 0, 255), (65, 0, 255), (125, 0, 255),
(190, 0, 255), (255, 0, 255), (255, 0, 190), (255, 0, 125), (255, 0, 65),
(255, 0, 0), (255, 65, 0), (255, 125, 0), (255, 190, 0), (255, 255, 0),
(190, 255, 0), (125, 255, 0), (65, 255, 0), (0, 255, 0), (0, 255, 65),
(0, 255, 125), (0, 255, 190), (0, 255, 255), (0, 190, 255), (0, 125, 255),
(0, 65, 255), (125, 125, 255), (158, 125, 255), (190, 125, 255), (223, 125, 255),
(255, 125, 255), (255, 125, 223), (255, 125, 190), (255, 125, 158), (255, 125, 125),
(255, 158, 125), (255, 190, 125), (255, 223, 125), (255, 255, 125), (223, 255, 125),
(190, 255, 125), (158, 255, 125), (125, 255, 125), (125, 255, 158), (125, 255, 190),
(125, 255, 223), (125, 255, 255), (125, 223, 255), (125, 190, 255), (125, 158, 255),
(182, 182, 255), (199, 182, 255), (219, 182, 255), (235, 182, 255), (255, 182, 255),
(255, 182, 235), (255, 182, 219), (255, 182, 199), (255, 182, 182), (255, 199, 182),
(255, 219, 182), (255, 235, 182), (255, 255, 182), (235, 255, 182), (219, 255, 182),
(199, 255, 182), (182, 255, 182), (182, 255, 199), (182, 255, 219), (182, 255, 235),
(182, 255, 255), (182, 235, 255), (182, 219, 255), (182, 199, 255), (0, 0, 113),
(28, 0, 113), (56, 0, 113), (85, 0, 113), (113, 0, 113), (113, 0, 85),
(113, 0, 56), (113, 0, 28), (113, 0, 0), (113, 28, 0), (113, 56, 0),
(113, 85, 0), (113, 113, 0), (85, 113, 0), (56, 113, 0), (28, 113, 0),
(0, 113, 0), (0, 113, 28), (0, 113, 56), (0, 113, 85), (0, 113, 113),
(0, 85, 113), (0, 56, 113), (0, 28, 113), (56, 56, 113), (69, 56, 113),
(85, 56, 113), (97, 56, 113), (113, 56, 113), (113, 56, 97), (113, 56, 85),
(113, 56, 69), (113, 56, 56), (113, 69, 56), (113, 85, 56), (113, 97, 56),
(113, 113, 56), (97, 113, 56), (85, 113, 56), (69, 113, 56), (56, 113, 56),
(56, 113, 69), (56, 113, 85), (56, 113, 97), (56, 113, 113), (56, 97, 113),
(56, 85, 113), (56, 69, 113), (81, 81, 113), (89, 81, 113), (97, 81, 113),
(105, 81, 113), (113, 81, 113), (113, 81, 105), (113, 81, 97), (113, 81, 89),
(113, 81, 81), (113, 89, 81), (113, 97, 81), (113, 105, 81), (113, 113, 81),
(105, 113, 81), (97, 113, 81), (89, 113, 81), (81, 113, 81), (81, 113, 89),
(81, 113, 97), (81, 113, 105), (81, 113, 113), (81, 105, 113), (81, 97, 113),
(81, 89, 113), (0, 0, 65), (16, 0, 65), (32, 0, 65), (48, 0, 65),
(65, 0, 65), (65, 0, 48), (65, 0, 32), (65, 0, 16), (65, 0, 0),
(65, 16, 0), (65, 32, 0), (65, 48, 0), (65, 65, 0), (48, 65, 0),
(32, 65, 0), (16, 65, 0), (0, 65, 0), (0, 65, 16), (0, 65, 32),
(0, 65, 48), (0, 65, 65), (0, 48, 65), (0, 32, 65), (0, 16, 65),
(32, 32, 65), (40, 32, 65), (48, 32, 65), (56, 32, 65), (65, 32, 65),
(65, 32, 56), (65, 32, 48), (65, 32, 40), (65, 32, 32), (65, 40, 32),
(65, 48, 32), (65, 56, 32), (65, 65, 32), (56, 65, 32), (48, 65, 32),
(40, 65, 32), (32, 65, 32), (32, 65, 40), (32, 65, 48), (32, 65, 56),
(32, 65, 65), (32, 56, 65), (32, 48, 65), (32, 40, 65), (44, 44, 65),
(48, 44, 65), (52, 44, 65), (60, 44, 65), (65, 44, 65), (65, 44, 60),
(65, 44, 52), (65, 44, 48), (65, 44, 44), (65, 48, 44), (65, 52, 44),
(65, 60, 44), (65, 65, 44), (60, 65, 44), (52, 65, 44), (48, 65, 44),
(44, 65, 44), (44, 65, 48), (44, 65, 52), (44, 65, 60), (44, 65, 65),
(44, 60, 65), (44, 52, 65), (44, 48, 65), (0, 0, 0), (0, 0, 0),
(0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0)]
print "Got Palette"
image = pygame.image.load(a)
image = pygame.transform.scale(image, ((image.get_width()/c,image.get_height()/c)))
print "Prepared Image"
def get_8bit(rgb):
R = []
for x in range(255):
n = palette[x]
Ra = abs(n[0]-rgb[0])
Rb = abs(n[1]-rgb[1])
Rc = abs(n[2]-rgb[2])
R.append( [Ra+Rb+Rc, x, max([Ra,Rb,Rc]), n] )
R = min(R)
return R[1], str(R[2]), R[3]
m = ['setscreen("graphics:800;600")',
'var x, y : int',
'x := 100',
'y := 100',
'procedure draw_%s (x, y : int)'%(a[:-4]),
' %s ... old color(RGB) | new color(RGB) | difference(RGB)'%('%')]
exec "d = %s"%(d)
print "Prepared Code and Cases"
total = 0
trans = 0
i = 0
ii = image.get_width()*image.get_height()
for x in range(image.get_width()):
for y in range(image.get_height()):
i += 1
if not y%100:
print "%",int(round(100.0/float(ii)*float(i)))
n = image.get_at((x,y))[:3]
if n != d:
eBit = get_8bit(n)
m.append(" drawdot (%s + x, %s + y, %s) %s %s | %s | %s"%(x, image.get_height()-y, eBit[0], "%", n, eBit[2], eBit[1]))
total += int(eBit[1])
else:trans += 1
m = m[:4] + ["",
"/*",
"Created from: %s"%(a),
"Reduced by: x%s"%(c),
"Transparancy (RGB): %s"%(str(d)),
"Transparent Dots: %s"%(trans),
"Drawn Dots: %s"%(ii-trans),
"Total Color Loss: %s"%(total),
"Average Color Loss: %s"%(float(total)/float(ii-trans)),
"",
"Generated by Aaron Voelker's Python Program (Sept 27, 2005)",
"*/",
""] + m[4:] + [
'end draw_%s'%(a[:-4]),
'',
'draw_%s (x, y)'%(a[:-4])]
print "% 100\nFinished Code"
try:
file = open(b,'w')
file.write('\n'.join(m))
file.close()
print "Save Complete"
except:
print "Save Failed"
Which creates a program in Turing that will draw whatever picture you ran through that program.
http://1v7.com/drsane/gingerale.txt << me with a gingerale-box over my head
But if you're going to use my program to do manual graphics in Turing, please give credit to my program (as if anyone uses Turing).
Haha.
|