You are on page 1of 5

Assignment-10

Name: Aditya Ram

Reg no: 20BCE7102

Question 1:
1. Write a program to draw a Bezier curve with the following curve points: (340, 80), (40, 40), (360,
360), (60, 320). Display all the tangents through the above points on the curve.

Code:
size(800,800);
noFill();
bezier(340, 80, 40, 40, 360, 360, 60, 320);
int steps = 6;
fill(255);
for (int i = 0; i <= steps; i++)
{
float t = i / float(steps);
float x = bezierPoint(340, 40, 360, 60, t);
float y = bezierPoint(80, 40, 360, 320, t);
float tx = bezierTangent(340, 40, 360, 60, t);
float ty = bezierTangent(80, 40, 360, 320, t);
float a = atan2(ty, tx);
a += PI;
stroke(255, 102, 0);
line(x, y, cos(a)*120 + x, sin(a)*120 + y);
stroke(0);
ellipse(x, y, 10, 10);
}
Question 2:
2. Write a program to draw a continuous smooth Bezier curve with five (5) control points (take x and
y co-ordinates from user).

Code:
size(800, 800);
background(255);
beginShape();
vertex(30, 70);
bezierVertex(25, 25, 100, 50, 50, 100);
bezierVertex(20, 130, 75, 140, 120, 120);
endShape();
Question 3:

3. Write programs to draw a B-splines curve with the following curve points: (40, 40), (80, 60),
(100, 100), (60, 120), and (50, 150).

Code:
int[] coords = { 40, 40, 80, 60, 100, 100, 60, 120, 50, 150 };
void setup(){
size(600, 600);
background(255);
smooth();
noFill();
stroke(0);
beginShape();
curveVertex(40, 40);
curveVertex(40, 40);
curveVertex(80, 60);
curveVertex(100, 100);
curveVertex(60, 120);
curveVertex(50, 150);
curveVertex(50, 150);
endShape();
fill(255, 0, 0);
noStroke();
for (int i = 0; i < coords.length; i += 2)
{
ellipse(coords[i], coords[i + 1], 3, 3);
}
}
Question 4:

4. Write a program to draw a Bezier surface with with four (4) control points (firs control point should
be taken dynamically using mouse cursor).

Code:
void setup()
{
background(255);
size(1000, 1000);
stroke(50, 168, 145);
noFill();
}

void draw()
{
background(255);
for (int i = 0; i < 600; i += 20)
{
bezier(mouseX-(i/2.0), 40+i, 410, 20, 440, 300, 240-(i/16.0), 300+(i/8.0));
}
}
Output:

You might also like