I am having this issue I can't seem to figure out. I'll try and explain;
I am using PeasyCam for camera operation, and I have all these Nodes in a network. Now, I want each node to have a thicker stroke, as the camera position moves closer to it.
// get current camera position as a PVector
float[] position = cam.getPosition();
PVector pos = new PVector (position[0], position[1], position[2]);
// get distance between current camera position and the current node
Now, the problem with this code is that it does the opposite. I'm sure it's very simple to 'invert' or 'reverse' the numbers so that the strokeWeight() value gets higher as the camera closes in on the point/node.
I'm having a hard time figuring this one out - I've the sample code as seen below, in order to draw a connection between two points. Thing is, I want the connection not to be a single line, but a random number of lines. Also, I want each line to have a random number of kinks (vertices) between the start point and the end point. Then, each kink (not including the start point and the end point), should have a slight random offset from what would be a straight line, resulting in a kind of 'blurry' connection, when applied to a bunch of start points and end points.
Now, I got it to work with a straight up example, connecting the left side of a box with the right side. Next step, which is where I'm stuck, is to get it to work in a larger network of points.
How do I get the interpolations/kinks to offset perpendicular to the connection?
Any help is appreciated,
Thanks in advance,
/Claus
import peasy.*;
PeasyCam cam;
float maxOff = 25.0; // maximum offset (deviation from the straight line)
ArrayList connections;
void setup() {
size(1200, 600, P3D);
cam = new PeasyCam(this, 500);
//cam.setYawRotationMode(); // maybe comment this out?
cam.setMinimumDistance(-1000);
cam.setMaximumDistance(1000);
generate();
}
void draw() {
background(0);
for (int i = connections.size()-1; i >= 0; i--) {
Connect c = (Connect) connections.get(i);
c.render();
}
noFill();
strokeWeight(.5);
stroke(255);
box(1000);
}
void generate() {
connections = new ArrayList(); // create an empty ArrayList
int num = int(random(1, 10)); // get random value for number of connections
for (int i = 0; i < num; i++) {
PVector start = new PVector(-500, 0, 0); // start-vector in left side of box
PVector end = new PVector(500, 0, 0); // end-vector in right side of the box
connections.add(new Connect(start, end, maxOff));
}
}
void mousePressed() {
generate();
}
class Connect {
// do random number of connections between start PVector and end PVector
// for each connection, do random interpolation calculation (number of 'kinks' on each curve)
// offset each 'kink' sligthly from what would be a straight line between start and end
I've been trying to wrap my head around this annoying, yet probably simple solution: I have build this mouse attractor code, that affects a grid of points. Now, I want to draw either lines or quads between the points, so that I have a rectangular grid instead of just points.
Any suggestions to how I can do that? I've been trying to figure it out with PVector and 2D arrays, but I just can't get it to work.
I've only just begun trying to figure out the PVector class - so this probably has a real simple solution to it ... I can't get the red point to move to mouse location, by using the PVector class. Any suggestions as to what I am doing wrong?
Thanks a bunch in advance!
/Claus
PVector loc, dir;
float rad = 75;
void setup() {
size(500, 500);
background(255);
noCursor();
// create random point
loc = new PVector(random(width), random(height));
dir = new PVector();
}
void draw() {
background(255);
// random point draw
stroke(255, 0, 0);
strokeWeight(10);
point(loc.x, loc.y);
// mouse
noFill();
stroke(0);
strokeWeight(10);
point(mouseX, mouseY);
if (mousePressed == true) {
// i create new PVector for mouse location
PVector mouse = new PVector(mouseX, mouseY);
// i create a PVector between mouse location and loc
dir.sub(dir, loc);
// i add dir to loc - but the point doesn't move???
I've been trying to do a sketch where I use PVector and noise() to move n agents around on the screen ... but I can't seem to get it to work properly.
Could anyone help me to see what's wrong with the code? It seems like the x and y increase/decrease are the same, which creates a 45 degree line where the ellipse's are drawn instead of using the entire canvas ... what am I doing wrong here?
Thanks in advance!
/Claus
// script written by Claus Rytter Bruun de Neergaard, October 2011
// GLOBAL VARIABLES ///////////////////////////////
int n = 100; // number of agents
float increase = 0.01; // maximum agent increase each frame
I am trying to write a code that draws an ellipse wherever I click on the screen. This is not a problem. Then I want to add some new functionality to that code.
1. Loop through all pts - if distance is less than x, then connect with line.
2. Loop through all pts - draw ellipse at pts based on closest pt (meaning if new pt inserted rescale already drawn ellipses).
Now, I believe that the issue with function 2 is that I don't know how to make it not measure on itself (making shortest distance = 0.0) ... any ideas? I think it might be the structure that isn't really working.
Thanks in advance,
/Claus
float[] mPosX = new float[0]; // declare array for x pos float[] mPosY = new float[0]; // declare array for y pos float[] shortest = new float[0]; // declare array for shortest distance
if (n > 0) { // making sure the loop will run only when second pt has been clicked for (int i = 0; i < n; i++) { float[] distance = new float[n]; // loop through each pt for (int j = 0; j < n-1; j++) { // for each pt, loop through all other pts distance[j] = dist(mPosX[i], mPosY[i], mPosX[j], mPosY[j]); if (distance[j] < 100) { line(mPosX[i], mPosY[i], mPosX[j], mPosY[j]); } } distance = sort(distance); shortest = append(shortest, distance[0]); ellipse(mPosX[i], mPosY[i], shortest[i], shortest[i]); } } }
void mousePressed() {
// write coordinates to array mPosX = append(mPosX, mouseX); mPosY = append(mPosY, mouseY); //println("x" + n + ": " + mPosX[n]); //println("y" + n + ": " + mPosY[n]);