graniph2
YaBB Newbies
Offline
Posts: 2
QUESTION ABOUT OUTPUT OF PDF !
Sep 22nd , 2009, 11:58pm
I want to out put pdf of line stroke. but it doesn`t work. please help me !! THIS IS CODE OF 1/2 import processing.opengl.*; import processing.pdf.*; FixedPointBuffer buf; // array of points to follow the mouse Tracker [] tracks; // how many points? int ntracks; // mouse-down flag boolean isDrawing = false; // HSB current color to rotate float myhue=0.0, mysat, mybri; // rate of hue rotation when in rotate mode float myhueinc=0.25; // RGB current color to plot with int myred, mygrn, myblu; // alpha value to plot with float myalf; // how fine to subdivide each frame float timeslice = 0.2; // flag the applet has mouse focus boolean bGotMouse = false; // flag if we are in "rainbow" mode boolean bHueRotate = true; boolean dosave=false; int num; float pt[]; int style[]; void setup() { size(480,480,OPENGL); colorMode(HSB); buf = new FixedPointBuffer(width,height); ntracks = 100; tracks = new Tracker[ntracks]; float ctrx = (float)(width/2); float ctry = (float)(height/2); for (int i=0; i<ntracks; i++) tracks[i] = new Tracker(ctrx,ctry); config(2); } void config(int mode) { float basespeed=0.0, basefriction=0.0; // slightly desaturating and brightening allows white highlights to accumulate mysat = 224.0; mybri = 160.0; switch(mode) { case 1 : // blue, tight response myhue = 256.0*2.0/3.0; myred = 16 << buf.shift; mygrn = 64 << buf.shift; myblu = 255 << buf.shift; basespeed = 0.03; basefriction = 0.04; break; case 2 : // red, medium response myhue = 0.0; myred = 255 << buf.shift; mygrn = 16 << buf.shift; myblu = 64 << buf.shift; basespeed = 0.02; basefriction = 0.03; myhue = 0.0; break; case 3 : // green, loose response myhue = 256.0/3.0; myred = 64 << buf.shift; mygrn = 255 << buf.shift; myblu = 16 << buf.shift; basespeed = 0.011; basefriction = 0.02; myhue = 0.333 * 256.0; break; case 4 : // gray, very tight myhue = 0.0; bHueRotate = false; // force to false when start gray mode myred = 64 << buf.shift; mygrn = 64 << buf.shift; myblu = 64 << buf.shift; basespeed = 0.05; basefriction = 0.07; break; } myalf = 0.5 * timeslice; for (int i=0; i<ntracks; i++) { tracks[i].speed = basespeed - (float)(i) * 0.0001; tracks[i].friction = basefriction - (float)(i) * 0.0001; } } void rotatehue() { myhue += myhueinc; if (myhue >= 256.0) myhue -= 256.0; color c = color(myhue,mysat,mybri); myred = ((int)red(c)) << buf.shift; mygrn = ((int)green(c)) << buf.shift; myblu = ((int)blue(c)) << buf.shift; } void draw() { // don't move towards mouse until we're sure applet has been focused // (otherwise they all bunch up at 0,0 before first mouse down - yuck) if (bGotMouse) { if (bHueRotate) rotatehue(); float targetx = (float)(mouseX); float targety = (float)(mouseY); float elapsed = 0.0; while (elapsed < 1.0) { for (int i=0; i<ntracks; i++) { tracks[i].movetoward( targetx, targety, timeslice ); if (isDrawing) buf.add(tracks[i].x, tracks[i].y, myred, mygrn, myblu, myalf); } elapsed += timeslice; } buf.render(); if(dosave) { // set up PGraphicsPDF for use with beginRaw() PGraphicsPDF pdf=(PGraphicsPDF)beginRaw(PDF, "pdf_complex_out.pdf"); // set default Illustrator stroke styles and paint background rect. pdf.strokeJoin(MITER); pdf.strokeCap(SQUARE); pdf.fill(0); pdf.noStroke(); pdf.rect(0,0, width,height); if(dosave) { endRaw(); dosave=false; } } } } void mousePressed() { bGotMouse = true; if (mouseButton == LEFT) { // redundant? yes. but keeps right button from interfering (as with mousePressed) isDrawing = true; } else if (mouseButton == RIGHT) { buf.background(0,0,0); } } void mouseReleased() { if (mouseButton == LEFT) { isDrawing = false; } } void keyPressed() { if (key=='1') config(1); else if (key=='2') config(2); else if (key=='3') config(3); else if (key=='4') config(4); else if (key=='h') bHueRotate = !bHueRotate; else if (key=='s') dosave=true; } // an 8.16 fixed point rgb buffer with sub-pixel sampling // (the extra precision is used to reduce rounding errors during accumulation) class FixedPointBuffer { static final int shift = 16; // number of .fixed bits static final int fixone = 1<<shift; // the "scale" of fixed point numbers static final int maxrgb = (256<<shift)-1; // max allowed for rgb values int wid, hei, area; int [] redbuf; int [] grnbuf; int [] blubuf; FixedPointBuffer(int w, int h) { wid = w; hei = h; area = wid * hei; redbuf = new int[area]; grnbuf = new int[area]; blubuf = new int[area]; loadPixels(); } void background(int r, int g, int b) { for (int idx=0; idx<area; idx++) { redbuf[idx] = r; grnbuf[idx] = g; blubuf[idx] = b; } }