0% found this document useful (0 votes)
2 views10 pages

Computer Graphics JS Programs

Uploaded by

swamiyash0808
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views10 pages

Computer Graphics JS Programs

Uploaded by

swamiyash0808
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Program to Draw Line

[Link](50, 50);
[Link](200, 50);
[Link]();
Program to Draw Circle

[Link]();
[Link](150, 100, 50, 0, 2 * [Link]);
[Link]();
Program to Draw Rectangle

[Link](100, 100, 150, 80); // (x, y, width, height)


Program to Implement Flood Fill

Use getImageData() and putImageData() with a recursive or stack-based approach.


Full implementation can be provided if needed.
Program to Draw an Ellipse

[Link]();
[Link](200, 150, 80, 40, 0, 0, 2 * [Link]);
[Link]();
Program to Implement 2-D Mirror Reflection

[Link]();
[Link](-1, 1); // Reflect over Y-axis
[Link](-[Link], 0);
[Link](100, 100, 100, 50);
[Link]();
Program to Draw a Smile

// Face
[Link](200, 200, 100, 0, 2 * [Link]);

// Eyes
[Link](160, 170, 10, 0, 2 * [Link]);
[Link](240, 170, 10, 0, 2 * [Link]);

// Smile
[Link](200, 210, 50, 0, [Link]);
[Link]();
Program to Implement 2-D Shearing

function shear(x, y, shx, shy) {


return [x + shx * y, y + shy * x];
}
Program to Draw Circle using Bresenhams Algorithm

function drawCircle(xc, yc, r) {


let x = 0, y = r;
let d = 3 - 2 * r;
plotCirclePoints(xc, yc, x, y);
while (y >= x) {
x++;
if (d > 0) {
y--;
d += 4 * (x - y) + 10;
} else {
d += 4 * x + 6;
}
plotCirclePoints(xc, yc, x, y);
}
}
Program to Implement 2-D Translation

function translatePoint(x, y, tx, ty) {


return [x + tx, y + ty];
}

You might also like