Kamis, 06 Desember 2012
Algoritma Elipse dan Midpoint Elipse
// AHMAD FADLY DZIL JALAL [2010 470 121]
// @ ALL RIGHTS RESERVED
#include "stdafx.h"
#include <glut.h>
GLuint global_w = 1200;
GLuint global_h = 600;
float putaran_A = 0;
float putaran_B = 0;
int sisi = 50;
void init();
void idle();
void display();
void reshape(int w, int h);
void ElipseSederhana(float xc, float yc, float x, float y);
void elipseMidpoint(float xc, float yc, float rx, float ry);
int _tmain(int argc, char* argv[])
{
glutInit(&argc,argv );
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutInitWindowPosition(50,50);
glutInitWindowSize(global_w,global_h);
glutCreateWindow ("Tugas");
glutSetWindowTitle( "Elipse" );
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
//glutIdleFunc(idle);
glutMainLoop();
return 0;
}
void init()
{
// clear background
glClearColor(0.0,0.0,0.0,1.0);
glShadeModel(GL_SMOOTH);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-global_w/2,global_w/2,-global_h/2,global_h/2,-1.0,1.0);
//glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);
};
void display (){
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glTranslatef(sisi,sisi,0);
glRotatef(putaran_B,0.0,0.0,0.0); //SUDUT, X, Y, Z
glTranslatef(-sisi,-sisi,0);
glBegin (GL_POINTS);
glColor3f (1,1,0);
elipseMidpoint(600, 300, 100 , 40);
glEnd();
glPopMatrix();
glutSwapBuffers();
glPushMatrix();
glTranslatef(sisi,sisi,0);
glRotatef(putaran_A,0.0,0.0,0.0); //SUDUT, X, Y, Z
glTranslatef(-sisi,-sisi,0);
glBegin (GL_LINES);//PUTIH
glColor3f (1,1,1);
elipseMidpoint(600, 300, 100 , 20);
glEnd();
glBegin (GL_LINES);//HIJAU
glColor3f (0,1,0);
elipseMidpoint(600, 400, 200 , 40);
glEnd();
glBegin (GL_POINTS);//HIJAU
glColor3f (0,1,0);
elipseMidpoint(400, 400, 20 , 40);
glEnd();
glBegin (GL_POINTS);//HIJAU
glColor3f (0,1,0);
elipseMidpoint(800, 400, 20 , 40);
glEnd();
glBegin (GL_POINTS);//BIRU
glColor3f (0,0,1);
elipseMidpoint(600, 200, 200 , 40);
glEnd();
glBegin (GL_POINTS);//BIRU
glColor3f (0,0,1);
elipseMidpoint(400, 200, 20 , 40);
glEnd();
glBegin (GL_POINTS);//BIRU
glColor3f (0,0,1);
elipseMidpoint(800, 200, 20 , 40);
glEnd();
glColor3f (1,1,1);
glBegin (GL_LINE_LOOP);
ElipseSederhana(200, 200, 100, 40);
glEnd();
glPopMatrix();
glutSwapBuffers();
glFlush();
}
void reshape (int w, int h){
global_w = w;
global_h = h;
glViewport(0,0,(GLsizei)w,(GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,w,0,h);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glScalef(1,1,1);
glutPostRedisplay();
}
void ElipseSederhana(float xc, float yc, float x, float y)
{
int p1[] = {(int)xc+x, (int)yc+y}; glVertex2iv(p1);
int p2[] = {(int)xc-x, (int)yc+y}; glVertex2iv(p2);
int p3[] = {(int)xc+x, (int)yc-y}; glVertex2iv(p3);
int p4[] = {(int)xc-x, (int)yc-y}; glVertex2iv(p4);
}
void elipseMidpoint(float xc, float yc, float rx, float ry)
{
float rxSq = rx * rx;
float rySq = ry * ry;
float x = 0, y = ry, p;
float px = 0, py = 2 * rxSq * y;
ElipseSederhana(xc, yc, x, y);
p = rySq - (rxSq * ry) + (0.25 * rxSq);
while (px < py)
{
x++;
px = px + 2 * rySq;
if (p < 0)
p = p + rySq + px;
else
{
y--;
py = py - 2 * rxSq;
p = p + rySq + px - py;
}
ElipseSederhana(xc, yc, x, y);
}
p = rySq*(x+0.5)*(x+0.5) + rxSq*(y-1)*(y-1) - rxSq*rySq;
while (y > 0)
{
y--;
py = py - 2 * rxSq;
if (p > 0)
p = p + rxSq - py;
else
{
x++;
px = px + 2 * rySq;
p = p + rxSq - py + px;
}
ElipseSederhana(xc, yc, x, y);
}
}
Sabtu, 17 November 2012
Trik Menjalankan Geany di windows :
Geany aslinya Linux, tapi akhirnya dibuat versi windows-nya. Akan tetapi tidak selengkap di Linux.
Disini saya akan menjelaskan bagaimana agar si Geany mau meng-compile program Pascal dan C
Geany aslinya Linux, tapi akhirnya dibuat versi windows-nya. Akan tetapi tidak selengkap di Linux.
Disini saya akan menjelaskan bagaimana agar si Geany mau meng-compile program Pascal dan C
- Siapkan Komputer dengan OS Windows
- Internet yang cukup memadai (Saya pakai Hotspot UMJ...hehehehe)
- Download compiler nya dulu :
- Untuk Bahasa C : http://sourceforge.net/projects/mingw/files/
- Untuk Free Pascal : http://sourceforge.net/projects/freepascal/files/
- Extract ke dua compiler tersebut, and Go to "My Computer".
- Klik kanan, pilih tabel Advanced, terus Environment Settings, arahkan ke directory dimana ekstrak ke dua kompiler tersebut. Defaultnya : U
Rabu, 10 Oktober 2012
Penerapan Algoritma Naif1, Naif2, DDA, Midpoint line di visual studio 2008
Sekedar sharing buat teman-teman mahasiswa, dan juga buat dokumentasi.
Siapa tahu dibutuhkan suatu saat...
// AhmadFadlyDzilJalal_2010470121_KG2.cpp : Defines the entry point for the console application. //
#include "stdafx.h"
#include <glut.h>
GLuint global_w=800;
GLuint global_h=600;
void init();
void display();
void reshape(int w,int h);
void AlgoritmaNaif1(int x1,int y1,int x2,int y2);
void AlgoritmaNaif2(int x1,int y1,int x2,int y2);
void AlgoritmaDDA (int x1,int y1,int x2,int y2);
void MidPoint (int x1,int y1,int x2,int y2);
int _tmain(int argc, char* argv[])
{
glutInit(&argc,argv );
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutInitWindowPosition(50,50);
glutInitWindowSize(global_w,global_h);
glutCreateWindow ("Tugas");
glutSetWindowTitle( "Garis Dengan Algoritma Naif 1 & 2 & DDA" );
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
void reshape(int w,int h)
{
global_w=w;
global_h=h;
glViewport(0,0,(GLsizei)w,(GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,w,0,h);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glScalef(1,1,1);
glutPostRedisplay();
}
void init()
{
glClearColor(0.3,0.5,0.5,1);
glShadeModel(GL_3D);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1,1,0);//glPointSize(20);
glBegin(GL_POINTS);
AlgoritmaNaif1(0,10,200,500 );
AlgoritmaNaif2(0,10,500,500);
AlgoritmaDDA (0,0,500,500);
MidPoint (100,100,500,150);
glEnd();
glFlush();
}
void MidPoint (int x1,int y1,int x2,int y2)
{
GLint xi =x1;
GLint yi =y1;
GLint dy = y2-y1;
GLint dx = x2-x1;
GLint D = (2 * dy) -dx;
GLint dE = 2* dy;
GLint dNE = dy-dx;
while (xi <= x2)
{
glVertex2f (xi,yi);
if (D<0) D+= dE;
else {
D+= dNE;
xi++;
}
yi++;
}
}
void AlgoritmaNaif1(int x1,int y1,int x2,int y2) {
GLfloat xi=x1;
GLfloat yi=y1;
GLfloat m=(y2-y1)/(x2-x1);
for (xi=x1; xi<x2; xi++) {
yi=m*(xi-x1)+y1;
glVertex2f(xi,yi);
printf("(%f,%f)\n",xi,yi);
}
}
void AlgoritmaNaif2(int x1,int y1,int x2,int y2) {
GLfloat xi=0;
GLfloat yi=y1;
GLfloat m=(y2-y1)/(x2-x1);
for (xi=x1; xi<x2; xi++) {
yi=m*(xi-x1)+y1;
yi+=m;
glVertex2f(xi,yi);
printf("(%f,%f)\n",xi,yi);
}
}
void AlgoritmaDDA (int x1, int y1, int x2, int y2){
GLfloat xi=x1;
GLfloat yi=y1;
GLfloat m = (y2-y1)/(x2-x1);
for (xi=x1; xi<x2; xi++){
yi+= m;
glVertex2f (xi,yi);
printf ("%f, %f\n", xi,yi);
}
}
// AhmadFadlyDzilJalal_2010470121_KG2.cpp : Defines the entry point for the console application. //
#include "stdafx.h"
#include <glut.h>
else {
D+= dNE;
xi++;
}
yi++;
}
}
void AlgoritmaNaif1(int x1,int y1,int x2,int y2) {
GLfloat xi=x1;
GLfloat yi=y1;
GLfloat m=(y2-y1)/(x2-x1);
for (xi=x1; xi<x2; xi++) {
yi=m*(xi-x1)+y1;
glVertex2f(xi,yi);
printf("(%f,%f)\n",xi,yi);
}
}
void AlgoritmaNaif2(int x1,int y1,int x2,int y2) {
GLfloat xi=0;
GLfloat yi=y1;
GLfloat m=(y2-y1)/(x2-x1);
for (xi=x1; xi<x2; xi++) {
yi=m*(xi-x1)+y1;
yi+=m;
glVertex2f(xi,yi);
printf("(%f,%f)\n",xi,yi);
}
}
void AlgoritmaDDA (int x1, int y1, int x2, int y2){
GLfloat xi=x1;
GLfloat yi=y1;
GLfloat m = (y2-y1)/(x2-x1);
for (xi=x1; xi<x2; xi++){
yi+= m;
glVertex2f (xi,yi);
printf ("%f, %f\n", xi,yi);
}
}
Langganan:
Postingan (Atom)