Jaypee University of Information Technology
MULTIMEDIA LAB
18B1WCI575
SANSKAR PANDEY
221030358
CS-512
INDEX
Date of Date of
S.No Experiment Name Remarks
Perform Submission
1 Text Manipulation
2 Piano Sound Simulation
3 Read and Write into a File
4 Huffman Coding Algorithm
5 Display Bitmap Image
Web Development for
6
Clothing Company
College Admissions
7
Brochure
Experiment 1: Text Manipulation
Objective:
The main objective of this lab is to get familiar with one of the components of multimedia,
i.e., "TEXT". Students are required to perform operations related to the manipulation of text.
Input:
str = “The quick brown fox jumps over the lazy dog.”
L = 11
Code:
def justify_text(words, L):
lines = []
curr_line = []
curr_len = 0
for word in words:
if curr_len + len(curr_line) + len(word) <= L:
curr_line.append(word)
curr_len += len(word)
else:
spaces_needed = L - curr_len
if len(curr_line) == 1:
lines.append(curr_line[0] + '_' * spaces_needed)
else:
total_spaces = spaces_needed + len(curr_line) - 1
per_space = total_spaces // (len(curr_line) - 1)
extra_spaces = total_spaces % (len(curr_line) - 1)
line = ''
for i in range(len(curr_line) - 1):
line += curr_line[i] + '_' * (per_space + (1 if i < extra_spaces else 0))
line += curr_line[-1]
lines.append(line)
curr_line = [word]
curr_len = len(word)
last_line = '_'.join(curr_line) + '_' * (L - len('_'.join(curr_line)))
lines.append(last_line)
return lines
# Input
text = "The quick brown fox jumps over the lazy dog."
L = 11
words = text.split()
# Output
justified_text = justify_text(words, L)
for line in justified_text:
print(line)
Output:
The___quick
brown___fox
jumped_over
the____lazy
dogs.______
Experiment 2: Sound Manipulation
Objective:
The main objective of this lab is to get familiar with one of the components of multimedia,
i.e., "SOUND".
Student Task:
1. Study the notes of a piano and simulate them using the keyboard.
2. Store the notes played in a file.
Input:
The input will consist of user interactions through the keyboard, simulating piano keys.
Code:
import pygame
pygame.mixer.init()
notes = {
'a': 'C.wav',
's': 'D.wav',
'd': 'E.wav',
'f': 'F.wav',
'g': 'G.wav',
'h': 'A.wav',
'j': 'B.wav',
}
def play_note(note):
pygame.mixer.music.load(note)
pygame.mixer.music.play()
played_notes = []
print("Press keys to play piano notes (a-j). Press 'q' to quit and save the notes.")
while True:
key = input("Press a key: ")
if key == 'q':
break
elif key in notes:
play_note_file = notes[key]
play_note(play_note_file)
played_notes.append(key)
else:
print("Invalid key. Use 'a' to 'j' for notes, 'q' to quit.")
with open("played_notes.txt", "w") as file:
file.write(" ".join(played_notes))
print("Played notes saved to 'played_notes.txt'.")
Output:
1. After playing the notes, the sequence of keys pressed (notes played) will be stored in
the file played_notes.txt.
asdfghj
Experiment 3: File Manipulation and Computer Graphics
Objective:
The main objective of this lab is to get familiar with two components of multimedia, i.e.,
“READ AND WRITE INTO A FILE” and "COMPUTER GRAPHICS". Students are
required to perform operations related to text manipulation and generate interactive computer
graphics.
Student Task:
1. Write a program to read a paragraph and store it in a file name suggested by the
author.
2. Devise a routine to produce an animation effect of a square transforming into a
triangle and then into a circle.
Input:
● A paragraph entered by the user to be saved in a file.
● Animation of a shape transitioning from a square to a triangle and then to a circle.
Code:
import pygame
import time
# Initialize Pygame
pygame.init()
def read_and_save_paragraph():
paragraph = input("Enter a paragraph: ")
file_name = input("Enter the file name to save: ")
with open(file_name, "w") as file:
file.write(paragraph)
print(f"Paragraph saved in {file_name}.")
def draw_square(screen, color, size):
pygame.draw.rect(screen, color, pygame.Rect(200, 150, size, size))
pygame.display.update()
def draw_triangle(screen, color, size):
pygame.draw.polygon(screen, color, [(200, 150+size), (200+size//2, 150), (200+size,
150+size)])
pygame.display.update()
def draw_circle(screen, color, size):
pygame.draw.circle(screen, color, (200+size//2, 150+size//2), size//2)
pygame.display.update()
def animate_shapes():
screen = pygame.display.set_mode((600, 400))
pygame.display.set_caption("Shape Transformation Animation")
screen.fill((255, 255, 255))
draw_square(screen, (0, 0, 255), 100)
time.sleep(1)
screen.fill((255, 255, 255))
draw_triangle(screen, (0, 255, 0), 100)
time.sleep(1)
screen.fill((255, 255, 255))
draw_circle(screen, (255, 0, 0), 100)
time.sleep(1)
time.sleep(2)
pygame.quit()
read_and_save_paragraph()
animate_shapes()
Output:
Enter a paragraph: fgdsfgv
Enter the file name to save: sdf
Paragraph saved in sdf.
Experiment 4: Huffman Coding Algorithm
Objective:
The main objective of this lab is to get introduced to text and image compression algorithms
and implement the Huffman coding algorithm.
Student Task:
● Implement the Huffman coding algorithm for compression.
● Go through the document "Basics of Image Compression" for an introduction to the
topic.
Input:
A string or sequence of text for which Huffman coding will be applied to compress.
Code:
#include <iostream>
#include <queue>
#include <vector>
#include <unordered_map>
using namespace std;
struct Node {
char ch;
int freq;
Node *left, *right;
Node(char ch, int freq) {
left = right = nullptr;
this->ch = ch;
this->freq = freq;
}
};
// Comparator for priority queue
struct compare {
bool operator()(Node* left, Node* right) {
return left->freq > right->freq;
}
};
// Traverse the Huffman Tree and store codes
void encode(Node* root, string str, unordered_map<char, string> &huffmanCode) {
if (root == nullptr)
return;
if (!root->left && !root->right) {
huffmanCode[root->ch] = str;
}
encode(root->left, str + "0", huffmanCode);
encode(root->right, str + "1", huffmanCode);
}
// Build Huffman Tree and generate codes
void buildHuffmanTree(string text) {
unordered_map<char, int> freq;
for (char ch : text) {
freq[ch]++;
}
priority_queue<Node*, vector<Node*>, compare> pq;
for (auto pair : freq) {
pq.push(new Node(pair.first, pair.second));
}
while (pq.size() != 1) {
Node* left = pq.top(); pq.pop();
Node* right = pq.top(); pq.pop();
int sum = left->freq + right->freq;
pq.push(new Node('\0', sum, left, right));
}
Node* root = pq.top();
unordered_map<char, string> huffmanCode;
encode(root, "", huffmanCode);
cout << "Huffman Codes:\n";
for (auto pair : huffmanCode) {
cout << pair.first << " " << pair.second << '\n';
}
cout << "\nOriginal string:\n" << text << '\n';
string str = "";
for (char ch : text) {
str += huffmanCode[ch];
}
cout << "\nEncoded string:\n" << str << '\n';
}
int main() {
string text;
cout << "Enter the text to be compressed: ";
getline(cin, text);
buildHuffmanTree(text);
return 0;
}
Output:
1. Enter the text to be compressed: wdfnsdvuhdouh
2. Huffman Codes:
3. w: 000
4. n: 001
5. d: 01
6. u: 100
7. h: 101
8. s: 1100
9. o: 1101
10. v: 1110
11. f: 1111
12.
13. Original string:
14. wdfnsdvuhdouh
15.
16. Encoded string:
17. 0000111110011100011110100101011101100101
Experiment 5: Display Bitmap Image
Objective:
The main objective of this lab is to work in detail with images.
Student Task:
● Write a program to show a bitmap image on your computer screen.
● Refer to the document "Image Data Basics" for a better understanding.
Input:
A BMP image file path.
Code:
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
def display_bitmap_image(image_path):
img = mpimg.imread(image_path)
plt.imshow(img)
plt.axis('off')
plt.show()
if __name__ == "__main__":
image_path = input("Enter the path of the BMP image: ")
display_bitmap_image(image_path)
Output:
Enter the path of the BMP image: sample_640×426.bmp
Experiment 6: Web Development for a Clothing Company
Objective:
The main objective of this lab is to get familiar with the web development component of
Multimedia.
Student Task:
Create a web page for a clothing company that contains all the details of the company and at
least five links to other web pages. For better understanding, students are advised to read the
“Web Development Guide” in the Multimedia Folder.
Code (HTML):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Clothing Company</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
padding: 20px;
background-color: #f8f8f8;
}
h1 {
color: #333;
}
.header {
background-color: #4CAF50;
color: white;
padding: 10px;
text-align: center;
}
.links {
margin: 20px 0;
}
.links a {
display: inline-block;
margin: 10px;
padding: 10px;
color: white;
background-color: #007BFF;
text-decoration: none;
border-radius: 5px;
}
.links a:hover {
background-color: #0056b3;
}
footer {
text-align: center;
margin-top: 20px;
font-size: 0.8em;
}
</style>
</head>
<body>
<div class="header">
<h1>Welcome to ABC Clothing Company</h1>
<p>Your one-stop shop for the latest fashion trends!</p>
</div>
<section>
<h2>About Us</h2>
<p>ABC Clothing Company has been providing quality apparel for over 10 years. We
pride ourselves on offering stylish and comfortable clothing for all occasions.</p>
</section>
<section>
<h2>Our Products</h2>
<p>From casual wear to formal attire, we have something for everyone. Explore our
latest collections!</p>
</section>
<section class="links">
<h2>Quick Links</h2>
<a href="products.html">Products</a>
<a href="about.html">About Us</a>
<a href="contact.html">Contact</a>
<a href="faq.html">FAQ</a>
<a href="blog.html">Blog</a>
</section>
<footer>
<p>© 2024 ABC Clothing Company. All rights reserved.</p>
</footer>
</body>
</html>
Output:
Experiment 7: College Admissions Brochure
Objective:
The main objective of this lab is to create a brochure for college admissions, including details
such as courses offered, curriculum, placements, and more.
Student Task:
Create a brochure for your college that includes information about the courses offered,
curriculum details, placement statistics, and other relevant admission information.
Code (HTML/CSS):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Jaypee University Admissions Brochure</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f0f8ff;
}
.header {
background-color: #007BFF;
color: white;
text-align: center;
padding: 20px;
border-bottom: 5px solid #0056b3;
}
h1 {
margin: 0;
font-size: 2.5em;
}
h2 {
color: #0056b3;
}
.content {
margin: 20px;
padding: 15px;
border-radius: 10px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
background-color: #fff;
}
.courses {
background-color: #e6f7ff;
border-left: 10px solid #007BFF;
}
.curriculum {
background-color: #fff3e6;
border-left: 10px solid #ff7f50;
}
.placement {
background-color: #f0e6ff;
border-left: 10px solid #9370db;
}
.admission {
background-color: #e6ffe6;
border-left: 10px solid #28a745;
}
.footer {
text-align: center;
margin-top: 20px;
font-size: 0.8em;
background-color: #007BFF;
color: white;
padding: 10px;
position: relative;
}
.footer p {
margin: 5px;
}
.shape {
border-radius: 50%;
background-color: #ffcccb;
width: 150px;
height: 150px;
position: absolute;
left: 30px;
top: -40px;
opacity: 0.3;
}
</style>
</head>
<body>
<div class="header">
<h1>Jaypee University of Information Technology</h1>
<p>Your Future Begins Here!</p>
</div>
<div class="content courses">
<h2>Courses Offered</h2>
<ul>
<li>Bachelor of Science in Computer Science</li>
<li>Bachelor of Business Administration</li>
<li>Bachelor of Arts in Psychology</li>
<li>Master of Science in Data Science</li>
<li>Master of Business Administration</li>
</ul>
</div>
<div class="content curriculum">
<h2>Curriculum Overview</h2>
<p>Our curriculum is designed to provide students with a well-rounded education. Key
areas of focus include:</p>
<ul>
<li>Industry-relevant skills</li>
<li>Practical training and internships</li>
<li>Research opportunities</li>
<li>Soft skills development</li>
</ul>
</div>
<div class="content placement">
<h2>Placement Statistics</h2>
<p>We take pride in our placement record:</p>
<ul>
<li>90% of students placed within 6 months of graduation</li>
<li>Top recruiters: ABC Corp, XYZ Inc., Tech Solutions, etc.</li>
<li>Average salary package: $60,000</li>
</ul>
</div>
<div class="content admission">
<h2>Admission Process</h2>
<p>To apply for admission, follow these steps:</p>
<ol>
<li>Visit our website and fill out the application form.</li>
<li>Submit the required documents.</li>
<li>Attend the counseling session.</li>
<li>Receive admission confirmation.</li>
</ol>
</div>
<div class="footer">
<div class="shape"></div>
<p>© 2024 Jaypee University of Information Technology. All rights reserved.</p>
<p>Contact us: [email protected] | Phone: +123-456-7890</p>
</div>
</body>
</html>
Output: