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.
IndexDiscussionGeneral Discussion,  Status › Does anyone remember a "magnetic field"
Page Index Toggle Pages: 1
Does anyone remember a "magnetic field" (Read 1743 times)
Does anyone remember a "magnetic field"
Jun 20th, 2005, 10:36pm
 
Several months ago, I was followint a random chain of Processing links, and came upon a script that created a Black and White 2D array of line segments that sort of followed the mouse pointer and made something that looked liek a magnetic field.

Do any of you remember seeing that script, and where it is?
Re: Does anyone remember a "magnetic field&am
Reply #1 - Jun 21st, 2005, 3:39am
 
Do you mean something similar to this

click with the mouse

http://epicure.graffity.net/things/p5/level01/flux01/index.html
http://epicure.graffity.net/things/p5/level01/flux02/index.html

found on the exhibition links on the right
Re: Does anyone remember a "magnetic field&am
Reply #2 - Jun 21st, 2005, 2:24pm
 
Maybe you mean mine, I just found it in the sketchbook of Processing version 0054. It's not online, but here's the code. Warning: this is old code, so you'll need to tweak it a bit before it will run on Processing Beta. Another warning: the code is really weird, I wrote it when I just started programming.

Code:
avoidVector[][] vectors = new avoidVector[9][9];
float adjust = 0;

void setup() {
size(200, 200);
background(255);
ellipseMode(CENTER_DIAMETER);

for (int i = 0; i < 9; i++) {
for (int j = 0; j < 9; j++) {
vectors[i][j] = new avoidVector(i*20+20, j*20+20, 20);
}
}
}

void loop() {
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 9; j++) {
vectors[i][j].update();
}
}

if (keyPressed) {adjust = PI/2;}
if (mousePressed) {adjust = PI;}
if (!mousePressed && !keyPressed) {adjust = 0;}
}

void vector(int x, int y, float dir, float len) {
dir = dir - 2*dir - PI;
float x2 = sin(dir) * len + x;
float y2 = cos(dir) * len + y;
line(x, y, x2, y2);
}

class avoidVector {
int x, y;
float len;

avoidVector(int nx, int ny, float nlen) {
x = nx;
y = ny;
len = nlen;
}

void update() {
stroke(0);
vector(x, y, atan2(mouseY-y, mouseX-x)-PI/2+adjust, len);

fill(255, 0, 0);
noStroke();
ellipse(x, y, 4, 4);
}
}


Koenie
Re: Does anyone remember a "magnetic field&qu
Reply #3 - Jun 22nd, 2005, 5:03am
 
Those aren't quite it, although they are GREAT!

I think the one I saw was on a hexagonal grid. But I may be imagining it.

Anyway, these are great, and I can get going with them.

Thanks everyone.
Re: Does anyone remember a "magnetic field&am
Reply #4 - Jun 22nd, 2005, 10:40am
 
If you are looking for the implementation of a hexagonal grid.  This can help you.

Quite a while ago, I had worked on one.  Although the code is a bit messy (it was my first Processing applet!!) hope it helps you.  It may not be the best way, I used no references at all, just a piece of paper an trigonometry.

here's the applet: Hexagonando

cheers
ricard

edit: this applet has a small bug, where the particles move out of the screen.  but I'm planning to fix these things soon when I update it to P5 BETA, now the code only works with ALPHA.
Re: Does anyone remember a "magnetic field&qu
Reply #5 - Jun 23rd, 2005, 3:31pm
 
Ricard, that is a very cool sketch.

I noticed right away that the particles drift towards the lower-right corner, so I let it run for a LONG time until they were all packed right down in the corner.

That was a neat effect/bug. Sometimes tha mistakes are more interesting that the original idea!
Page Index Toggle Pages: 1