I want to make this code more advanced. I would like to have more rows of eyes both the horisontal and vertical way. How do i do that? Should i use the “for (int …)” ??
And then i want the pupils in the eye to be rectangles instead ? Heeeelpp
Eye [] eyes; //erklær en array af variable af datatypen Eye
void setup() {
size(800, 600);
background(28,28,28);
eyes = new Eye[5];
for (int i = 0; i < 5; i++)
eyes [i] = new Eye(i*(width/5) +100, 300);
}
void draw() {
for (int i = 0; i < 5; i++) {
eyes[i].draw();
}
}
class Eye {
float x, y;
float D = 60;
float d = D/2;
float atangens;
color EyeColor = color(247, 50, 50);
Eye (float tempX, float tempY) {
x = tempX;
y = tempY;
}
void draw() {
pushMatrix();
translate(x, y);
stroke(0);
strokeWeight(2);
fill(255);
ellipse(0, 0, D, D);
fill(EyeColor);
noStroke();
if ((mouseX-x) < 0) atangens = atan((mouseY-y)/(mouseX-x)) - PI;
if ((mouseX-x) >= 0) atangens = atan((mouseY-y)/(mouseX-x));
pushMatrix();
rotate (atangens);
ellipse(d/2, 0, d, d);
popMatrix();
popMatrix();
}
}
Actually i have another question… If it’s not too much to ask… I want to use the “z” and “x” keys to make til diameter on the white circle bigger or smaller, but i’m having problems with the “key pressed” function… Can u maybe help me on this one aswell?
Clock [] clock;
void setup() {
size(690, 700);
background(4,23,176);
clock = new Clock[10*10];
int k=0;
for (int i = 0; i < 10; i++) {
for (int iy = 0; iy < 10; iy++) {
clock [k] = new Clock(i*(width/10.5) +50, 50 + iy * 65 );
k++;
}
}
//eyes = new Eye[5*2];
//for (int i = 0; i < 5; i++)
// eyes [i] = new Eye(i*(width/5) +100, 300);
}
void draw() {
for (int i = 0; i < clock.length; i++) {
clock[i].draw();
}
}
class Clock {
float x, y;
float D = 60;
float d = D/2;
float atangens;
color ClockColor = color(4,23,176);
Clock (float tempX, float tempY) {
x = tempX;
y = tempY;
}
void draw() {
pushMatrix();
translate(x,y);
stroke(0);
noStroke();
fill(247, 247, 247);
ellipse(0, 0, D, D);
fill(ClockColor);
noStroke();
if ((mouseX-x) < 0) atangens = atan((mouseY-y)/(mouseX-x)) - PI;
if ((mouseX-x) >= 0) atangens = atan((mouseY-y)/(mouseX-x));
pushMatrix();
rotate (atangens);
rectMode(CENTER);
rect(d/2-5, 0, 29, 2);
//ellipse(d/2, 0, d, d);
popMatrix();
popMatrix();
}
}
I want them all to be affected. and i moved the float out before setup, (made a copy), and it doesn-t say fail anymore, but nothing happens when i press the z and x