Posts

Showing posts with the label C

Computer Graphics Project "Planet Orbit" Source Code with Glut OpenGL

Image
Hello there !!!  This time I will post a project in the past. It is about rotation and applied to make earth orbital with moon and sun. As reminder, for you who haven’t install glut you can download it in here and follow the instruction I uploaded too. You can download this orbital project in here too. The image above is the result of orbital project. Here is the source code for this project. #include <windows.h> #include <stdlib.h> #include <GL/glut.h> #include <math.h> void myinit() { glClearColor(0.0, 0.0, 0.0, 1.0); glColor3f(1.0, 0.0, 0.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-400.0, 400.0, -400.0, 400.0,-400.0,400.0); glMatrixMode(GL_MODELVIEW); glShadeModel(GL_FLAT); glEnable(GL_DEPTH_TEST); } float putaransatu, putarandua = 0; typedef struct{ float x,y; } point2D_t; void drawDot(int x,int y){ glBegin(GL_POINTS); glVertex2i(x,y); glEnd(); } /*void bintang(void) { static int tick=0; static...

Computer Graphics Project "MINION" Source Code with Glut OpenGL

Image
Hello !!! This time I post about computer graphics again. And yes, I will share a project which mainly used rotation and a little bit morphing. You can download this project here ( Download here to download glut and follow the instruction ) .The character used in this project is well known. Well here’s the depiction of this project. Minion !!! The eyes will rotate. And it’s smile will move up and down which give you a creepy smile hahaha.  So here’s the source code for this project : #include <stdio.h> #include <math.h> #include <GL/glut.h> #ifndef M_PI #define M_PI 3.141592653589793 #endif typedef struct { float x; float y; } point2D_t; typedef struct { float r; float g; float b; } color_t; ////////////// OpenGL drawShape Functions ver 1 ///////////////// void setColor(float red,float green,float blue) { glColor3f(red, green, blue); } void setColor(color_t col) { glColor3f(col.r, col.g, col.b); } void drawDot(float x,float y) { ...

Computer Graphics using GLUT projects Source Code : Tiles Pattern

Image
Hello !!! Today I want to share my past project in computer graphics using Glut. For you who still do not have glut for C library, you can download it in here . I also give instruction how to installed it in your project here . And here are the projects for this tiles pattern.Actually, I made many of them in the past. But I’ll post them on by one in the future. This project of mine is tiles pattern. Most of it contains polygon lines. The result is just like  picture below : So You know computer graphics is such an existence which make you drawing with code instead of pencil or pen :p. So yeah the listing must be so long since this project used procedural programming. here are the source code for this project : // Created by: Dean Nicholls // Date: 18th June 2010 // Created For: http://www.levelbylevel.com // // This is a small OpenGL application which will display a // blue sphere on a black background. // // This Program was created to acompany the tutorial // fo...

Structure of C or C ++

Image
Structure of C or C ++ The commands listed in the program listing (listing the same as the syntax) C or C ++ are written with blocks. Each block is working on tasks that match with the task. Make sure every function name in accordance with the commands that are in it. Don't make a reduction function but the name of the function of addition. In the C or C ++ program there should be at least one main function that is the main function. This play function is also called the parent function. Why parent? Because any program written in C or C ++ language should have this function. What is a statement? So in the programming language, the commands that exist in the listing program is also called a statement. In the main function you can give empty statement but what do you expect for empty statement instead of empty program :). Yes, at least there is one statement lah. For the number of statements available, theoretically there is no explanation of how many limits can be writt...

Program Prime Numbers C Language

Image
Hey everyone, I want to share my experience with C language. This my program will print prime numbers. You simply enter the number of primes that you want to display. And this is the source code. #include<stdio.h> int main(){ int a, n, i, sum, total=0; printf("input how prime should print : "); scanf("%d",&n); for(a=1;total<n;a++){ sum=0; for(i=1;i<=a;i++){ if(a%i==0){ sum++; } } if(sum==2){ printf("%d ",a); total++; } } } It is a program from me, hopefully useful.

Why Should You Learn C ?

Image
Why Should You Learn C ? Although C is simple but do not underestimate it because C language is the most powerful programming language ever made. In this all-round IT world, many programming languages have sprung up and then used even out of use. So there must be a reason why C still exists today and until now almost no language can match its power. 90% of beginner programmer assumes that C has been replaced by Java, C #, etc., then why should learn C. I do not know why they have such statue but one thing I can be sure that they will not be able to outperform 10% which  have differ opinion from the others. The reason is simple, how can a skyscraper can stand if the foundation is not strong. C is a programming language developed by AT & T's Bell laboratory in the United States in 1972. It was written by a man named Dennis Ritchie. Now let's analyze why C language should be the first programming language you learn: I'm sure that no one can learn Java ...

Algorithm and Flowchart Simple Calculator

Image
Algorithm :  Initialize val1, val2, oprs, result  Input val1  Input val2  Choose operation (oprs) from +, -, x or :  If you choose operation (+), then the result = val1 + val2  If you select operation (-), then result = val1 - val2  If you select operation (x), then result = val1 * val2  If you select operation (:), then result = val1 / val2  Print results And this is the flowchart :

Algorithms and Programming Languages : How to implement algorithm in some programming languages?

Image
Algorithms and Programming Languages : How to implement algorithm in some programming languages? Consider the following example algorithm used to decompress the contents of array X (i) as below: The above algorithm consists of instructions. Although the instructions are written in codes close to computer programming languages, but the computer can not understand and execute those instructions. Computers can only understand if the instruction is written in a language called programming language. Here is given example of some programming languages as implementation of the above algorithm: It appears that the instructions in the Algorithm are intentionally made close to the instructions used in the programming language. So if it has been written the algorithm to solve a problem, then we can easily convert algorithm into form of programming language.