Search for question
Question

1 > Assignments > Animate

0

Animate

Due Tuesday by 11:59pm Points 100 Submitting an external tool

Animate

The goal of this assignment is to understand how to binary numbers work, and practice C programming.

Create a program to print integers as animated patterns made from their binary representation.

dwayne@Robust: 007-bitmap$

The animation above shows the execution of the following command:

$ ./animate 10 64 32 16 8 16 23 64

The first number (N) indicates the number of times the complete image should be "scrolled around". The rest of numbers are decimal

values which represent each row of the image. The top row is the first number, the next number represents the second row, and so on.

The first thing the program does is to clear the screen and put the cursor at the top-left. It does this using the code below. The le is the C

string literal for an escape (ESC) character, commonly used to send instructions to terminals. In this case, the ESC-c tells the terminal to

clear itself.

printf("\ec");

Next, the program displays two characters for each bit of each number. If the bit is one it displays (two Unicode Full Block characters),

but you can use an non-space characters, for example ##. If the bit is zero, two spaces are displayed. (Two characters are used because it

makes the aspect ratio closer to "square".) Obviously a newline is used to move the output cursor to the next row.

◄ Previous

Wireshark 4.0.8....dmg

python-3.11.5-m....pkg

pycharm-profes....dmg

FinalSubmission-....zip

Next ►

FinalSubmission-....zip

Show All

X/nAssignments > Animate

Animate

Due Tuesday by 11:59pm

$ ./animate 2 1 5

## @@

응응

@@ ##

%%

@@ ##

응응

## @@

olo

@@ ##

%%

@@ ##

응응

## @@

Hints:

001 1

101 5

◄ Previous

100 right-most bits "wrapped around"

110

010

011

Wireshark 4.0.8....dmg

Points 100 Submitting an external tool

001 we're back where we started

101

100

110

010

011

In the example above, each "lap" requires 3 shifts because the number 5 requires 3 bits. If either of the numbers were larger than 7, the

width of the image would be larger. The first example has 7 columns since 6410 = 100 00002.

Your solutions should work for any number of rows and for images upto 30 bits wide. Here are few more sets of numbers to try.

001

101

256 256 640 640 640 1096 9300 1037395 2080 2080 2048

14336 17408 33280 257 130 68 56

136 68 34 17 34 68 136

143165576 71582788 35791394 17895697 143165576 71582788 35791394 17895697 143165576 17895697 35791394 71582788 143165576 17895697 35791394 71582788 143165

we made 2 "laps", so stop

Debug without using the terminal escape sequence.

python-3.11.5-m....pkg

pycharm-profes....dmg

FinalSubmission-....zip

Next ►

FinalSubmission-....zip

Show All

X/nD1 › Assignments > Animate

Animate

Due Tuesday by 11:59pm Points 100 Submitting an external tool

printf("\ec");

Next, the program displays two characters for each bit of each number. If the bit is one it displays (two Unicode Full Block characters),

but you can use an non-space characters, for example ##. If the bit is zero, two spaces are displayed. (Two characters are used because it

makes the aspect ratio closer to "square".) Obviously a newline is used to move the output cursor to the next row.

After the entire image is drawn the program pauses for a moment using the function call shown below. This allows the viewer to see the

image, before it is replaced by the next image in about a tenth of a second. You can adjust the speed of the animation by adjusting the

delay.

usleep(100000);

Next the image must be "scrolled" one pixel (bit) to the right. Any bits that "fall off" should be "put back" on the left side. This process

should be repeated until the entire image has "looped around" N times.

The width of the image is determined by the highest bit in any row. In the example shown below, the terminal was not reset between

images, instead a blank line is used. Also each "pixel" uses a different character to indicate how movement works.

$ ./animate 2 1 5

## @@

@@ ##

응응

@@ ##

g

## @@

@@ ##

◄ Previous

Wireshark 4.0.8....dmg

001 1

101 5

100 right-most bits "wrapped around"

110

010

011

001 we're back where we started

101

100

110

010

python-3.11.5-m....pkg

pycharm-profes....dmg

FinalSubmission-....zip

1

Next ►

FinalSubmission-....zip

Show All

X/n› Assignments › Animate

Animate

Due Tuesday by 11:59pm

% %

## @@

001

101

Points 100 Submitting an external tool

In the example above, each "lap" requires 3 shifts because the number 5 requires 3 bits. If either of the numbers were larger than 7, the

width of the image would be larger. The first example has 7 columns since 6410 100 00002.

=

Your solutions should work for any number of rows and for images upto 30 bits wide. Here are few more sets of numbers to try.

we made 2 "laps", so stop

256 256 640 640 640 1096 9300 1037395 2080 2080 2048

14336 17408 33280 257 130 68 56

136 68 34 17 34 68 136

143165576 71582788 35791394 17895697 143165576 71582788 35791394 17895697 143165576 17895697 35791394 71582788 143165576 17895697 35791394 71582788 143165

Hints:

• Debug without using the terminal escape sequence.

If the Unicode characters aren't working, just use ##.

• Powers of 2 can be computing using a shift operation.

• You can shift the bits OR the "mask".

• It is not necessary to compute everything first, print as you go.

• You are not required to handle any input errors or illegal usage.

• A well-crafted solution should be less than 40 lines long, not counting comments or blank lines.

Submit your solutions as a single source file.

Submit

◄ Previous

Source: Choose File No file chosen

Submit

Wireshark 4.0.8....dmg

View problem in a new window

python-3.11.5-m....pkg

pycharm-profes....dmg

FinalSubmission-....zip

Next

FinalSubmission-....zip

Show All

X

Fig: 1

Fig: 2

Fig: 3

Fig: 4