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.
Page Index Toggle Pages: 1
OUROBOROS (Read 179 times)
OUROBOROS
Dec 29th, 2008, 3:15am
 
Hello,
I have recently started learning processing, and have ran into to some trouble. I have created this thread both for this problem, but also for the future problems I am likely to run into as the project goes along. I own the books: Creative Coding and Computational Art, by Ira Greenberg and A Programming Handbook for Visual Designers and Artists, by
Casey Reas and Ben Fry, and any help along with reference to chapters in these books would be highly appreciated. So, Basically what I want to end up with is this:

Code:
void setup() {
size(800, 800); //størelse
smooth();
noStroke();
fill(100, 100); //fyld

}

void draw() {
background(255);
frameRate(30);

float x = width * 0.25;
float y = width * 0.5;
float z = width * 0.75;

float r1 = radians(0);
float r2 = radians(0);

float tyk = 2.5; //tykkelse
float ryk = tyk * 2;

for (float i = 0; i < 270; i = i+ryk) {
arc(x, z, y, y, radians(i), radians(i) + radians(tyk)); //lower left
}

for (float k = 90; k < 360; k = k+ryk) {
arc(x, x, y, y, radians(k), radians(k) + radians(tyk)); //upper left
}

for (float j = 180; j < 450; j = j+ryk) {
arc(z, x, y, y, radians(j), radians(j) + radians(tyk)); //upper right
}

for (float k = -90; k < 180; k = k+ryk) {
arc(z, z, y, y, radians(k), radians(k) + radians(tyk)); //lower right
}

for (float l = -90 + tyk; l < 90; l = l+ryk) {
arc(x, y, y, y, radians(l), radians(l) + radians(tyk)); //middle left
}

for (float m = 0 + tyk; m < 180; m = m+ryk) {
arc(y, x, y, y, radians(m), radians(m) + radians(tyk)); //upper middle
}

for (float n = 90 + tyk; n < 270; n = n+ryk) {
arc(z, y, y, y, radians(n), radians(n) + radians(tyk)); //middle right
}

for (float o = 180 + tyk; o < 360; o = o+ryk) {
arc(y, z, y, y, radians(o), radians(o) + radians(tyk)); //lower middle
}
}

Only I would like it all to be animated. So i wrote this:

Code:
int[] start = {0, 90, 180};
int[] slut = {45, 135, 225};

int numArcs = 3;
Arc[] arcs = new Arc[numArcs];

void setup() {
size(400,400);
smooth();
noStroke();
for(int i = 0; i < numArcs; i++) {
arcs[i] = new Arc(width/2, height/2, width, radians(start[i]), radians(slut[i]));
}}

void draw() {
background(0);
fill(255);
for(int i = 0; i < start.length; i++) {
arcs[i].move();
arcs[i].display();
}}

class Arc {
float x, y;
float diameter;
float start;
float slut;

Arc(float xpos, float ypos, float dia, float st, float sl) {
x = xpos;
y = ypos;
diameter = dia;
start = st;
slut = sl;
}

void move() {
slut += radians(1);
if (slut > radians(45)) {
start += radians(1);
}
if (slut > radians(270)) {
slut = radians(270);
}
if (start > radians(270)) {
start = 0;
slut = 0;
}
}

void display() {
arc(x, y, diameter, diameter, start, slut);
}
}


The problem to me, seems that i need a "temporary arc" for when they reach radians(270), or possibly a different approach is needed?
Re: OUROBOROS
Reply #1 - Dec 29th, 2008, 12:53pm
 
A simple approach is to drop limit checking: angles beyond 360° are still valid:
Code:
  void move() {  
slut += radians(1);
start += radians(1);
}

A lateral approach is to left the angles unchanged and to use pushMatrix, rotate and popMatrix to do the rotations.
Page Index Toggle Pages: 1