19BCD7246 Cse2006 Lab3 L1
19BCD7246 Cse2006 Lab3 L1
19BCD7246 Cse2006 Lab3 L1
To write a C program to perform 2D basic transformations such as translation, rotation, scaling, shearing
and reflection.
OUTPUT:
Reflection:
Rotation:
2. Shearing
OUTPUT:
3. Scaling
function setup(){
createCanvas(500,500);
background(255);
smooth();
}
function draw(){
var Sx = 0.85;
var Sy = 1.15;
var x1 = 150;
var y1 = 200;
var x2 = 450;
var y2 = 200;
var x3 = 450;
var y3 = 400;
noFill();
stroke(0);
strokeWeight(3);
triangle(x1,y1,x2,y2,x3,y3);
triangle(x1*Sx,y1*Sy,x2*Sx,y2*Sy,x3*Sx,y3*Sy);
}
OUTPUT:
4. Reflection
W.r.t x = y line
Code
function setup(){
createCanvas(500,500);
background(255);
smooth();
}
function draw(){
var x1 = 250;
var y1 = 250;
var x2 = 400;
var y2 = 250;
var x3 = 400;
var y3 = 350;
noFill();
stroke(0);
strokeWeight(3);
triangle(x1,y1,x2,y2,x3,y3);
triangle(y1,x1,y2,x2,y3,x3);
}
OUTPUT:
5. Rotation (Angle = 270 degrees)
function setup() {
createCanvas(500, 500);
fill(0);
}
function draw() {
background(255);
translate(225, 225);
drawGrid();
noFill();
stroke(0);
strokeWeight(2);
triangle(0,50,250,50,250,200);
rotate(radians(270));
translate(-250,-100);
triangle(0,50,200,50,200,200);
}
function drawGrid() {
stroke(200);
fill(120);
for (var x=-width; x < width; x+=50) {
line(x, -height, x, height);
text(x, x+1, 10);
}
for (var y=-height; y < height; y+=50) {
line(-width, y, width, y);
text(y, 1, y+10);
}
}
OUTPUT: