» codelab : http://codelab.fr/accueil » Forum : Hello world : http://codelab.fr/hello-world » hi : http://codelab.fr/1026 Ceci est la version imprimable d'un sujet du forum, pour retourner à la version complète : hi |
gametheory — 2009-02-05 14:26:31 |
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...... |
22_80 — 2009-02-05 18:54:41 |
Hi, |
emoc — 2009-02-05 23:57:54 |
Hi Gametheory, |
gametheory — 2009-02-06 00:39:17 |
thanks a million i will work it out from there |
gametheory — 2009-02-10 19:28:16 |
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: |
emoc — 2009-02-10 22:40:33 |
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); } } |
gametheory — 2009-02-10 22:54:33 |
thanks a lot but i need to see dpoints plotting from one point to another as in slow motion......maybe i should use threading??? |
22_80 — 2009-02-11 13:03:51 |
Try |
gametheory — 2009-02-17 13:03:40 |
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 |
emoc — 2009-02-19 10:52:18 |
Hi Gametheory,
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. 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]); } } } } } |
gametheory — 2009-02-19 10:54:48 |
many thanks....i will look in it |
gametheory — 2009-02-23 11:02:15 |
just tried it out.....many thanks....!!! i appreciate |
gametheory — 2009-03-01 10:01:47 |
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?? |
gametheory — 2009-03-01 17:01:47 |
if i use vertex for a 3d structure must i use three parameters one of which would be negative?? |
emoc — 2009-03-02 22:12:26 |
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.
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/ |
gametheory — 2009-03-03 13:50:09 |
many thanks.... |
gametheory — 2009-03-04 07:58:19 |
i am in the process of writing code in order to design a teapot....as yet after consulting some other codes and modifying it i only managed to come up with the result of a kind of a cylinder. My problem is actually how to manage to draw the curve which shoots off from the base in such a way that it meets with a line at the top and then at the end of this line or surface i design the same curved side back again. Sphere does not help here because the sides of a teapot must bulge out.... |