#include<iostream>
#include<conio.h>
using namespace std;
int main(){
char band_metal[]="sepulture";
char *band_punk="rancid";
cout<<"Nama band Metal= "<<band_metal<<endl;
cout<<"Nama band Punk = "<<band_punk<<endl;
band_punk=band_punk-=10;
cout<<"Nama Band Metal= "<<band_metal<<endl;
cout<<"Nama Band Punk = "<<band_punk<<endl;
getch();
}
Leni M.S.L
Selasa, 11 Desember 2012
Senin, 10 Desember 2012
Contoh Program bola bergerak.C++
#include <GL/glut.h>Z
#include <stdlib.h>
#include <math.h>
typedef struct
{
float x;
float y;
} point2D_t;
void segiN(point2D_t p[], point2D_t p0, float r, int n)
{
float a=6.28/n;
for(int i=0;i<n;i++)
{
p[i].x=p0.x+r*cos(i*a);
p[i].y=p0.y+r*sin(i*a);
}
}
//fungsi untuk menggambar segiNdari titik di void segiN
void fillPolygon(point2D_t p[], int n)
{
glBegin(GL_POLYGON);
for(int i=0;i<n;i++)
{
glColor3f (255,255,255);
glVertex2f(p[i].x,p[i].y);
}
glEnd();
}
void bola()
{
static float x=0, y=0;
static int statsX=1, statsY=1;
point2D_t Segi[50],ps={x,y};
segiN(Segi,ps,10,50);
fillPolygon(Segi,50);
if(statsX == 1)
x+=0.05;
else if(statsX == 0)
x-=0.05;
if(statsY == 1)
y+=0.05;
else if(statsY == 0)
y-=0.05;
if(x >=150)
statsX-=1;
else if (x <=-150)
statsX+=1;
if(y >= 110)
statsY-=1;
else if(y <=-100)
statsY+=1;
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
bola();
glutSwapBuffers();
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowPosition(25,25);
glutInitWindowSize(640,480);
glutCreateWindow("Program X");
glClearColor(0.0,0.0,0.0,0.0);
gluOrtho2D(-160.,160.,-120.,120.);
glutIdleFunc(display);
glutDisplayFunc(display);
glutMainLoop();
}
Senin, 03 Desember 2012
Contoh Program Membuat Hujan.C++
#include <stdlib.h>
#include <math.h>
#include <time.h>
typedef struct {//MEMBUAT VARIABEL
float e[];
float mY[4][4];
}
VEKTOR,MATRIK;
typedef struct{
double x;
double y;
}TITIK;
typedef struct{
double red,green,blue;
}WARNA;
void setColor(WARNA col){
glColor3f(col.red,col.green,col.blue);//metode pewarnaan
}
VEKTOR operator * (MATRIK a, VEKTOR b)
{
VEKTOR c;
int i,j;
for (i=0;1<3;i++){
c.e[i]=0;
for (j=0;j<3;j++)
c.e[i]+=a.mY[i][j]*b.e[j];
}
return c;
}
VEKTOR titikV(TITIK pnt,TITIK transPoint)
{
VEKTOR vec;
vec.e[0]=pnt.x - transPoint.x;
vec.e[1]=pnt.y - transPoint.y;
vec.e[2]=1.;
return vec;
}
TITIK vector2point(VEKTOR vec,TITIK transPoint)
{
TITIK pnt;
pnt.x=vec.e[0] + transPoint.x;
pnt.y=vec.e[1] + transPoint.y;
return pnt;
}
void transform2D(TITIK p[], MATRIK mat, int n,float xCentre, float yCentre){
VEKTOR vec;
TITIK transPoint;
transPoint.x= xCentre;
transPoint.y= yCentre;
for (int i=0; i<n; i++){
vec=titikV (p[i],transPoint);
vec=mat*vec;
p[i]=vector2point (vec,transPoint);
}
}
void Line(double x1, double y1, double x2, double y2){
glBegin(GL_LINES);
glVertex2d(x1,y1);
glVertex2d(x2,y2);
glEnd();
}
void hujan(){
static TITIK hjn[295];
static int bunyi=0;
int i;
if(bunyi==0){
for (i=0;i<295;i++){
hjn[i].x=rand()%10000;
hjn[i].y=rand()%10000;
}
}
for (i=0;i<295;i++){
hjn[i].x-=1;
hjn[i].y-=1;
if (hjn[i].x<0||hjn[i].y<0){
hjn[i].x=rand()%800;
hjn[i].y=rand()%600;
}
}
glColor3f(1,1,1);
for (i=0;i<200;i++){
Line(hjn[i].x, hjn[i].y, hjn[i].x-4, hjn[i].y-2);
}
bunyi++;
}
void display (void){
glClear (GL_COLOR_BUFFER_BIT);
hujan();
glutSwapBuffers();
}
int main(int argc,char **argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowPosition(100,100);
glutInitWindowSize(800,600);
glutCreateWindow("Leni");
glClearColor(0.0, 0.0, 0.0, 0);
gluOrtho2D(0.,800.,0.,600.);
glutIdleFunc(display);
glutDisplayFunc(display);
glutMainLoop();
}
Outputnya :
Langganan:
Postingan (Atom)
