X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fjulia.c;h=d7066b0896e94d2dad8b8d8156423482292330ab;hb=4ade52359b6eba3621566dac79793a33aa4c915f;hp=6a7323def51dc9687448082d5dec6f87a180cfaf;hpb=49f5b54f312fe4ac2e9bc47581a72451bd0e8439;p=xscreensaver diff --git a/hacks/julia.c b/hacks/julia.c index 6a7323de..d7066b08 100644 --- a/hacks/julia.c +++ b/hacks/julia.c @@ -20,6 +20,7 @@ static const char sccsid[] = "@(#)julia.c 4.03 97/04/10 xlockmore"; * other special, indirect and consequential damages. * * Revision History: + * 10-Jun-06: j.grahl@ucl.ac.uk: tweaked functions for parameter of Julia set * 28-May-97: jwz@jwz.org: added interactive frobbing with the mouse. * 10-May-97: jwz@jwz.org: turned into a standalone program. * 02-Dec-95: snagged boilerplate from hop.c @@ -37,38 +38,23 @@ static const char sccsid[] = "@(#)julia.c 4.03 97/04/10 xlockmore"; */ #ifdef STANDALONE -# define DEFAULTS "*count: 1000 \n" \ - "*cycles: 20 \n" \ - "*delay: 10000 \n" \ - "*ncolors: 200 \n" +# define DEFAULTS "*count: 1000 \n" \ + "*cycles: 20 \n" \ + "*delay: 10000 \n" \ + "*ncolors: 200 \n" \ + "*fpsSolid: true \n" \ + "*ignoreRotation: True \n" \ + # define UNIFORM_COLORS -# define reshape_julia 0 -# define julia_handle_event 0 # include "xlockmore.h" /* in xscreensaver distribution */ #else /* !STANDALONE */ # include "xlock.h" /* in xlockmore distribution */ #endif /* !STANDALONE */ -static Bool track_p; - #define DEF_MOUSE "False" -static XrmOptionDescRec opts[] = -{ - {"-mouse", ".julia.mouse", XrmoptionNoArg, "on"}, - {"+mouse", ".julia.mouse", XrmoptionNoArg, "off"}, -}; -static argtype vars[] = -{ - {&track_p, "mouse", "Mouse", DEF_MOUSE, t_Bool}, -}; -static OptionStruct desc[] = -{ - {"-/+mouse", "turn on/off mouse tracking"}, -}; - -ENTRYPOINT ModeSpecOpt julia_opts = { 2, opts, 1, vars, desc }; +ENTRYPOINT ModeSpecOpt julia_opts = { 0, }; #define numpoints ((0x2<depth)-1) @@ -93,6 +79,8 @@ typedef struct { #endif GC stippledGC; XPoint **pointBuffer; /* pointer for XDrawPoints */ + Bool button_down_p; + int mouse_x, mouse_y; } juliastruct; @@ -137,28 +125,14 @@ apply(juliastruct * jp, register double xr, register double xi, int d) static void incr(ModeInfo * mi, juliastruct * jp) { - int cx, cy; - - if (track_p) - { - Window r, c; - int rx, ry; - unsigned int m; - XQueryPointer(MI_DISPLAY(mi), MI_WINDOW(mi), - &r, &c, &rx, &ry, &cx, &cy, &m); - if (cx <= 0 || cy <= 0 || - cx >= MI_WIN_WIDTH(mi) || cy >= MI_WIN_HEIGHT(mi)) - goto NOTRACK; - } - - if (track_p) + if (jp->button_down_p) { - jp->cr = ((double) (cx + 2 - jp->centerx)) * 2 / jp->centerx; - jp->ci = ((double) (cy + 2 - jp->centery)) * 2 / jp->centery; + jp->cr = ((double) (jp->mouse_x + 2 - jp->centerx)) * 2 / jp->centerx; + jp->ci = ((double) (jp->mouse_y + 2 - jp->centery)) * 2 / jp->centery; } else { - NOTRACK: +#if 0 jp->cr = 1.5 * (sin(M_PI * (jp->inc / 300.0)) * sin(jp->inc * M_PI / 200.0)); jp->ci = 1.5 * (cos(M_PI * (jp->inc / 300.0)) * @@ -166,6 +140,15 @@ incr(ModeInfo * mi, juliastruct * jp) jp->cr += 0.5 * cos(M_PI * jp->inc / 400.0); jp->ci += 0.5 * sin(M_PI * jp->inc / 400.0); +#else + jp->cr = 1.5 * (sin(M_PI * (jp->inc / 290.0)) * + sin(jp->inc * M_PI / 210.0)); + jp->ci = 1.5 * (cos(M_PI * (jp->inc / 310.0)) * + cos(jp->inc * M_PI / 190.0)); + + jp->cr += 0.5 * cos(M_PI * jp->inc / 395.0); + jp->ci += 0.5 * sin(M_PI * jp->inc / 410.0); +#endif } } @@ -194,7 +177,7 @@ init_julia(ModeInfo * mi) #ifndef HAVE_COCOA - if (track_p && !jp->cursor) + if (jp->button_down_p && !jp->cursor && !jp->cursor) { Pixmap bit; XColor black; @@ -217,7 +200,7 @@ init_julia(ModeInfo * mi) if (jp->pixmap == None) { GC fg_gc = None, bg_gc = None; - jp->circsize = (MIN(jp->centerx, jp->centery) / 96) * 2 + 1; + jp->circsize = MAX(8, (MIN(jp->centerx, jp->centery) / 96) * 2 + 1); jp->pixmap = XCreatePixmap(display, window, jp->circsize, jp->circsize, 1); gcv.foreground = 1; fg_gc = XCreateGC(display, jp->pixmap, GCForeground, &gcv); @@ -271,6 +254,44 @@ init_julia(ModeInfo * mi) } +static void +reshape_julia (ModeInfo *mi, int w, int h) +{ + init_julia (mi); +} + + +ENTRYPOINT Bool +julia_handle_event (ModeInfo *mi, XEvent *event) +{ + juliastruct *jp = &julias[MI_SCREEN(mi)]; + + if (event->xany.type == ButtonPress && + event->xbutton.button == Button1) + { + jp->button_down_p = True; + jp->mouse_x = event->xbutton.x; + jp->mouse_y = event->xbutton.y; + return True; + } + else if (event->xany.type == ButtonRelease && + event->xbutton.button == Button1) + { + jp->button_down_p = False; + return True; + } + else if (event->xany.type == MotionNotify && jp->button_down_p) + { + jp->mouse_x = event->xmotion.x; + jp->mouse_y = event->xmotion.y; + return True; + } + + return False; +} + + + /* hack: moved here by jwz. */ #define ERASE_IMAGE(d,w,g,x,y,xl,yl,xs,ys) \ if (ylcenterx * jp->cr / 2) + jp->centerx - 2; new_circle.y = (int) (jp->centery * jp->ci / 2) + jp->centery - 2; XSetForeground(display, gc, MI_WIN_BLACK_PIXEL(mi)); - ERASE_IMAGE(display, window, gc, new_circle.x, new_circle.y, - old_circle.x, old_circle.y, jp->circsize, jp->circsize); + XFillArc(display, window, gc, + old_circle.x-jp->circsize/2-2, + old_circle.y-jp->circsize/2-2, + jp->circsize+4, jp->circsize+4, + 0, 360*64); /* draw a circle at the c-parameter so you can see it's effect on the structure of the julia set */ XSetForeground(display, jp->stippledGC, MI_WIN_WHITE_PIXEL(mi)); @@ -315,8 +339,12 @@ draw_julia (ModeInfo * mi) XSetStipple(display, jp->stippledGC, jp->pixmap); XSetFillStyle(display, jp->stippledGC, FillOpaqueStippled); #endif /* HAVE_COCOA */ - XFillRectangle(display, window, jp->stippledGC, new_circle.x, new_circle.y, - jp->circsize, jp->circsize); + XDrawArc(display, window, jp->stippledGC, + new_circle.x-jp->circsize/2, + new_circle.y-jp->circsize/2, + jp->circsize, jp->circsize, + 0, 360*64); + if (jp->erase == 1) { XDrawPoints(display, window, gc, jp->pointBuffer[jp->buffer], numpoints, CoordModeOrigin);