X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?p=xscreensaver;a=blobdiff_plain;f=hacks%2Fceltic.c;h=5e8e361f77aebfc38e2e4c40da8187c3e772fea4;hp=deb3f3327df506fedc0c2edfe5718c4228f74b0b;hb=ccb7f4903325f92555a9722bba74b58346654ba0;hpb=0d6b320def9180cf907ceaed56b23a972a11b757 diff --git a/hacks/celtic.c b/hacks/celtic.c index deb3f332..5e8e361f 100644 --- a/hacks/celtic.c +++ b/hacks/celtic.c @@ -1,4 +1,4 @@ -/* celtic, Copyright (c) 2005 Max Froumentin +/* celtic, Copyright (c) 2006 Max Froumentin * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -7,6 +7,10 @@ * documentation. No representations are made about the suitability of this * software for any purpose. It is provided "as is" without express or * implied warranty. + * + * A celtic pattern programme inspired by "Les Entrelacs Celtes", by + * Christian Mercat, Dossier Pour La Science, no. 47, april/june 2005. + * See */ #include @@ -14,7 +18,7 @@ #include "screenhack.h" #include "erase.h" -#define SQRT3_2 .86602540378443864676 +#define SQRT_3 1.73205080756887729352 /*-----------------------------------------*/ Display *dpy; @@ -33,6 +37,7 @@ struct params { unsigned long cluster_size; /* only used if type is kennicott */ unsigned long delay; /* controls curve drawing speed (step delay * in microsecs) */ + unsigned long nsteps; /* only if triangle: number of subdivisions along the side */ unsigned long nb_orbits; /* only used if type is polar */ unsigned long nb_nodes_per_orbit; /* only used if type is polar */ @@ -384,52 +389,50 @@ static Graph make_grid_graph(int xmin, int ymin, int width, int height, int step } - -static Graph make_triangle_graph(int xmin, int ymin, int width, int height, int step) - /* make a simple grid graph */ +static Graph make_triangle_graph(int xmin, int ymin, int width, int height, int edge_size) { Graph g; - int row,col,x,y; - int size=widthx1=x1; ss->x2=x2; ss->x3=x3; ss->x4=x4; @@ -543,7 +546,7 @@ static void spline_to_s(Spline s, FILE *f) for (i=0;isegments->nb_elements;i++) { ss=s->segments->elements[i]; fprintf(f," - segment %d: (%g, %g),(%g, %g),(%g, %g),(%g, %g)\n", - i,ss->x1,ss->y1,ss->x2,ss->y2,ss->x3,ss->y3,ss->x4,ss->y4); + i,ss->x1,ss->y1,ss->x2,ss->y2,ss->x3,ss->y3,ss->x4,ss->y4); } } #endif @@ -633,8 +636,8 @@ static void pattern_edge_couple_set(Pattern p, Edge e, Direction d, int value) } static void pattern_draw_spline_direction(Pattern p, Spline s, - Node node, Edge edge1, Edge edge2, - Direction direction) + Node node, Edge edge1, Edge edge2, + Direction direction) { double x1=(edge1->node1->x+edge1->node2->x)/2.0; double y1=(edge1->node1->y+edge1->node2->y)/2.0; @@ -716,7 +719,7 @@ static void pattern_make_curves(Pattern p) /* add the spline segment to the spline */ pattern_draw_spline_direction(p,s,current_node, - current_edge,next_edge,current_direction); + current_edge,next_edge,current_direction); /* cross the edge */ current_edge = next_edge; @@ -738,9 +741,9 @@ static void pattern_animate(Pattern p, unsigned long delay) int i,segment,unused; int ticks = 0; double step=0.0001; /* TODO: set the step (or the delay) as a - * function of the spline length, so that - * drawing speed is constant - */ + * function of the spline length, so that + * drawing speed is constant + */ Spline s; XSetLineAttributes(dpy,gc,params.curve_width,LineSolid,CapRound,JoinRound); @@ -749,33 +752,33 @@ static void pattern_animate(Pattern p, unsigned long delay) for (t=0.0;t<1;t+=step) { for (i=0;isplines->nb_elements;i++) if ((s=p->splines->elements[i])) { /* skip if one-point spline */ - spline_value_at(s, &x, &y, fmod(t,1.0),&segment); - spline_value_at(s, &x2, &y2, fmod(t+step,1.0),&unused); - - /* look ahead for the shadow segment */ - t2=t+step; - if (t2<=1.0) { - spline_value_at(s, &x3, &y3, fmod(t2,1.0),&unused); - while (t2+step<1.0 && (x3-x2)*(x3-x2)+(y3-y2)*(y3-y2) < params.shadow_width*params.shadow_width) { - t2+=step; - spline_value_at(s, &x3, &y3, fmod(t2,1.0),&unused); - } - - spline_value_at(s, &x4, &y4, fmod(t2+step,1.0),&unused); - - /* draw shadow line */ - XDrawLine(dpy,window,shadow_gc, - (int)rint(x3),(int)rint(y3), - (int)rint(x4),(int)rint(y4)); - } - /* draw line segment */ - if (p->splines->nb_elements==1) - XSetForeground(dpy, gc, colors[segment%(ncolors-3)+2].pixel); - else - XSetForeground(dpy, gc, colors[s->color].pixel); - XDrawLine(dpy,window,gc, - (int)rint(x),(int)rint(y), - (int)rint(x2),(int)rint(y2)); + spline_value_at(s, &x, &y, fmod(t,1.0),&segment); + spline_value_at(s, &x2, &y2, fmod(t+step,1.0),&unused); + + /* look ahead for the shadow segment */ + t2=t+step; + if (t2<=1.0) { + spline_value_at(s, &x3, &y3, fmod(t2,1.0),&unused); + while (t2+step<1.0 && (x3-x2)*(x3-x2)+(y3-y2)*(y3-y2) < params.shadow_width*params.shadow_width) { + t2+=step; + spline_value_at(s, &x3, &y3, fmod(t2,1.0),&unused); + } + + spline_value_at(s, &x4, &y4, fmod(t2+step,1.0),&unused); + + /* draw shadow line */ + XDrawLine(dpy,window,shadow_gc, + (int)rint(x3),(int)rint(y3), + (int)rint(x4),(int)rint(y4)); + } + /* draw line segment */ + if (p->splines->nb_elements==1) + XSetForeground(dpy, gc, colors[segment%(p->ncolors-3)+2].pixel); + else + XSetForeground(dpy, gc, colors[s->color].pixel); + XDrawLine(dpy,window,gc, + (int)rint(x),(int)rint(y), + (int)rint(x2),(int)rint(y2)); } if (++ticks > 100) { @@ -796,8 +799,8 @@ static void pattern_animate(Pattern p, unsigned long delay) spline_value_at(s, &x2, &y2, fmod(t-offset,1.0),&unused); while ((x2-x)*(x2-x)+(y2-y)*(y2-y) < params.shadow_width*params.shadow_width) { - offset+=step; - spline_value_at(s, &x2, &y2, fmod(t-offset,1.0),&unused); + offset+=step; + spline_value_at(s, &x2, &y2, fmod(t-offset,1.0),&unused); } XDrawLine(dpy,window,gc, (int)rint(x),(int)rint(y), (int)rint(x2),(int)rint(y2)); @@ -861,6 +864,19 @@ static void params_to_s(FILE *f) } #endif +#if 0 +static void colormap_to_s(int ncolors, XColor *colors) +{ + int i; + printf("-- colormap (%d colors):\n",ncolors); + for (i=0;i 2) - make_smooth_colormap (dpy, xgwa.visual, xgwa.colormap, - colors, &ncolors, True, 0, True); - } - + ncolors = get_integer_resource ("ncolors", "Integer"); + if (ncolors > 2) + make_smooth_colormap (dpy, xgwa.visual, xgwa.colormap, + colors, &ncolors, True, 0, True); } }