Skip to content
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# P_1_0_01
#
# Generative Gestaltung, ISBN: 978-3-87439-759-9
# First Edition, Hermann Schmidt, Mainz, 2009
# Hartmut Bohnacker, Benedikt Gross, Julia Laub, Claudius Lazzeroni
# Copyright 2009 Hartmut Bohnacker, Benedikt Gross, Julia Laub, Claudius Lazzeroni
#
# http://www.generative-gestaltung.de
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Ported from the Processing original to processing_py.

# changing colors and size by moving the mouse
#
# MOUSE
# position x : size
# position y : color
#
# KEYS
# s : save png
from datetime import datetime

from processing_py import *


def setup():
size(720, 720)
no_cursor()


def draw():
rect_mode(CENTER)
no_stroke()
background(hsva(mouse_y / 2, 1.0, 1.0))

fill(hsva(360 - mouse_y / 2, 1.0, 1.0))
rect(360, 360, mouse_x + 1, mouse_x + 1)


def key_pressed():
if key == "s" or key == "S":
save_frame(timestamp() + "_##.png")


def timestamp():
return datetime.now().strftime("%y%m%d_%H%M%S")


run()
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# P_1_1_1_01
#
# Generative Gestaltung, ISBN: 978-3-87439-759-9
# First Edition, Hermann Schmidt, Mainz, 2009
# Hartmut Bohnacker, Benedikt Gross, Julia Laub, Claudius Lazzeroni
# Copyright 2009 Hartmut Bohnacker, Benedikt Gross, Julia Laub, Claudius Lazzeroni
#
# http://www.generative-gestaltung.de
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Ported from the Processing original to processing_py.

# draw the color spectrum by moving the mouse
#
# MOUSE
# position x/y : resolution
#
# KEYS
# s : save png
from datetime import datetime

from processing_py import *

step_x = 0
step_y = 0


def setup():
size(800, 400)
background(0.0)


def draw():
global step_x, step_y
no_stroke()

step_x = int(mouse_x) + 2
step_y = int(mouse_y) + 2
for grid_y in range(0, height, step_y):
for grid_x in range(0, width, step_x):
fill(hsva(grid_x / width * 360, (height - grid_y) / height, 1.0))
rect(grid_x, grid_y, step_x, step_y)


def key_pressed():
if key == "s" or key == "S":
save_frame(timestamp() + "_##.png")


# timestamp
def timestamp():
return datetime.now().strftime("%y%m%d_%H%M%S")


run()
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# P_1_1_2_01
#
# Generative Gestaltung, ISBN: 978-3-87439-759-9
# First Edition, Hermann Schmidt, Mainz, 2009
# Hartmut Bohnacker, Benedikt Gross, Julia Laub, Claudius Lazzeroni
# Copyright 2009 Hartmut Bohnacker, Benedikt Gross, Julia Laub, Claudius Lazzeroni
#
# http://www.generative-gestaltung.de
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Ported from the Processing original to processing_py.

# changing the color circle by moving the mouse.
#
# MOUSE
# position x : saturation
# position y : brighness
#
# KEYS
# 1-5 : number of segments
# s : save png
from datetime import datetime

from processing_py import *

segment_count = 360
radius = 300


def setup():
size(800, 800)


def draw():
no_stroke()
background(1.0)

angle_step = 360 // segment_count

begin_shape(TRIANGLE_FAN)
vertex(width / 2, height / 2)
for angle in range(0, 361, angle_step):
vx = width / 2 + cos(radians(angle)) * radius
vy = height / 2 + sin(radians(angle)) * radius
vertex(vx, vy)
fill(hsva(angle, mouse_x / width, mouse_y / height)) # GAP: per-vertex fill() inside begin_shape() is ignored, the whole shape takes one color
end_shape()


def key_released():
global segment_count
if key == "s" or key == "S":
save_frame(timestamp() + "_##.png")

if key == "1":
segment_count = 360
elif key == "2":
segment_count = 45
elif key == "3":
segment_count = 24
elif key == "4":
segment_count = 12
elif key == "5":
segment_count = 6


def timestamp():
return datetime.now().strftime("%y%m%d_%H%M%S")


run()
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# P_1_2_1_01
#
# Generative Gestaltung, ISBN: 978-3-87439-759-9
# First Edition, Hermann Schmidt, Mainz, 2009
# Hartmut Bohnacker, Benedikt Gross, Julia Laub, Claudius Lazzeroni
# Copyright 2009 Hartmut Bohnacker, Benedikt Gross, Julia Laub, Claudius Lazzeroni
#
# http://www.generative-gestaltung.de
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Ported from the Processing original to processing_py.

# shows how to interpolate colors in different styles/ color modes
#
# MOUSE
# left click : new random color set
# position x : interpolation resolution
# position y : row count
#
# KEYS
# 1-2 : switch interpolation style
# s : save png
# c : save color palette
import struct
from datetime import datetime

from processing_py import *

tile_count_x = 2
tile_count_y = 10

colors_left = [None] * tile_count_y
colors_right = [None] * tile_count_y
colors = []

interpolate_shortest = True


def setup():
size(800, 800)
no_stroke()
shake_colors()


def draw():
global tile_count_x, tile_count_y, colors
tile_count_x = int(remap(mouse_x, 0, width, 2, 100))
tile_count_y = int(remap(mouse_y, 0, height, 2, 10))
tile_width = width / tile_count_x
tile_height = height / tile_count_y

# just for ase export
colors = [None] * (tile_count_x * tile_count_y)
i = 0

for grid_y in range(tile_count_y):
col1 = colors_left[grid_y]
col2 = colors_right[grid_y]

for grid_x in range(tile_count_x):
amount = remap(grid_x, 0, tile_count_x - 1, 0, 1)

if interpolate_shortest:
# interpolate in rgb
inter_col = lerp_color(col1, col2, amount)
else:
# interpolate in hsb
inter_hue = lerp(hue(col1), hue(col2), amount)
inter_saturation = lerp(saturation(col1), saturation(col2), amount)
inter_brightness = lerp(brightness(col1), brightness(col2), amount)
inter_col = hsva(inter_hue, inter_saturation, inter_brightness)
fill(inter_col)

pos_x = tile_width * grid_x
pos_y = tile_height * grid_y
rect(pos_x, pos_y, tile_width, tile_height)

# just for ase export
colors[i] = inter_col
i += 1


def shake_colors():
for i in range(len(colors_left)):
colors_left[i] = hsva(random(0, 60), random(0, 100) / 100, 1.0)
colors_right[i] = hsva(random(160, 190), 1.0, random(0, 100) / 100)


def mouse_released():
shake_colors()


def key_released():
global interpolate_shortest
if key == "c" or key == "C":
save_ase(colors, timestamp() + ".ase")
if key == "s" or key == "S":
save_frame(timestamp() + "_##.png")

if key == "1":
interpolate_shortest = True
if key == "2":
interpolate_shortest = False


def save_ase(colors, filename):
# write an ase file (adobe swatch exchange)
f = open(filename, "wb")
f.write(b"ASEF")
f.write(struct.pack(">HHI", 1, 0, len(colors)))
for c in colors:
name = c.to_hex()
block = struct.pack(">H", len(name) + 1) + name.encode("utf-16-be") + b"\x00\x00"
block = block + b"RGB " + struct.pack(">fff", red(c), green(c), blue(c))
block = block + struct.pack(">H", 0)
f.write(struct.pack(">HI", 1, len(block)))
f.write(block)
f.close()

# timestamp
def timestamp():
return datetime.now().strftime("%y%m%d_%H%M%S")


run()
Loading
Loading