0% found this document useful (0 votes)
66 views5 pages

Readme

The document provides details about exercises completed by Bogdan Predescu, a student in the FILS faculty. It summarizes Bogdan's approaches to solving 7 exercises involving basic graphics and animation. It explains that exercises 1-6 involved drawing basic shapes and lines, while exercise 7 required creating animation of a stick figure moving left and right using buffered images. The document notes that exercise 7 posed the most difficulty initially but was solved by using pre-generated sprite images displayed in sequence to create an animation effect.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views5 pages

Readme

The document provides details about exercises completed by Bogdan Predescu, a student in the FILS faculty. It summarizes Bogdan's approaches to solving 7 exercises involving basic graphics and animation. It explains that exercises 1-6 involved drawing basic shapes and lines, while exercise 7 required creating animation of a stick figure moving left and right using buffered images. The document notes that exercise 7 posed the most difficulty initially but was solved by using pre-generated sprite images displayed in sequence to create an animation effect.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

***

Name: Predescu Bogdan


Faculty: FILS - 1232E
***
Requirements Done: All Exercises
***
Brief Explanation for Exercices:
For the first 2 exercices i used a boolean firstTime in order to keep the
graphics, avoid repainting and draw only once when the the applet is
initialized.
EX1)
I used a method from the class Graphics (g.fillRect(4,9,1,1));
where x and y are coordinates of the point and 1,1 are the width and
height of the point;
EX2)
For this exercise i only used the method g.fillRect(x,y,width,height)
where (x,y) are taken from the mouseCliked method and width, height
are given.
EX3)
This exercise has static coordinates so it will be executed only once in
the paint method at the start of the applet.
All i had to do was to use the line Bresenham method and put the
coordinates x0,y0,x1,y1;
EX4)
Is the same like ex 3 with static coordinates;

EX5)
For this exercise i had to use int x,y for the click coordinates(which is a
point);
All i had to do was to set the values for x and y when the mouse is
clicked
(x = e.getX() and y=e.getY();)
Then i had to find a way to determine the number of click(when the
mouse is clicked twice -> draw the line). So i created a boolean
twoPoints which is false by default.
The approach i used is a basic one:
if(twoPoints == false) {
nextPoint = e.getPoint();
twoPoints = true;
}else {
previousPoint = nextPoint;
nextPoint = e.getPoint();
line (previousP.x,previousP.y,nextP.x,nextP.y,g,10,10);
}
When the first click is pressed next Point takes the coordinates (x,y) and
two Points
becomes true; When the second click is pressed previousPoints takes the
values of nextPoint and nextPoints takes the values (x,y) from the mouse
click. Only second time the line Bresenham method is called to draw the
line between the 2 points.
The exercise can also be done using a counter and check the counter for
parity (something like
if (counter %2 == 0) {drawBresenhamLine();} else {};

EX6)
Insted of drag, in order to avoid calling repaint(), i used mousePressed
and mouseReleased methods. I took x1,y1 from mousePressed and x2,y2
from mouseReleased.
In MouseReleased i call the method line(x1,y1,x2,y2). I do that because
in mouseReleased x1,y1 are defined from mousePressed.
EX7)
I generated some animated stages in paint.net and then i populated a List
of BufferedImages(8 frames for right, 8 frames for left). I created an
interface Animation which comes with some basic methods. Then a class
StickMan which implements that inferface in order to have
@OverrideMethods. I also defined a method checkBoundsX which
keeps the character inside the screen for X Axis. Then the rest is done in
paintMethod which works on two cases when boolean right in true or
when boolean left is true; These values are set from the keyboard when
arrows are pressed. Then I take all 8 frames for right and all 8 frames for
left in order and make a cycle of frames per right/left keys.
***Time Spent and Difficulty
I don't know exactly the number of hours, but for the first 6 exercises
I've spent one hours i think. They are quite simple, except the
Bresenham Algorithm which have to be implemented, after that,
everything is ok.
The Bonus exercise was a little difficult because in the first stage i tried
to create a frame(sprite) using only forms(polygon,circle etc), but i
realisez that is quite hard because is a lot of work especially for
incrementing the x coordinates for movements.
The code for a single frame was like this:
static int[] arrHead = {150,50,215,100};
static int[] arrEyes1 = {239 , 235, 10, 10};
static int[] arrEyes2 = {275 , 240, 10, 10};
static int[] arrMouth = {245 , 270, 270, 273};

static int[] arrBodyX = {245,255,235,225};


static int[] arrBodyY = {300,300,450,450};
static int[] arrHandsLX = {243,190,180,195,200,242};
static int[] arrHandsLY = {320,330,370,370,340,330};
static int[] arrHandsRX = {252,271,310,310,263,250};
static int[] arrHandsRY = {320,352,357,369,364,330};
static int[] arrLegsLX = {236,270,260,249,255,236};
static int[] arrLegsLY = {438,443,533,530,453,450};
static int[] arrLegsRX = {225,213,198,212,225,235};
static int[] arrLegsRY = {450,525,545,550,523,450};
Graphics2D g2d = (Graphics2D)g;
//TEXT,
g2d.drawOval(150, 50, 215, 100);
g2d.setFont(new Font("Serif",Font.BOLD,20));
g2d.drawString("Hello", 245, 105);
//HEAD
g2d.setColor(Color.GREEN);
g2d.fillOval(arrHead[0] , arrHead[1], arrHead[2],
arrHead[3] );
//EYES
g2d.setColor(Color.BLACK);
g2d.fillOval(arrEyes1[0] , arrEyes1[1], arrEyes1[2],
arrEyes1[3]);
g2d.fillOval(arrEyes2[0] , arrEyes2[1], arrEyes2[2],
arrEyes2[3]);
//MOUTH
g2d.drawLine(arrMouth[0],arrMouth[1],arrMouth[2],arrMouth[3]);
//BODY
g2d.setColor(Color.RED);

g2d.fillPolygon(arrBodyX, arrBodyY,
arrBodyX.length);
//HANDS
//left hand
g2d.setColor(Color.BLACK);
g2d.fillPolygon(arrHandsLX, arrHandsLY,
arrHandsLX.length);
//right hand
g2d.fillPolygon(arrHandsRX, arrHandsRY,
arrHandsRX.length);
//LEGS
g2d.fillPolygon(arrLegsLX, arrLegsLY,
arrLegsLX.length);
g2d.fillPolygon(arrLegsRX, arrLegsRY,
arrLegsRX.length);

So i realised that i have to work too much for a minimum of 8 frames for
right movements.
Then i discovered some tools like openGL, slick library, spritesheet and
an algorithm which takes a spriteSheet formed of X frames and divides
it by width. With some AppGameContainer, renderMethod and 2-3
functions everything worked fine.
But in the end i decided to use simple things like a set of 8
frames(sprites images) for every movement and display them in some
order. In order to create the animation i change the image quickly and
modified the x coordinates for that image, in this way the animation
effect is made. I could probably add some random obstacles, effects,
music, etc, but that's maybe for the next homework :).

You might also like