We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › creating a vector image from a group of points
Page Index Toggle Pages: 1
creating a vector image from a group of points (Read 579 times)
creating a vector image from a group of points
May 30th, 2009, 7:12am
 
hi list, i have a group of points stored in an array. How can i create  a vector image from those points? is that posible?


many thanks


P.
Re: creating a vector image from a group of points
Reply #1 - May 30th, 2009, 8:22am
 
Yes, it is possible.

Example:
Code:
int[] coordinates =
{
10, 10,
50, 100,
120, 170,
200, 60
};

void setup()
{
size(250, 250);
stroke(#0088DD);
background(255);

// Note I start at 2
int len = coordinates.length;
for (int i = 2; i < len - 1; i += 2)
{
line(coordinates[i - 2], coordinates[i - 1], coordinates[i], coordinates[i + 1]);
}
// If you want to close the shape
line(coordinates[len - 2], coordinates[len - 1], coordinates[0], coordinates[1]);
}

You can also look at Vertex at the reference page.
Re: creating a vector image from a group of points
Reply #2 - May 30th, 2009, 1:08pm
 
hi philho , i know i can do that, but is that the same as vector images? i thought a line was not a vector image as for example in flash, is it the same?
Re: creating a vector image from a group of points
Reply #3 - May 31st, 2009, 12:32am
 
It depends on your final goal.

If by "create  a vector image" you mean "create a vector image file", it needs some extra steps, indeed. But then, you must indicate which format you need, the most popular 2D ones being SVG and PDF (the latter being trivial to do in Processing).

If that's "to get the same rendering as a vector image, keeping the quality through scaling and rotating", as opposed to bitmap images, line() fills the bill. Now it might take a few extra steps to replay the image after moving, scaling and rotating.

A vector image is an abstract set of coordinates and information (fill/stroke colors, kind of shape, etc.) which is rendered on screen by some software (PDF reader, Flash viewer, SVG viewer, etc.).
So somehow Processing is such kind of viewer, with a vector language which is a derivative of Java...
Page Index Toggle Pages: 1