Last active
August 29, 2015 14:11
-
-
Save azbones/5733906c6b2b3374ae9e to your computer and use it in GitHub Desktop.
This is the main code for my 2015 new year's card
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
//This code is written in Processing which is a programming language | |
//for visual arts. You can download it for free at https://processing.org/ | |
// | |
//Collin's attempt at modern art- exploding cherry blossoms...BOOM! | |
PImage img; | |
String[] names; | |
void setup(){ | |
size(1280, 800); | |
smooth(); | |
noLoop(); | |
names = loadStrings("names.txt");//load names to make each card unique | |
img = loadImage("cherry.jpg");//load cherry blossom for color pallette | |
} | |
void draw(){ | |
//make each person a unique piece of art using their name to seed randomness | |
for(String name:names){ | |
background(255,255,255); | |
int hash_val = hash_name(name);//use your name to create a unique random seed w/ hash func | |
randomSeed(hash_val);//your name is now creating the art | |
float iters = random(5,80); | |
float xoff = 0.0; | |
float yoff = 0.0; | |
for(int a=0; a < iters; a++){ | |
xoff = xoff + .03; | |
yoff = yoff + .03; | |
float line_color = random(0, 3); | |
float alpha = random(100,255); | |
color pix_1 = img.get(int(random(img.width)),int(random(img.height))); | |
color pix_2 = img.get(int(random(img.width)),int(random(img.height))); | |
stroke(pix_1, alpha); | |
noFill(); | |
float stroke_w = random(60); | |
strokeWeight(stroke_w); | |
float y_start = random(height); | |
float x_start = random(width); | |
float y_finish = random(height); | |
float x_finish = random(width); | |
float x1 = noise(xoff) * width;//perlin noise keeps it mellow | |
float y1 = noise(yoff) * height; | |
float x2 = noise(xoff) * width; | |
float y2 = noise(yoff) * height; | |
float blur_value = random(.6); | |
filter (BLUR, blur_value); | |
bezier(x_start, y_start, x1, y1, x2, y2, x_finish, y_finish); | |
if ((a%4)==0){ | |
int new_x = int(random(0,1280)); | |
int new_y = int(random(0,800)); | |
int in_x = 200; | |
int in_y = 200; | |
translate(new_x, new_y); | |
rotate(noise(xoff) * TWO_PI); | |
flower(pix_2, in_x, in_y);//call cherry blossom func to draw flowers | |
resetMatrix(); | |
} | |
} | |
saveFrame("/"+name+"/"+name+".png"); | |
} | |
exit();// I wonder if anyone will actually read this part... | |
} | |
void flower(int clr, float in_x, float in_y){ | |
//draw cherry blossom using MATH | |
strokeWeight(random(1, 8)); | |
int alpha_val = int(random(10,100)); | |
stroke(clr, alpha_val); | |
int ped = 5; | |
int r = int(random(5,50)); | |
float p = TWO_PI/ped; | |
float p2 = PI/ped; | |
float a = r * cos(p2); | |
float b = r * sin(p2); | |
float r2 = sqrt(sq(r - a) + sq(b)); | |
float an = asin( b/r2); | |
for(int i =0; i < ped; i++ ) { | |
float an2 = i * p; | |
float x = cos(an2) * r; | |
float y = sin(an2) * r; | |
arc(x, y, r2 * 2, r2 * 2, an2 + an + PI, an2 + TWO_PI + PI - an); | |
} | |
} | |
int hash_name(String name){ | |
//take name from list and hash to int to seed random function | |
int s_len = name.length(); | |
println(s_len); | |
IntList name_num; | |
name_num = new IntList(); | |
for (int i=0; i<s_len; i++){ | |
name_num.append(name.charAt(i)); | |
println(name.charAt(i)); | |
} | |
int hash = 1; | |
for (int i:name_num){ | |
hash = hash+(31*i);//it's not SHA-256... | |
} | |
return hash; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment