Created
May 12, 2012 09:35
-
-
Save zeffii/2665527 to your computer and use it in GitHub Desktop.
rewrite
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
import re | |
from urllib.request import urlopen | |
#usage | |
# - set to cycles first | |
# - unselect any objects. | |
# - run. | |
remote_location = "http://dribbble.com/shots/550651-Dune-Runner" | |
def regex_this(html): | |
pattern = '<a href="\/colors\/(.*)"' | |
matches = re.findall(pattern, html) | |
return [i[:6] for i in matches] | |
def get_html(remote_location): | |
html_raw = urlopen(remote_location) | |
html = html_raw.readall().decode() | |
return ''.join(html) | |
def color_hex_to_BSDF_input(group): | |
rgb = [group[i:i+2] for i in range(0, 6, 2)] | |
r, g, b = [(int(col, 16)/255) for col in rgb] | |
return r, g, b, 1.0 | |
def get_colors_from_html(remote_location): | |
html = get_html(remote_location) | |
return regex_this(html) | |
def make_object(pos, col): | |
bpy.ops.mesh.primitive_cube_add() | |
new_obj = bpy.context.active_object | |
new_obj.location = (float(pos*2), 0.0, 0.0) | |
new_obj.data.materials.append(col) | |
def create_objects_and_materials(color_group, col_name='swatch'): | |
for idx, color in enumerate(color_group): | |
col = pymat.new(col_name + str(idx)) | |
col.use_nodes = True | |
rgb_values = color_hex_to_BSDF_input(color) | |
Diffuse_BSDF = col.node_tree.nodes['Diffuse BSDF'] | |
Diffuse_BSDF.inputs[0].default_value = rgb_values | |
make_object(idx, col) | |
pymat = bpy.data.materials | |
color_group = get_colors_from_html(remote_location) | |
create_objects_and_materials(color_group) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if dribbble produces alpha swatches, this script will crumble in its present state