We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi Im trying to produce a series of coloured lines that flow smoothly. I currently do this in Coreldraw by drawing a line through the points and then using CorelDraw's internal smooth function - which leaves some parts of the curve (normally an obtuse angle) not quite right but this is fixed by then removing every other point that the curve must pass thru which results in near perfect smoothness at the cost of accuracy.
Given that it is the smoothnes of the curve that is most important here, can somebody help with advice on what is the right way to go about this in p5.js?
Answers
Do you mean something like this?
Note that curveVertex() needs to be used between beginShape() and endShape().
Thanks allonestring, I think I've got it. The use of createVector is a little different from what I expected - am I right in thinking that it actually represents a point in two or 3d space rather than a direction to that point? Im wanting to colour individual parts of the line in different colours so; Is it possible to leave the line in the same place as its drawn but have it broken up into separate objects? (So that it looks like a single continuous line but is in fact made up of many objects, each object being defined by 2 points?)
Here I've used the vector just as a convenient way of holding two numbers which I'll use as (x, y) co-ordinates. I could've used arrays for each of x and y. The Vector class provides methods that will look familiar if you use vectors in maths.
You might have to draw a picture to show what you mean, as I don't think that you mean a dashed line.
this is just a play on it, nothing to do with the original post....
Sorry Chrisir - I get an error with your code that points me to p5.js FAQ - Why can't I assign variables using p5 functions and variables before setup()?
Thanks for the reply allonestring, https://flic.kr/s/aHskCow13R shows a coloured line of the type. Im drawing fancy graphs and want to plot a line thru a set of points but have that line in a different colour between each point (see http://nicksoph.wix.com/spotline for images, intention is to make similar as an online app. )
My code is Java p5
Like this?
Love your lines!
@Chrisr. I didnt know there was such a thing as java P5. Thanks, I will take another look to see if I can understand what it does but I'm struggling with learning javascript and suspect I wont be adding java to my studies.
Thanks allonestring - that does exactly what's required. I was thinking about how to break a line up not drawing lots of small ones and your code shows very well how to proceed. Thanks again.