xxxxxxxxxx
/*
UPC-CITM
Nom: Jose L. Redondo Tello
Data: 13.03.22
The concept of my genotype was the eye color.
Initially I wanted to create a dynamic eye inheritance project, wich would feature not onlly the color of the eyes, but
different distinctive features such as eyelashes and eye shape, but i had to scale it down due to time constraints and
the unexpected difficulty of drawing a believable eye, note that due to the artistic nature of these assigments, the option of
following a tutorial was discarted.
*/
let irisIterations = 100; //Times that we repeat 360 degree line drawing
let angle = 360;
let internalRadius = 120; //internal radius of the pupil
let externalRadius = 400; //external radius of the eyeball
let irisInRadius = 60; //internal radius of the iris
let irisOutRadius = 180; //external radius of the iris
let startPosVariation = 10;
//Iris class
class Iris
{
//Constructor, takes RGB value, and color variation attribute
constructor(irisR, irisG, irisB, colorVariation)
{
this.irisR = irisR;
this.irisG = irisG;
this.irisB = irisB;
this.colorVariation = colorVariation;
}
//Draw the iris
Display()
{
//Draw the white eyeball
fill(220);
ellipse(width * 0.5, height * 0.5, 600, externalRadius);
//draw pupil
fill(20, 20, 20, 255);
ellipse(width * 0.5, height * 0.5, internalRadius, internalRadius);
//Set position to the center and set no fill flag
push();
noFill();
translate(width * 0.5, height * 0.5);
this.DrawIris();
this.DrawIrisExternalGradient();
pop();
}
DrawIris()
{
let angleOffset = 0.1; //Added angle to create a sphere with the lines
for (let i = 0; i < irisIterations; ++i)
{
for (let j = 0; j < angle; j++)
{
let colorOffset = random(-this.colorVariation, this.colorVariation); //Get color offset
let pos1OffsetX = random(-startPosVariation, startPosVariation); //Get pos offset
let pos1OffsetY = random(-startPosVariation, startPosVariation);
push();
stroke(color(this.irisR + colorOffset, this.irisG + colorOffset, this.irisB + colorOffset, 150)); //Set color of the line, taking into account the variation
//calculate line points
let x1 = cos(j + angleOffset) * irisInRadius + pos1OffsetX;
let y1 = sin(j + angleOffset) * irisInRadius + pos1OffsetY;
let x2 = cos(j + angleOffset) * irisOutRadius;
let y2 = sin(j + angleOffset) * irisOutRadius;
//draw line
line(x1, y1, x2, y2);
pop();
}
angleOffset += 0.1; //Add offset
}
}
//Used to obscure the exterior part of the iris
DrawIrisExternalGradient()
{
let externalGradient = 100; //Set alfa gradient
for (let i = 0; i < externalGradient; ++i)
{
push();
stroke(color(20, 20, 20, externalGradient - i * 2)); //Reduce alfa
ellipse(0.0, 0.0, irisOutRadius * 2 - i, irisOutRadius * 2 - i); //Reduce ellipse size
pop();
}
}
}
function setup()
{
createCanvas(windowWidth, windowHeight); //Create canvas
background(40); //Set background color
angleMode(DEGREES); //Set angle mode
colorMode(RGB); //Set color mode
//Create Iris
let i1 = new Iris(181, 101, 29, 30);
let i2 = new Iris(120, 80, 40, 20);
let i3 = new Iris(171, 199, 219, 50);
let i4 = new Iris(50, 130, 70, 50);
let i5 = new Iris(160, 100, 49, 30);
push();
translate(400, 0); //move all objects to the right
push();
scale(0.6); //Scale down the eye
translate(-400, -150); //Set eye position
i1.Display(); //Draw iris
pop();
push();
scale(0.6);
translate(400, -150);
i2.Display();
pop();
push();
scale(0.6);
translate(0, 600);
i3.Display();
pop();
push();
scale(0.6);
translate(-800, 600);
i4.Display();
pop();
push();
scale(0.6);
translate(800, 600);
i5.Display();
pop();
}