Monday, June 29, 2015

Computer Graphics : Digital Differential Algorithm (DDA)


We don't have this in the lab exercise, but if you haven't done Bresenham line algorithm, you could start with this, then do Bresenham algorithm.

Anyways, if you try it, it's just good to see how this works too. You might not see much difference when compared to Bresenham, based on accuracy and stuff...at least I couldn't...may be I should run them both with same input and keep the output windows nearby and try to check the difference, and use some magnifying glass too probably...:P

You should try it! And this algorithm considers negative slope also, so code for that and the code should work even if the two points are given as input in different order, like point A first then point B or vice versa. It's obvious, still, just reminding you.

I was planning to post the code, since it's not a lab exercise, but since I asked you to try it, first try. And if you don't get it, mail me and I will help you with your code :) and later, may be I will provide my code if necessary.
 


Computer Graphics : Basic Circle !


Well, our teacher didn't teach circle yet, but I wanted to try it with the basic circle formula, like how I tried for basic line

This is how it looks :


You should notice the accuracy problems at a few points...I gotta analyze some things and try something different for those parts of the circle

This is the code :

Basic Circle Code

Computer Graphics : Bresenham Line Algorithm


The formula for m<1 has been implemented below.

The formula for m>1 should be found out and implemented.

Though I don't know if we should even find out the formulas for negative slope where |m| < 1 and |m| >1 ; for now, you could just try for positive m for which m>1

Bresenham Line Code



Saturday, June 27, 2015

Internet Programming : map tag


The first post based on Internet Programming Lab!

Ex 1 is based on basic HTML 5 tags, like, paragraph, break line, anchor, image, head,title and also based on the attributes of tags like src in img tag and href in anchor tag

Learn them from google and w3schools.com

Then there's map tag, below is an example :

<img src="planets.gif" width="145" height="126" alt="Planets" usemap="#planetmap">

<map name="planetmap">
  <area shape="rect" coords="0,0,82,126" href="sun.htm" alt="Sun">
  <area shape="circle" coords="90,58,3" href="mercur.htm" alt="Mercury">
  <area shape="circle" coords="124,58,8" href="venus.htm" alt="Venus">
</map>
 
You can try the code in this page if you have never used this tag : 

http://www.w3schools.com/tags/tag_map.asp
 
In the above example, you will see that different parts of the image is mapped to pages that  contain enlarged image of that part. It's planets here.

About the attributes. To give the coordinates for circle shape, you need to know the center of the circle and the radius.

It goes like : x,y,r
 
where (x,y) is the center and r is the radius.
 
You can find the points by opening the  image in an editor that can tell the coordinates of various points on the image just by scrolling over the mouse over to that point. Editors like Paint in windows and KolorPaint in CentOS can do that.
 
For rectangle, you need to the points on the opposite sides of a diagonal, like the left top corner and the right bottom corner point of the rectangle.

left top : (a,b)
right bottom : (c,d)
 
The attribute is like :
coords="a,b,c,d"
 
Try it out if you haven't! It's nice! :)

Feedback and About Blog


If you are visiting this blog, and if you think it helps you, do give feedback through comments or mail, about what you expect from the blog. Like, is it good to have posts that teach you how to do stuff ? or you want code ? or both ? or what ?

About posting code...well, I am really not the type of person who just copies code or encourages the same. Though I must say, I never typed much of SQL queries in 3rd sem and had lots of issues learning it later.

Most times, it's some lazy person asking for code...very few people get code from others and learn from it, by analyzing it. And believe me when I say - One of the toughest jobs is, understanding another guy's code. I would say you better break your head and try writing the code instead of breaking your head trying to understand the way someone else thinks. Just a suggestion.

So, codes won't be posted much. At least, not exact codes for lab work, though related codes and references will be posted.

Don't forget to give feedback!

Friday, June 26, 2015

Computer Graphics : Just some Line Algorithm


Try analyzing the below code. It's not exactly DDA algorithm. It just uses some basic math like DDA, and the trick for 'sampling' is based on the slope value.

In DDA algorithm, the equations for the coordinates are recurrence equations, here I haven't used recurrence stuff, that's it.

Refer this pdf if you don't know about DDA algorithm :

Line Algorithms PDF


The Code :

Basic Line Code

And do check on the glVertex2f() function...I am checking on it too...if that works fine, then we don't need to go for better algorithms etc...we can pass floating point arguments and plot the line. Though it doesn't make sense...like, pixels are discrete countable stuff. So, we can't just say plot a pixel at ( 234.6 , 156.7 )..it looks weird...Look about it. And do mail me if you get something.

Computer Graphics : Triangle Primitive


Triangle Fan

#include<GL/glut.h>

void myInit()
{
    glClearColor(1.0,1.0,1.0,0.0);
    glColor3f(1.0,0.0,0.0);
    glPointSize(1);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0.0,640.0,0.0,480.0);
}

void myDisplay()
{
    glClear(GL_COLOR_BUFFER_BIT);

    glBegin(GL_TRIANGLE_FAN);
        glVertex2d(200,200);
       
        glVertex2d(150,250);
        glVertex2d(250,250);
       
        glVertex2d(300,225);
        glVertex2d(300,175);
       
        glVertex2d(250,150);
        glVertex2d(150,150);
       
        glVertex2d(100,175);
        glVertex2d(100,225);
        glVertex2d(150,250);
    glEnd();

    glFlush();
}

int main(int argc,char* argv[])
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
    glutInitWindowSize(640,480);
    glutCreateWindow("First Exercise");
    glutDisplayFunc(myDisplay);
    myInit();
    glutMainLoop();
    return 1;
}

This was nice...you should try this


Wednesday, June 24, 2015

Computer Graphics Ex 1 : Primtives


If you have attended Computer Graphics Lab, read further.

This is some good page I found about primitives, except for Polygons :

https://www.opengl.org/wiki/Primitive

I was planning to put up some codes and show some outputs based on the above explanation...anyways, most of them are easy, and you would understand them on your own, if you read it along with the examples given in the above link...

If you still want to look at code and some output pictures, here's a link I found out just now :

http://www.codeproject.com/Articles/23991/OpenGL-Geometric-Primitives

The above link has code, output pictures and some stuff about polygons, actually, convex polygons, which I never understood when I just tried the code and checked the output to understand it by trial and error...It's still a bit confusing for me...so, read it slow and twice...other than that, everything should be okay with some reference using the links and practice.

And if you have attended the lab, you would know that Ex 1 is just about drawing these simple primitives. And then we have a chess board drawing. It's cool, try it soon! You can draw these using the primitives, which makes things easier. But later, I think, we will even do stuff like - use just points to draw stuff. Just point primitive. Cool, isn't it ? :P

Tuesday, June 23, 2015

Java Compiler for linux


You could use eclipse editor and stuff. This is the simplest method, where you just need any editor, like gedit, and a java compiler and java interpreter (Java Runtime Environment etc) for executing, I don't know much actually.

To compile a java program in linux, you need the java compiler, javac... like gcc for C and g++ for C++

To get javac, type this in terminal :

sudo apt-get install openjdk-8-jdk

and to execute, you need the 'java' command, I think it's preinstalled in the new versions of ubuntu, so, just type in the terminal :

java

and you should see many options for the command. Which means, it is already installed.

Or get it by typing this :

sudo apt-get install openjdk-8-jre


To verify it's working, open gedit or some editor and type this code :

class test
{
    public static void main(String[] args)
    {
        System.out.println("Hello World");
    }
}

And save this as test.java (don't change the name)

and run the following commands one by one :

javac test.java

java test

and it should print "Hello World" as output. Good luck ! :)


Argo UML for linux and windows

For Windows, download the setup file from here :

http://filehippo.com/download_argouml/

and install it.


For Linux :

Download this archive :

http://argouml-downloads.tigris.org/nonav/argouml-0.34/ArgoUML-0.34.tar.gz

and put the archive in the home folder. Now, type these commands in the terminal one by one :

tar -zxvf ArgoUML-0.34.tar.gz

chmod +x argouml-0.34/argouml.sh

./argouml-0.34/argouml.sh

The last line will open up Argo UML. And the above process will create a folder in your home folder, named "argouml-0.34", this is the place where the software files are kept, and this folder will have the .sh script file to run the application. This is understood from the last line.

Monday, June 22, 2015

Computer Graphics - getting glut library


We need glut to practice all our code, because the code contains functions from the glut library...so to get the glut library, you need to type this in the terminal :

sudo apt-get install freeglut3-dev

Now, just to verify, try this code :

#include<GL/glut.h>

void myInit()
{
    glClearColor(1.0,1.0,1.0,0.0);
    glColor3f(1.0,0.0,0.0);
    glPointSize(1);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0.0,640.0,0.0,480.0);
}

void myDisplay()
{
    glClear(GL_COLOR_BUFFER_BIT);

    glBegin(GL_LINES);
        glVertex2d(100,100);
        glVertex2d(100,200);
    glEnd();

    glFlush();
}

int main(int argc,char* argv[])
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
    glutInitWindowSize(640,480);
    glutCreateWindow("First Exercise");
    glutDisplayFunc(myDisplay);
    myInit();
    glutMainLoop();
    return 1;
}

save the above code as sample.c

and to compile, type this in the terminal :

gcc sample.c -lGL -lGLU -lglut -o sample

( it's 'l' , that is, a small L after every hyphen )

and now to see the output, type the usual thing :

./sample

The output should appear in a new window, and the output is a red line at the left bottom of the window. This way you can verify that glut libraries are installed properly and that you can run programs which use glut library functions, good luck! :)