Toxiclibs: convert Vec2D to ArrayList
in
Contributed Library Questions
•
2 years ago
Hey!
I found this little Toxiclibs example but i can't get it to run.
the problem is, that it wants to convert a List<Vec2D> to an ArrayList and this is not possible.
i hope somebody can help me out here.
import toxi.color.*;
import toxi.geom.*;
import toxi.math.*;
import toxi.util.datatypes.*;
import processing.pdf.*;
float XRAD = 300;
float YRAD = 500;
int RES = 6;
int NUM_POINTS=6;
void setup() {
size(1024, 768);
smooth();
noLoop();
}
void draw() {
ColorTheme t = new ColorTheme("test");
t.addRange("fresh ivory", 0.5);
t.addRange("intense goldenrod", 0.25);
t.addRange("intense red", 0.15);
t.addRange("fresh teal", 0.05);
t.addRange("bright yellow", 0.05);
t.addRange(ColorRange.BRIGHT, TColor.newRandom(), random(0.02, 0.05));
ColorList list = t.getColors(160);
long timeStamp=System.currentTimeMillis()/1000;
beginRecord(PDF, "colors-"+timeStamp+".pdf");
background(list.getLightest().toARGB());
noStroke();
drawSpline(list);
endRecord();
}
void keyPressed() {
redraw();
}
void drawSpline(ColorList list) {
int numCols = list.size();
Vec2D[] points=new Vec2D[NUM_POINTS];
points[0]=new Vec2D(-XRAD,random(0.2,0.9)*height);
for(int i=1; i < points.length-1; i++) {
points[i]=new Vec2D(random(-1,1)*50+(float)i/points.length*width,random(0.25,0.75)*height);
}
points[points.length-1]=new Vec2D(width+XRAD,random(height));
ArrayList vertices = new Spline2D(points).computeVertices(width/RES);
for(Iterator i=vertices.iterator(); i.hasNext(); ) {
Vec2D v=(Vec2D)i.next();
fill(list.get(MathUtils.random(numCols)).toARGB());
ellipse(v.x,v.y,noise(v.y*0.01)*XRAD,noise(v.x*0.01)*YRAD);
}
}
I found this little Toxiclibs example but i can't get it to run.
the problem is, that it wants to convert a List<Vec2D> to an ArrayList and this is not possible.
i hope somebody can help me out here.
import toxi.color.*;
import toxi.geom.*;
import toxi.math.*;
import toxi.util.datatypes.*;
import processing.pdf.*;
float XRAD = 300;
float YRAD = 500;
int RES = 6;
int NUM_POINTS=6;
void setup() {
size(1024, 768);
smooth();
noLoop();
}
void draw() {
ColorTheme t = new ColorTheme("test");
t.addRange("fresh ivory", 0.5);
t.addRange("intense goldenrod", 0.25);
t.addRange("intense red", 0.15);
t.addRange("fresh teal", 0.05);
t.addRange("bright yellow", 0.05);
t.addRange(ColorRange.BRIGHT, TColor.newRandom(), random(0.02, 0.05));
ColorList list = t.getColors(160);
long timeStamp=System.currentTimeMillis()/1000;
beginRecord(PDF, "colors-"+timeStamp+".pdf");
background(list.getLightest().toARGB());
noStroke();
drawSpline(list);
endRecord();
}
void keyPressed() {
redraw();
}
void drawSpline(ColorList list) {
int numCols = list.size();
Vec2D[] points=new Vec2D[NUM_POINTS];
points[0]=new Vec2D(-XRAD,random(0.2,0.9)*height);
for(int i=1; i < points.length-1; i++) {
points[i]=new Vec2D(random(-1,1)*50+(float)i/points.length*width,random(0.25,0.75)*height);
}
points[points.length-1]=new Vec2D(width+XRAD,random(height));
ArrayList vertices = new Spline2D(points).computeVertices(width/RES);
for(Iterator i=vertices.iterator(); i.hasNext(); ) {
Vec2D v=(Vec2D)i.next();
fill(list.get(MathUtils.random(numCols)).toARGB());
ellipse(v.x,v.y,noise(v.y*0.01)*XRAD,noise(v.x*0.01)*YRAD);
}
}
1