Docsity

ADAVANCE JAVA PROGRAMMING, Cheat Sheet of Java Programming

Toggle sidebar
bg1
Subject Code : 3160717 Subject Name : Data Visualization Date :31/01/2023
Enrollment No : 200420107076 Name : Raj Dudhat
Practical No. : 2(a)
Problem Statement:
Draw Line, Rectangle, Circle, Arc, House. Apply different styles.
Program:
<!DOCTYPE html>
<html>
<head>
<title>Canvas Drawing</title>
<style>
canvas {
border: 1px solid black;
}
</style>
</head>
<body>
<canvas id="myCanvas" width="400" height="400"></canvas>
<script>
const canvas = document.getElementById("myCanvas");
const ctx = canvas.getContext("2d");
// Draw a line
ctx.beginPath();
ctx.moveTo(50, 50);
ctx.lineTo(200, 50);
ctx.lineWidth = 5;
ctx.strokeStyle = "blue";
ctx.stroke();
// Draw a rectangle
ctx.beginPath();
ctx.rect(50, 100, 200, 100);
ctx.fillStyle = "yellow";
ctx.fill();
ctx.lineWidth = 3;
SCET/CO/2022-23/EVEN/BE Shift-II/Sem-VI Page No : 1
pf3
pf4
pf5

Partial preview of the text

Download ADAVANCE JAVA PROGRAMMING and more Cheat Sheet Java Programming in PDF only on Docsity!

Enrollment No : 200420107076 Name : Raj Dudhat

Practical No. : 2(a)

Problem Statement:

Draw Line, Rectangle, Circle, Arc, House. Apply different styles.

Program:

Canvas Drawing

Enrollment No : 200420107076 Name : Raj Dudhat ctx.strokeStyle = "red"; ctx.stroke(); // Draw a circle ctx.beginPath(); ctx.arc(200, 250, 50, 0, 2 * Math.PI); ctx.fillStyle = "lightgreen"; ctx.fill(); ctx.lineWidth = 5; ctx.strokeStyle = "green"; ctx.stroke(); // Draw an arc ctx.beginPath(); ctx.arc(100, 250, 50, Math.PI / 4, (3 * Math.PI) / 4); ctx.lineWidth = 2; ctx.strokeStyle = "purple"; ctx.stroke();

HOUSE:

Document

canvas

Enrollment No : 200420107076 Name : Raj Dudhat context.beginPath(); context.rect(150, 300, 200, 200); context.lineWidth = 5; context.strokeStyle = "red"; context.fillStyle = "brown"; context.fill(); context.stroke(); context.beginPath(); context.rect(225, 400, 50, 100); context.lineWidth = 5; context.strokeStyle = "black"; context.fillStyle = "green"; context.fill(); context.stroke(); context.beginPath(); context.moveTo(100, 300); context.lineTo(400, 300); context.lineWidth = 5; context.strokeStyle = "purple"; context.lineTo(250, 200); context.closePath(); context.fillStyle = "blue"; context.fill(); context.stroke();

Enrollment No : 200420107076 Name : Raj Dudhat

Output:

HOUSE: