I am having some trouble with my program. I am looking to create a shape and have it move back and forth. I added velocity to my location but it's not working.
Also, when I println(sideFront[i]); I only get 3 values instead of 4. Not sure why.
Any help would be appreciated,
Thanks
Face faces;
void setup() {
size(500,400);
smooth();
faces = new Face(10,10,25);
}
void draw() {
background(200);
faces.display();
faces.check();
}
class Face {
PVector location;
PVector velocity;
float faceScale;
float[] frontx;
float[] fronty;
PVector[] sideFront;
Face(float _x, float _y, float _faceScale) {
location = new PVector(_x,_y);
velocity = new PVector(2,0);
faceScale = _faceScale;
frontx = new float[] {location.x,location.x+faceScale,location.x+faceScale,location.x};
fronty = new float[] {location.y,location.y,location.y+faceScale,location.y+faceScale};
sideFront = new PVector[frontx.length];
for (int i = 0; i<frontx.length;i++) {
sideFront[i] = new PVector(frontx[i], fronty[i]);
}
}
void display() {
beginShape();
for(int i = 0; i < frontx.length; i++) {
vertex(sideFront[i].x, sideFront[i].y);
// println(sideFront[i]);
//println(location.x);
}
endShape(CLOSE);
location.add(velocity);
//println(location);
}
void check() {
if ((location.x > location.x+faceScale) || (location.x < location.x-faceScale)) {
The code below does what I want, however when I remove "noLoop()" I would like the starting position to be in the same spot. With noLoop() removed, it jumps all over the place. What can be done?
I did some searches but couldn't find a solution to this.
I am loading a csv file and trying to create a separate array for each of the lines. When I try this, I get an error that says I cannot convert string[] to float[].
My original code before creating a csv file was structured like this:
I then load the csv with the goal of having each line as it's own array, like the first block of code.
String[] lines = loadStrings("inx-test-one.csv");
for (int i = 0; i < lines.length; i++) {
float[][] arrayTest = { float(lines[i]) };
}
That's where I am stuck. Wouldn't this be the same as float[][] yearsAll = { yearOne, yearTwo}; ? When I println(lines[i]); I get the separate arrays like the individual ones up top.
How do I replicate the code in the first block using loadString and a loop?
I am doing the Time series exercise in Ben Fry's Visualizing Data book.
My question has to do with mapping months instead of years.
Here is the line of code I am having trouble modifying:
float x = map(years[row], yearMin, yearMax, plotX1, plotX2);
----
An excerpt from my data:
Date Price
0131
1.0038
0201
1.0007
--
0131 is the end of January and 0201 is the beginning of February.
--
The map function is calculating the lowest number and the highest number, plotting them to the x range. However this creates a large space at the end of each month since the number jumps higher.
What would I need to do to solve for the missing space?
Right now I have a random grid of colors chosen from an array. I would like mousePressed to check the color of the rectangle clicked, determine which it is, and then select a different color based on the result.
I am not sure which direction to move in going forward.
I am having trouble connecting lines from one dot to another in this circle. I'm pretty sure I need to loop through an array, but I am not 100% sure how to structure this.