Hello,

I'm having a problem I don't quite understand (that's why I'm here! otherwise I would have solved it
)

I stumbled across Memo Atkins' example of simple harmonic motion, and I wanted to see if I could write that up.

I thought I had it, but I'm having problems when I increment the speed for each node. I've tried different ways of incrementing the speed of each node, but it always seems to result in groups of nodes operating at near the same speed, while other sections behave near properly.

I'm new to processing and to programming in general, so I figure this is something simple about math or procedure that I'm missing. Anyway, I'd much appreciate any help.

Thanks!

- //space between nodes
- int nodeSpace = 10;
- int nodeLoc = 0;
- int totalNodes = 81;
- //attempt to make each node have it's own speed
- //float speedInc = 1;
- //float speedUpdate = 20;
- float speed = 1;
- //node attribs
- float[]nodeSize = new float [totalNodes];
- float[]xLoc = new float [totalNodes];
- float[]yLoc = new float [totalNodes];
- float[]ySpeed = new float [totalNodes];
- void setup(){
- size(800, 200);
- //setup nodes
- for (int i = 0; i < totalNodes; i++){
- nodeSize[i] = 10;
- xLoc[i] = (nodeLoc);
- yLoc[i] = (height/2);
- if (i == 0){
- ySpeed[i] = speed;
- }else{
- ySpeed[i] = (ySpeed[i-1]+.1);
- }
- // ySpeed[i] = (speedUpdate);
- nodeLoc += nodeSpace;
- // speed update attempt
- // speedUpdate -= speedInc;
- }
- frameRate(12);
- }
- void draw(){
- background(255);
- strokeWeight(.5);
- line(0, height/2, width, height/2);
- // noStroke();
- smooth();
- fill(0, 0, 0, 100);
- for (int i = 0; i < totalNodes; i ++){
- if(i == 0){
- yLoc[i] += ySpeed[i];
- }else{
- yLoc[i] += ySpeed[i];
- }
- if(yLoc[i] >= (height-nodeSize[i]/2) || yLoc[i] <= nodeSize[i]/2){
- ySpeed[i] *= -1;
- }
- ellipse(xLoc[i], yLoc[i], nodeSize[i], nodeSize[i]);
- }
- }

1