FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   Newbie: animated sketched line drawing
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: Newbie: animated sketched line drawing  (Read 331 times)
pass


Newbie: animated sketched line drawing
« on: Dec 16th, 2004, 6:03pm »

Hello World,  
 
I've been quickly hacking away at by Pablo Tamarits http://ruglen.free.fr smoothtracer (excellent), and have got the beginings of a nice random sketch generator, it looks as though the line is drawing itself in a nice smooth manner, which is what i am after, however it is also the cause of my problems... The differance between the two is that the line he generates is in motion, whereas the line i want to generate is static.
 
It generates the smooth line by drawing several lines and then averaging them out to a curve and then drawing a final line in a differant colour on the curve. My troubles start with those first lines, as they also draw over the line i'm after.  
 
I'm not to sure what i'm doing to the poor mans code, but here's what i've done so far which is just play around with some values.
 
 // hacked from Pablo Tamarits http://ruglen.free.fr  
  
 boolean mouseDown = false;  
 boolean mouseDownFirst = true;  
  
 boolean modeRandom = true;  
  
 float randMax = 100;  
  
 int nbPoints = 100;  
 float[][] points = new float[nbPoints][100]; //  [][0]==x; [][1]==y;  
 int colorInit = 0;  
 float colorPas;  
  
 int posX = 0;  
 int posY = 0;  
 int longX = 300;  
 int longY = 600;  
  
 void setup() {  
   size(300,600);  
   background(127);  
   for (int i=0; i < nbPoints; i++) {  
     points[i][0] = (longX/2)+posX;  
     points[i][1] = (longY/2)+posY;  
   }  
   colorPas = float(-510);  
   println(colorPas);  
   mouseX = (longX/2)+posX;  
   mouseY = (longY/2)+posY;  
   framerate(45);
 }  
  
 void loop() {  
   drawLineStrip();  
   moveLineStrip();  
 
  drawCadre();  
  smooth();  
 }  
  
 void drawLineStrip() {  
   float colorAct = colorInit;  
   for (int i=nbPoints-1; i > 0; i--) {  
     stroke(colorAct);  
     line(points[i][0], points[i][1], points[i-1][0], points[i-1][1]);  
     colorAct -= colorPas+450;  
     colorAct = constrain(colorAct,0,255);  
   }  
 }  
  
 void moveLineStrip() {  
   if (mouseIsClicked()) {  
     modeRandom = !modeRandom;  
   }  
  
   if (modeRandom) {  
     float randValX = random(randMax);  
     float randValY = random(randMax);  
     randValX = randMax/2 - randValX;  
     randValY = randMax/2 - randValY;  
      
     points[0][0] = constrain(randValX+points[0][0], posX, posX+longX);  
     points[0][1] = constrain(randValY+points[0][1], posY, posY+longY);  
  
   } else {  
     points[0][0] = constrain(mouseX, posX, posX+longX);  
     points[0][1] = constrain(mouseY, posY, posY+longY);  
   }  
  
   for (int i=nbPoints-1; i > 0; i--) {  
     points[i][0] = (points[i][0] +  points[i-1][0]) / 2;  
     points[i][0] = constrain(points[i][0], posX, posX+longX);  
    points[i][1] = (points[i][1] +  points[i-1][1]) / 2;  
     points[i][1] = constrain(points[i][1], posY, posY+longY);  
   }  
 }  
  
 void drawCadre() {  
   noFill();  
   stroke(5);  
   rect(posX,posY,longX-1,longY-1);  
 }  
  
 boolean mouseIsClicked() {  
   boolean _mouseIsClicked = false;  
   if (mouseDown && mouseDownFirst) {  
     _mouseIsClicked = true;  
     mouseDownFirst = false;  
   } else if (!mouseDown) {  
     mouseDownFirst = true;  
   }  
   return _mouseIsClicked;  
 }  
  
 void mousePressed() {  
   mouseDown = true;  
 }  
  
 void mouseReleased() {  
   mouseDown = false;  
 }  
 
My question is, is there any simple way to get those lines to plot there values without being drawn, or even make them transparent, so they don't overwrite the black line?
 
i've put up the code at  
http://homepage.mac.com/domslinn/index.html
 
Many thanks to your enlighted soul
« Last Edit: Dec 17th, 2004, 3:57pm by pass »  
Pages: 1 

« Previous topic | Next topic »