Annonce

>>> Bienvenue sur codelab! >>> Première visite ? >>> quelques mots sur codelab //// une carte des membres//// (apéros) codelab


#1 2009-02-05 14:26:31 hi

gametheory
membre
Date d'inscription: 2009-02-05
Messages: 12

hi



i'm completely new to the programming world and i'm very frustrated at my inability to write code in java and processing......yet i do not lose hill though the uphill battle makes me bananas.....whatever....i need to write a processing program whereby i use mouse control to draw a point on the drawing window when the mouse button is pressed.....so far so good i did manage that bit....however i am then bugged down by the idea of extending this program to place a succession of points each connected to the next by a straight line segment so that when a key on the keyboard is pressed the sketch is terminated by drawing a line from the last point to the first. i though of using arrays and a for loop but as yet havent come to solving this and writing the code.......and then i need to store the coordinate pairs in a file......

everybody tells me to practise....and rightly so..but is there anyone who can help me at least indicating useful tutotial sites abt processing and java please...

many thnks

regards

gametheory

Hors ligne

 

#2 2009-02-05 18:54:41 Re : hi

22_80
membre
Lieu: Paris
Date d'inscription: 2008-02-29
Messages: 205

Re: hi



Hi,

Take a look at http://codelab.fr/39

+
+

Hors ligne

 

#3 2009-02-05 23:57:54 Re : hi

emoc
@#@*$
Lieu: Quimper
Date d'inscription: 2008-01-28
Messages: 1576
Site web

Re: hi



Hi Gametheory,

You need a two-dimensional array to keep point coordinates, then for each mouse click add mouseX and mouseY of the click (using mousePressed) as a new point coordinates. In the draw() part of your sketch, redraw this array each frame with point() and line().

I could give you code but you want to learn by yourself, don't you ? smile

If you get stuck or lose patience, just ask...

Hors ligne

 

#4 2009-02-06 00:39:17 Re : hi

gametheory
membre
Date d'inscription: 2009-02-05
Messages: 12

Re: hi



thanks a million i will work it out from there

i appreciate
regards

Hors ligne

 

#5 2009-02-10 19:28:16 Re : hi

gametheory
membre
Date d'inscription: 2009-02-05
Messages: 12

Re: hi



further to my problem whereby i had to plot points on d screen and join them by a straight line segment which stops once a key is pressed that is d drawing ends this is what i managed to come up with:

boolean drawVertex = false;

void setup(){
 
  size(450,450);
 
  background(25,88,126);
  strokeWeight(30);
 
int [] x = {50, 67, 89, 124, 345};

int [] y = { 98, 56,45,125, 56};

beginShape();

for(int i = 0; i < x.length; i++){
 
  point (x[i], y[i]);
}

beginShape();

for(int i = 0; i < x.length; i++){
 
  vertex (x[i], y[i]);
}


  void keyPressed() {
 
  if ((key == 'A')){
    endShape(CLOSE) = true;
}

}
}

whereby im missing the stage whereby the vertex actaully passes from one point to another..........among the errors is dat d compiler points out that void keyPressed is an unexpected token.....

thnks

ps i just tried this too...............
boolean drawVertex = false;

void setup(){
 
  size(500,500);
 
  strokeWeight (18);
 
}

void draw(){
 
  background(45,200,88);
 
  if (drawVertex == true) {
    beginShape ();
    point (25,450);
    point (45,156);
    endShape();
  }
}

void keyPressed() {
 
  if ((key == 'A')) {
   
    drawVertex = true;
  }
}

void keyReleased(){
 
  drawVertex = false;
 
}
but i need to see the line being plotted.........maybe frameRate() ??

thnks

Dernière modification par gametheory (2009-02-10 19:40:45)

Hors ligne

 

#6 2009-02-10 22:40:33 Re : hi

emoc
@#@*$
Lieu: Quimper
Date d'inscription: 2008-01-28
Messages: 1576
Site web

Re: hi



Your first attempt would work with some minor changes : add draw(), and put keyPressed() out from setup() and draw() as shown below, pressing caps A closes the shape.

Code (p5) :

boolean drawVertex = false;
int [] x = {50, 67, 89, 124, 345};
int [] y = { 98, 56,45,125, 56};

void setup(){
  size(450,450);
  background(25,88,126);
  strokeWeight(30);
}

void draw() {
  beginShape();
  for(int i = 0; i < x.length; i++){
    point (x[i], y[i]);
    vertex (x[i], y[i]);
  }
}

void keyPressed() {
  if ((key == 'A')){
    endShape(CLOSE);
  }
}

Hors ligne

 

#7 2009-02-10 22:54:33 Re : hi

gametheory
membre
Date d'inscription: 2009-02-05
Messages: 12

Re: hi



thanks a lot but i need to see dpoints plotting from one point to another as in slow motion......maybe i should use threading???

thanks again

Hors ligne

 

#8 2009-02-11 13:03:51 Re : hi

22_80
membre
Lieu: Paris
Date d'inscription: 2008-02-29
Messages: 205

Re: hi



Try
frameRate(1); in your setup() method : http://www.processing.org/reference/frameRate_.html

+
+

Hors ligne

 

#9 2009-02-17 13:03:40 Re : hi

gametheory
membre
Date d'inscription: 2009-02-05
Messages: 12

Re: hi



hi itsme again guys.....i have manged to write a processing program whereby i load a text file called positions and plot the corresponding points. However in order to draw these points and calling the draw method, the program doesn't respond....this is my code so far....any help gretaly appreciated

thanks



PrintWriter output;

void setup()
{
   
   size(1024,768);
   
   strokeWeight(7);
   
   output = createWriter("positions.txt");
}
   
   void draw()
   {
     
     if (mousePressed)
     {
       
       output.println(mouseX + "\t" + mouseY + "\n");
       point(20,120);
       point(5,180);
       point(16,200);
       point(100,60);
       point(120,40);
       point(70,20);
       
     }
     
     if (keyPressed)
     {output.flush();
     output.close();
     }
   }

that is as regards the plotting of points.....if i need to use draw these points should i use a for loop in the draw method?

plus how will draw identify these points? shouldi store them in an array 2 dimensional array first?

thnks

Hors ligne

 

#10 2009-02-19 10:52:18 Re : hi

emoc
@#@*$
Lieu: Quimper
Date d'inscription: 2008-01-28
Messages: 1576
Site web

Re: hi



Hi Gametheory,

citation :

if i need to use draw these points should i use a for loop in the draw method?
plus how will draw identify these points? shouldi store them in an array 2 dimensional array first?

Yes, read the file contents into an array, then from the draw method, call a function to draw your array from point 0 to point X, point X should be 1 at the first step, 2 at next step, etc. You could use millis() to define this step.

Here are some bits of code that could be useful :

Code (p5) :

int maxpoints = 1000;
int nb = 0;
float points[][] = new float[maxpoints][2];

void setup() {
  size(400, 400); 
}

void draw() {
  background(255,255,255);  
  stroke(0);
  frameRate(25);
  drawPoints();
}

void mousePressed() {
  nb ++;
  points[nb][0] = mouseX;
  points[nb][1] = mouseY;
}

void drawPoints() {
  if (nb > 0) {
    for (int i = 0; i <= nb; i++) {
      point(points[i][0], points[i][1]);
    }
    if (nb > 1) {
      for (int i = 2; i <= nb; i++) {
        line(points[i-1][0], points[i-1][1], points[i][0], points[i][1]);
        if (i == nb) {
            line(points[1][0], points[1][1], points[i][0], points[i][1]);
        }
      }
    }
  }
}

Hors ligne

 

#11 2009-02-19 10:54:48 Re : hi

gametheory
membre
Date d'inscription: 2009-02-05
Messages: 12

Re: hi



many thanks....i will look in it

regards

Hors ligne

 

#12 2009-02-23 11:02:15 Re : hi

gametheory
membre
Date d'inscription: 2009-02-05
Messages: 12

Re: hi



just tried it out.....many thanks....!!! i appreciate

regards

Hors ligne

 

#13 2009-03-01 10:01:47 Re : hi

gametheory
membre
Date d'inscription: 2009-02-05
Messages: 12

Re: hi



its me again.....i must design a 3d teapot....and i would like to design curves....would it be useful to use curveVertex or curveBezier??

thnks

Hors ligne

 

#14 2009-03-01 17:01:47 Re : hi

gametheory
membre
Date d'inscription: 2009-02-05
Messages: 12

Re: hi



if i use vertex for a 3d structure must i use three parameters one of which would be negative??

thnks

Hors ligne

 

#15 2009-03-02 22:12:26 Re : hi

emoc
@#@*$
Lieu: Quimper
Date d'inscription: 2008-01-28
Messages: 1576
Site web

Re: hi



gametheory a écrit:

its me again.....i must design a 3d teapot....and i would like to design curves....would it be useful to use curveVertex or curveBezier??

bezierVertex will give you more control over the curves drawn, with control points, but it's harder to use. curveVertex only need points coordinates and the curves will be drawn passing by these points.

gametheory a écrit:

if i use vertex for a 3d structure must i use three parameters one of which would be negative??

You'll need points within a 3d space, with 3 coordinates, one for each axis : x, y ,z . Those coordinates could be positive or negative. You should take a look at processing 3D examples : http://processing.org/learning/3d/

Hors ligne

 

fil rss de cette discussion : rss

Pied de page des forums

Powered by FluxBB

codelab, graphisme & code : emoc / 2008-2024