Character Generation by the Bitmap Method is a fundamental technique in computer graphics for rendering text or custom symbols on a raster display. A character is represented as a two-dimensional binary (or integer) grid — called a bitmap — where each cell in the grid corresponds to one pixel. A 1 (or any non-zero value) means the pixel should be drawn; a 0 means it should be left blank. This method is used in early video games, embedded displays, and any system that needs custom pixel-perfect fonts.
Category Archives: Snippets
Mix (C++ and Assembly) Program to Sort Numbers in Descending Order
This post demonstrates how to sort an array of integers using inline assembly in C++. We use basic comparison and swap logic in assembly embedded within a C++ program.
#include<iostream.h>
#include<conio.h>
void main()
{
int a[5], x, y;
int i, j;
cout << "\n Enter 5 Numbers:";
for(i = 0; i < 5; i++)
{
cin >> a[i];
}
//Sorting
for(i = 0; i < 4; i++)
{
for(j = 0; j < 4; j++)
{
x = a[j];
y = a[j + 1];
asm {
mov ax, x
mov bx, y
cmp ax, bx
jge nxt
mov cx, ax
mov ax, bx
mov bx, cx
mov x, ax
mov y, bx
}
nxt:
a[j] = x;
a[j + 1] = y;
}
}
cout << "\n Sorted Array:";
for(i = 0; i < 5; i++)
cout << a[i] << " ";
getch();
}
Implementing Bresenham’s Circle Drawing Algorithm in C++
Bresenham’s circle algorithm is an efficient way to draw a circle using only integer calculations. It eliminates the need for floating-point arithmetic and is widely used in computer graphics.
Below is the implementation of Bresenham’s circle drawing algorithm using C++ and the graphics.h library. This program takes user input for the circle’s center and radius, then uses the algorithm to plot the circle.
Continue reading Implementing Bresenham’s Circle Drawing Algorithm in C++Implementing Boundary Fill Algorithm in C++
The Boundary Fill Algorithm is a region-filling technique used in computer graphics to fill a connected area with a new colour. Starting from a seed pixel inside the shape, the algorithm recursively colours every neighbouring pixel as long as it does not match the defined boundary colour and has not already been coloured with the new fill colour. It supports 8-connected filling, meaning it spreads to all eight surrounding pixels — including diagonals.
Continue reading Implementing Boundary Fill Algorithm in C++Implementing Bresenham’s Line Algorithm in C++
Bresenham’s Line Algorithm is one of the most fundamental algorithms in computer graphics. It determines the set of pixels that most closely approximate a straight line between two given endpoints on a raster display. The key advantage of Bresenham’s algorithm over simpler approaches is that it uses only integer arithmetic — no floating-point multiplication or division — making it extremely fast for hardware and software rendering alike.
Continue reading Implementing Bresenham’s Line Algorithm in C++Implementing 2-D Transformation in C++
2-D Transformations are fundamental operations in computer graphics that change the position, size, or orientation of geometric objects on a 2-D plane. The three basic transformations are Translation (moving an object), Scaling (resizing an object), and Rotation (rotating an object about the origin). This C++ program implements all three transformations on a line segment entered by the user and renders the transformed result using the Turbo C++ graphics.h library.
Implementing Tower of Hanoi Problem in Java
The Tower of Hanoi is a classic mathematical puzzle that elegantly demonstrates the power of recursion. It consists of three rods (pegs) and a number of disks of different sizes that can slide onto any rod. The puzzle begins with all disks stacked in ascending size order on one rod (smallest on top) and the goal is to move the entire stack to another rod.
Three rules must be followed:
- Only one disk may be moved at a time.
- A disk may only be moved if it is the uppermost disk on its rod.
- No disk may be placed on top of a smaller disk.
The minimum number of moves required to solve the puzzle with n disks is 2n − 1. For 3 disks, that’s 7 moves; for 10 disks, 1023 moves.
Continue reading Implementing Tower of Hanoi Problem in Java