Skip to content

python3, and made gradient a function #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 45 additions & 38 deletions gradient.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,49 @@
from PIL import Image
import glob, os, math

import sys
from ast import literal_eval as make_tuple
import tupleFunctions as tf

startColor = (66, 138, 255)
endColorX = (65, 255, 217)
endColorY = (118, 65, 255)
size = (500, 500)

im = Image.new("RGB", size, 'black')
pixels = im.load()

deltaX = ((endColorX[0]-startColor[0]) / float(size[0]), (endColorX[1]-startColor[1]) / float(size[0]), (endColorX[2]-startColor[2]) / float(size[0]))
deltaY = ((endColorY[0]-startColor[0]) / float(size[0]), (endColorY[1]-startColor[1]) / float(size[0]), (endColorY[2]-startColor[2]) / float(size[0]))
print deltaX, " DELTA X"
print deltaY, " DELTA Y"
print

thisPixelX = ()
thisPixelY = ()

for j in range(im.size[1]): # for every pixel:
if (j != 0):
thisPixelY = tf.addTuples(thisPixelY, deltaY)
else:
thispixelY = startColor

for i in range(im.size[0]):
if (i == 0 and j == 0) :
thisPixelX = startColor
thisPixelY = startColor
pixels[i,j] = startColor
continue
if (i != 0):
thisPixelX = tf.addTuples(thisPixelX, deltaX)
else:
thisPixelX = startColor
add = tf.divTuple(tf.addTuples(thisPixelY, thisPixelX), 2)
pixels[i,j] = tf.roundTuple(add)

im.show()


def make_gradient(start_color, end_color_x, end_color_y, size):
startColor = start_color
endColorX = end_color_x
endColorY = end_color_y
size = size
im = Image.new("RGB", size, 'black')
pixels = im.load()

deltaX = ((endColorX[0]-startColor[0]) / float(size[0]), (endColorX[1]-startColor[1]) / float(size[0]), (endColorX[2]-startColor[2]) / float(size[0]))
deltaY = ((endColorY[0]-startColor[0]) / float(size[0]), (endColorY[1]-startColor[1]) / float(size[0]), (endColorY[2]-startColor[2]) / float(size[0]))
print(deltaX, " DELTA X")
print(deltaY, " DELTA Y")


thisPixelX = ()
thisPixelY = ()

for j in range(im.size[1]): # for every pixel:
if (j != 0):
thisPixelY = tf.addTuples(thisPixelY, deltaY)
else:
thispixelY = startColor

for i in range(im.size[0]):
if (i == 0 and j == 0) :
thisPixelX = startColor
thisPixelY = startColor
pixels[i,j] = startColor
continue
if (i != 0):
thisPixelX = tf.addTuples(thisPixelX, deltaX)
else:
thisPixelX = startColor
add = tf.divTuple(tf.addTuples(thisPixelY, thisPixelX), 2)
pixels[i,j] = tf.roundTuple(add)

return im

if __name__ == '__main__':
i = make_gradient(make_tuple(sys.argv[1]), make_tuple(sys.argv[2]), make_tuple(sys.argv[3]), make_tuple(sys.argv[4]))
i.show()
2 changes: 1 addition & 1 deletion tupleFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ def roundTuple(x):
z = []
for i in range(len(x)):
z.append(int(math.floor(x[i] + 0.5)))
return tuple(z)
return tuple(z)