Coding Membuat baling-baling berputar pada pemrograman grafis tidak terlalu susah. Anda hanya perlu membuat persegi, tiang, segiti. Selebihnya Anda kombinasikan objek-objek tersebut untuk membuat sebuah drone atau baling-baling.
Coding dibawah ini adalah contoh coding membuat drone atau baling-baling sederhana pada java. Anda juga bisa membuat nya lebih sempurna.
Berikut adalah coding dari cara membuat drone pada java :
PENAMPAKAN PROGRAM JIKA DIJALANKAN
Coding dibawah ini adalah contoh coding membuat drone atau baling-baling sederhana pada java. Anda juga bisa membuat nya lebih sempurna.
Berikut adalah coding dari cara membuat drone pada java :
package org.yourorghere; import com.sun.opengl.util.Animator; import java.awt.Frame; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.media.opengl.GL; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLCanvas; import javax.media.opengl.GLEventListener; import javax.media.opengl.glu.GLU; /** * Transformasi.java <BR> * author: Brian Paul (converted to Java by Ron Cemer and Sven Goethel) <P> * * This version is equal to Brian Paul's version 1.2 1999/10/21 */ public class Transformasi implements GLEventListener { public static void main(String[] args) { Frame frame = new Frame("Simple JOGL Application"); GLCanvas canvas = new GLCanvas(); canvas.addGLEventListener(new Transformasi()); frame.add(canvas); frame.setSize(640, 480); final Animator animator = new Animator(canvas); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { // Run this on another thread than the AWT event queue to // make sure the call to Animator.stop() completes before // exiting new Thread(new Runnable() { public void run() { animator.stop(); System.exit(0); } }).start(); } }); // Center frame frame.setLocationRelativeTo(null); frame.setVisible(true); animator.start(); } public void init(GLAutoDrawable drawable) { // Use debug pipeline // drawable.setGL(new DebugGL(drawable.getGL())); GL gl = drawable.getGL(); System.err.println("INIT GL IS: " + gl.getClass().getName()); // Enable VSync gl.setSwapInterval(1); // Setup the drawing area and shading mode gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); gl.glShadeModel(GL.GL_SMOOTH); // try setting this to GL_FLAT and see what happens. } public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { GL gl = drawable.getGL(); GLU glu = new GLU(); if (height <= 0) { // avoid a divide by zero error! height = 1; } final float h = (float) width / (float) height; gl.glViewport(0, 0, width, height); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); glu.gluPerspective(45.0f, h, 1.0, 20.0); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); } public void kotak(GL gl){ gl.glBegin(GL.GL_QUADS); gl.glColor3d(1,0,1); gl.glVertex3d(-2,0,-2); gl.glVertex3d(2,0,-2); gl.glVertex3d(2,0,2); gl.glVertex3d(-2,0,2); gl.glEnd(); } public void tiang(GL gl){ gl.glBegin(GL.GL_TRIANGLES); gl.glColor3d(0,0,1); gl.glVertex3d(-0.5, 0, 0); gl.glVertex3d(0, 1.5, 0); gl.glVertex3d(0.5, 0, 0); gl.glEnd(); } public void kincir(GL gl){ gl.glBegin(GL.GL_TRIANGLES); gl.glColor3d(0,1,1); gl.glVertex3d(-1, 1.5, -0.5); gl.glVertex3d(-1, 1.5, 0.5); gl.glVertex3d(0, 1.5, 0); gl.glVertex3d(0, 1.5, 0); gl.glVertex3d(1, 1.5, -0.5); gl.glVertex3d(1, 1.5, 0.5); gl.glEnd(); } static double sudut =0; static double sudutPlus=0; static double sudutMinus=0; public void display(GLAutoDrawable drawable) { GL gl = drawable.getGL(); // Clear the drawing area gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity(); // Move the "drawing cursor" around sudut -=0.25; sudutPlus +=1.5; sudutMinus -=1.5; gl.glTranslated(0, -0.5, -4); gl.glRotated(sudut,0,1,0); kotak(gl); gl.glTranslated(-1.5, 0, -2); tiang(gl); gl.glRotated(sudutPlus,0,1,0); kincir(gl); gl.glRotated(sudutMinus, 0,1,0); gl.glTranslated(3,0,0); // gl.glBegin(GL.GL_LINES); // gl.glVertex3d(0, 0, 0); // gl.glVertex3d(4,0,0); // gl.glEnd(); // // gl.glBegin(GL.GL_LINES); // gl.glVertex3d(0, 0, 0); // gl.glVertex3d(0,4,0); // gl.glEnd(); // // gl.glBegin(GL.GL_LINES); // gl.glVertex3d(0, 0, 0); // gl.glVertex3d(0,0,4); // gl.glEnd(); // // int sudut=0; // sudut += 1; // gl.glRotated(sudut,0,0,1); // // gl.glBegin(GL.GL_TRIANGLES); // gl.glColor3d(0,0,1); // gl.glVertex3d(0,2,0); // gl.glVertex3d(2,0,0); // gl.glVertex3d(0,0,0); // gl.glEnd(); // // Flush all drawing operations to the graphics card gl.glFlush(); } public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { } }
PENAMPAKAN PROGRAM JIKA DIJALANKAN
0 komentar untuk Contoh Coding Membuat Drone/Baling-Baling Pemrograman Grafis pada Java.
Perlihatkan Semua Komentar Tutup Semua Komentar