Skip to content

Instantly share code, notes, and snippets.

@Ram-N
Last active July 7, 2020 00:10
Show Gist options
  • Save Ram-N/ba4277acb2828e86ef5e8bd105086abc to your computer and use it in GitHub Desktop.
Save Ram-N/ba4277acb2828e86ef5e8bd105086abc to your computer and use it in GitHub Desktop.
Perlin Noise Coloring
# The noise value was calculated at each pixel,
# using Processing’s built-in noise function.
# This value was scaled up (by a factor of 10 to 100) and rounded,
# yielding an integer for every pixel in the frame.
# Colors were designated based on this number using a switch.
# Finally, a point/dot was drawn at each pixel, in the assigned color.
# The greater the scaling factor, the thinner and more numerous the noise bands.
# Creates a 2D List of 0's, nCols x nRows large
def makeGrid(nCols, nRows):
grid = []
for i in range(nRows):
# Create an empty list for each row
grid.append([])
for j in range(nRows):
# Pad each column in each row with a 0
grid[i].append(0)
return grid
w, h = 400, 500
factor = 0.03
colr = makeGrid(w, h)
RED = [255, 0, 0]
GREEN = [0, 255, 0]
BLUE = [0, 0, 255]
def setup():
global min_value, max_value
size(w,h)
min_value, max_value = 1000, 0
for x in range(w):
for y in range(h):
colr[x][y] = noise(x * factor, y * factor)
if colr[x][y] < min_value:
min_value = colr[x][y]
if colr[x][y] > max_value:
max_value = colr[x][y]
print(min_value, max_value)
for x in range(w):
for y in range(h):
col = map(colr[x][y], min_value, max_value, 0, 255)
stroke(col)
point(x,y)
# Creates a 2D List of 0's, nCols x nRows large
def makeGrid(nCols, nRows):
grid = []
for i in range(nRows):
# Create an empty list for each row
grid.append([])
for j in range(nRows):
# Pad each column in each row with a 0
grid[i].append(0)
return grid
w, h = 800, 800
xfactor = 50.3
yfactor = 40.3
colr = makeGrid(w, h)
RED = [255, 0, 0]
GREEN = [0, 255, 0]
BLUE = [0, 0, 255]
YELLOW = [0, 255, 255]
MAGENTA = [255, 0, 255]
CYAN = [255, 255, 0]
color_list = [RED, RED, YELLOW, BLUE, CYAN, MAGENTA, GREEN]
def setup():
global min_value, max_value
size(w,h)
min_value, max_value = 1000, 0
for x in range(w):
for y in range(h):
colr[x][y] = noise(x /xfactor, y /yfactor)
if colr[x][y] < min_value:
min_value = colr[x][y]
if colr[x][y] > max_value:
max_value = colr[x][y]
print(min_value, max_value)
for x in range(w):
for y in range(h):
col = map(colr[x][y], min_value, max_value, 0, 6.99)
stroke(*color_list[int(col)])
point(x,y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment