float x = 0.0; float y = 0.0; float x2 = 0.0; float y2 = 0.0; float rot_deg_inc = radians(4); float cur_angle = 90; float i = 1; float change_ratio = 5; float Radius= 0.0; float max_lim = 20; float frame_rate = 30; boolean skip_radius_calc_once = false; //bezier variables float y_bez1 = 0.0; float x_bez1 = 0.0; float y_bez2 = 0.0; float x_bez2 = 0.0; float y_mid1 = 0.0; float x_mid1 = 0.0; float y_mid2 = 0.0; float x_mid2 = 0.0; //SET YOUR color variables //background, 0 is black 255 is white float back_grey = 30; //alpha is by percentage so this is faded 30% float alpha_fill = 80; //amount of time spent transitioning between colors float slow_colors_by = 15; //how big does the line need to be to change color? 2 is low 5 is high float color_change_ratio = 3; //initial fill colors when this thing starts float red_fill = 100; float blue_fill= 0; float green_fill= 100; //low and high limits to keep colors in a particular range float red_high_lim = 255; float red_low_lim = 100; float blue_high_lim = 255; float blue_low_lim = 0; float green_high_lim = 255; float green_low_lim = 100; //different ratios allow for the colors to scale idependently //if the ratios are equal you will stay in a tonal range... float red_ratio = .5; float blue_ratio = .5; float green_ratio = .5; //change this to vary the S curve // 0 = a flat line // 0-30 slight cure // 30-45 moderate curve // 60 more dramatic // 75 sharp lip // 90 very dramatic (default) // 120 curve moves towards center // 150 doubles over itself // 180 point of rotation is at bez_ratio float bez_angle = radians(90); //change this to make the curve more or less dramatic //3 begins to form conelike shapes //2- is an avergae S curve like a pinwheel (default?) //1.5 produces a dramatic curve //1 is a very dramatic curve // under 1 increases the size of the curve float bez_ratio = 2; //shapes at 2,90 are very intersting... //vary this number between .25 and 3 to decrease the curve of the S float bez_amp = 1; void setup() { size(600,600); framerate(frame_rate); background(back_grey,back_grey,back_grey); smooth(); x = mouseX; y = mouseY; x2 = mouseX - max_lim; y2 = mouseY - max_lim; } void loop() { //if the mouse is pressed then we can begin the drawing if (mousePressed == true) { Start_Draw(); } else { //reset the radius of the drawing Radius = max_lim; skip_radius_calc_once = true; } } void Start_Draw() { //this allows the center to change modestly in the direction of the user. x = mouseX; y = mouseY; //calculate the length of the radius if the mouse has not been lifted if (skip_radius_calc_once == false) { Radius = sqrt(sq(x2-x) + sq(y2-y)); } else { skip_radius_calc_once = false; } //calculate the current angle based on the x axis of the circle origin cur_angle = atan2(y2-(y), x2-(x)); //add a little to the angle to rotate the line cur_angle += rot_deg_inc; //acount for if we have gone around the circle (keep rotating in current direction) if(cur_angle > 2*PI) { cur_angle -= 2*PI; } //limit the size of the Radius if(Radius > max_lim) { Radius -= Radius/frame_rate; } //recalculate the x2 y2 points x2 = Radius * cos(cur_angle) + x; y2 = Radius * sin(cur_angle) + y; Get_Bez_Points(); Calculate_Colors(); //draw the line each one is based on... // stroke(100,0,0); // line(x,y,x2,y2); //finally lets draw the curve bezier(x,y,x_bez1,y_bez1,x_bez2,y_bez2,x2,y2); } void Calculate_Colors() { //increase the intensity of a color depending on println("Radius = "+ Radius); //if the raidus is small make it lighter if (Radius < max_lim*color_change_ratio) { if (red_fill >= red_low_lim){ red_fill -= (frame_rate/red_ratio)/slow_colors_by; } if (blue_fill >= blue_low_lim) { blue_fill -= (frame_rate/blue_ratio)/slow_colors_by; println(blue_fill); } if (green_fill >= green_low_lim) { green_fill -= (frame_rate/green_ratio)/slow_colors_by; } } //if the radius is big increase intensity else { if (red_fill <= red_high_lim) { red_fill += (frame_rate/red_ratio)/slow_colors_by; } if(blue_fill <= blue_high_lim) { blue_fill += (frame_rate/blue_ratio)/slow_colors_by; } if (green_fill <= green_high_lim) { green_fill += (frame_rate/green_ratio)/slow_colors_by; } } stroke(red_fill,green_fill,blue_fill,alpha_fill); } void Get_Bez_Points() { //caclulate two new points between the endpoints from which //to base your besier curve points y_mid1 = (y+y2)/bez_ratio; x_mid1 = (x+x2)/bez_ratio; //point two optional for experimentation y_mid2 = (y+y2)/(bez_ratio/2); x_mid2 = (x+x2)/(bez_ratio/2); //calculate a degree point away from the current line from origin y_bez1 = (Radius/bez_amp) * sin(cur_angle-bez_angle) + y; x_bez1 = (Radius/bez_amp) * cos(cur_angle-bez_angle) + x; //calculate a degree point away from a point farther down y_bez2 = (Radius/bez_amp) * sin(cur_angle+bez_angle) + y_mid1; x_bez2 = (Radius/bez_amp) * cos(cur_angle+bez_angle) + x_mid1; }