This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

Tuesday, May 19, 2020

Membuat Event Heading serta tulisan dengn objek berbentuk P tidak sempurna menggunakan OpenGL

halo kawan-kawan, ksli ini saya berbagai ilmu lagi yaitu Membuat Event Heading serta tulisan dengn objek berbentuk P tidak sempurna menggunakan OpenGL.

berikut tools modul tambhan untuk membuatnya selain OpnGL,

pip install OpenGLContext
pip install PyVRML97
pip install pillow

berikut source codenya

from OpenGLContext import testingcontext
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *

# Koordinat x dan y untuk posisi kotak
pos_x = 0
pos_y = 0

# Warna Kotak
merah = 0
hijau = 0
biru = 0

# Warna Teks
teks_merah = 1
teks_hijau = 1
teks_biru = 1

# Teks Warna Objek
warna_objek = "Hitam"

# Teks Warna Background
warna_background = "Hitam"


def init():
    glClearColor(0.0, 0.0, 0.0, 1.0)
    gluOrtho2D(-500.0, 500.0, -500.0, 500.0)

def drawBitmapText(string,x,y,z) :
    glRasterPos3f(x,y,z)
    for c in string :
        glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,ord(c))

def reshape(w, h):
    glViewport(0,0,w,h)
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    gluOrtho2D(0,w,h,0)
    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()

def drawText():
    glColor3f(teks_merah,teks_hijau,teks_biru)
    drawBitmapText("Warna",-460,-350,0)
    drawBitmapText("Objek : " + warna_objek,-460,-400,0)
    drawBitmapText("Backgorund : " + warna_background ,-460,-450,0)
   
   

# Membuat P tidak sempurna
def kotak():
    global pos_x, pos_y
    glColor3f(merah,hijau,biru)
   
    glBegin(GL_LINE_STRIP)
 #koordinat membuat P tak sempurna
    glVertex2f(50 + pos_x,-250 + pos_y)

    glVertex2f(-50 + pos_x,-250 + pos_y)

    glVertex2f(-50 + pos_x,250 + pos_y)

    glVertex2f(250 + pos_x,250 + pos_y)

    glVertex2f(250 + pos_x,0 + pos_y)  

    glVertex2f(50 + pos_x,0 + pos_y)

    glVertex2f(50 + pos_x,-250 + pos_y)


    glEnd()


def display():
    glClear(GL_COLOR_BUFFER_BIT)

    drawText();

    glColor3f(1.0,1.0,1.0)
    glBegin(GL_LINES)
    glVertex2f(-500.0, 0.0)
    glVertex2f(500.0, 0.0)
    glVertex2f(0.0, 500.0)
    glVertex2f(0.0, -500.0)
    glEnd()


   
    glPushMatrix()
    kotak()
    glPopMatrix()



    glFlush()

def input_mouse(button, state, x, y):
    global merah, hijau, biru
    global warna_objek
   
    # Saat mengklik kanan warna kotak akan berubah menjadi warna hijau dan biru
    if button == GLUT_RIGHT_BUTTON and state == GLUT_DOWN:
        if hijau < 1:
            merah = 0
            hijau = 1
            biru = 0
            warna_objek = "Hijau"
        elif biru < 1:
            merah = 0
            hijau = 0
            biru = 1
            warna_objek = "Biru"
        print("Klik Kanan ditekan ", "(", x, ",", y, ")")
     # Saat mengklik kiri warna kotak akan berubah menjadi warna merah dan hitam
    elif button == GLUT_LEFT_BUTTON and state == GLUT_DOWN:
        if merah < 1:
            merah = 1
            hijau = 0
            biru = 0
            warna_objek = "Merah"
        else:
            merah = 0
            hijau = 0
            biru = 0
            warna_objek = "Hitam"
           
        print("Klik Kiri ditekan ", "(", x, ",", y, ")")

def input_keyboard(key,x,y):
    global pos_x, pos_y
    global warna_background
    global teks_merah, teks_hijau, teks_biru

    # Untuk mengubah posisi kotak

    if key == GLUT_KEY_UP:
        pos_y += 5
        print("Tombol Atas ditekan ", "x : ", pos_x, " y : ", pos_y)
    elif key == GLUT_KEY_DOWN:
        pos_y -= 5
        print("Tombol Bawah ditekan ", "x : ", pos_x, " y : ", pos_y)
    elif key == GLUT_KEY_RIGHT:
        pos_x += 5
        print("Tombol Kanan ditekan ", "x : ", pos_x, " y : ", pos_y)
    elif key == GLUT_KEY_LEFT:
        pos_x -= 5
        print("Tombol Kiri ditekan ", "x : ", pos_x, " y : ", pos_y)

    # Untuk Mengubah Warna backgorund window
   
    # Background Kiri Atas berubah warna menjadi Merah
    if pos_x < 0 and pos_y > 0:
        glClearColor(1.0, 0.0, 0.0, 1.0)
        warna_background = "Merah"

        teks_merah = 0
        teks_hijau = 0
        teks_biru = 0

    # Background Kanan Atas berubah warna menjadi Hijau
    if pos_x > 0 and pos_y > 0:
        glClearColor(0.0, 1.0, 0.0, 1.0)
        warna_background = "Hijau"

        teks_merah = 0
        teks_hijau = 0
        teks_biru = 0

    # Background Kanan Bawah berubah warna menjadi Biru
    if pos_x > 0 and pos_y < 0:
        glClearColor(0.0,0.0,1.0,1.0)
        warna_background = "Biru"

        teks_merah = 1
        teks_hijau = 1
        teks_biru = 1

    # Background Kiri Bawah berubah warna menjadi Hitam
    if pos_x < 0 and pos_y < 0:
        glClearColor(0.0,0.0,0.0,1.0)
        warna_background = "Hitam"

        teks_merah = 1
        teks_hijau = 1
        teks_biru = 1
       

   

def update(value):
    glutPostRedisplay()
    glutTimerFunc(10,update,0)

def main():
    glutInit(sys.argv)
    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB)
    glutInitWindowSize(500,500)
    glutInitWindowPosition(100,100)
    glutCreateWindow("Tugas 9 Event Handling Mouse & keyboard, Font text")

    glutDisplayFunc(display)


    glutSpecialFunc(input_keyboard)
    glutMouseFunc(input_mouse)

    glutTimerFunc(50, update, 0)

   

    init()
    glutMainLoop()
   
main()

disana sudah ada penjelasan dari codenya
dan berikut adalah outputnya

 

 

 sekian dan terima kasih



Share:

Tuesday, May 12, 2020

Membuat event heading dengan tambahan karakter bitmap pada openGL

kali ini saya kembali lagi berbagi ilmu tentang membuat event heading di openGL dengan tambahan karakter bitmap, yaitu tambbahan berupa tulisan untuk bisa melakukannya openGL membutuhkan modul baru atau instal modul diantaranya

pip install OpenGLContext
pip install PyVRML97
pip install pillow

berikut adalah source codenya

from OpenGLContext import testingcontext
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *

# Koordinat x dan y untuk posisi kotak
pos_x = 0
pos_y = 0

# Warna Kotak
merah = 0
hijau = 0
biru = 0

# Warna Teks
teks_merah = 1
teks_hijau = 1
teks_biru = 1

# Teks Warna Objek
warna_objek = "Hitam"

# Teks Warna Background
warna_background = "Hitam"


def init():
    glClearColor(0.0, 0.0, 0.0, 1.0)
    gluOrtho2D(-500.0, 500.0, -500.0, 500.0)

def drawBitmapText(string,x,y,z) :
    glRasterPos3f(x,y,z)
    for c in string :
        glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,ord(c))

def reshape(w, h):
    glViewport(0,0,w,h)
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    gluOrtho2D(0,w,h,0)
    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()

def drawText():
    glColor3f(teks_merah,teks_hijau,teks_biru)
    drawBitmapText("Warna",-460,-350,0)
    drawBitmapText("Objek : " + warna_objek,-460,-400,0)
    drawBitmapText("Backgorund : " + warna_background ,-460,-450,0)
   
   

# Membuat bentuk kotak
def kotak():
    global pos_x, pos_y
    glColor3f(merah,hijau,biru)
   
    glBegin(GL_POLYGON)
    # Kiri Atas
    glVertex2f(-50 + pos_x,-50 + pos_y)
    # Kanan Atas
    glVertex2f(50 + pos_x,-50 + pos_y)
    # Kanan Bawah
    glVertex2f(50 + pos_x,50 + pos_y)
    # Kiri Bawah
    glVertex2f(-50 + pos_x,50 + pos_y)
    glEnd()


def display():
    glClear(GL_COLOR_BUFFER_BIT)

    drawText();

    glColor3f(1.0,1.0,1.0)
    glBegin(GL_LINES)
    glVertex2f(-500.0, 0.0)
    glVertex2f(500.0, 0.0)
    glVertex2f(0.0, 500.0)
    glVertex2f(0.0, -500.0)
    glEnd()


   
    glPushMatrix()
    kotak()
    glPopMatrix()



    glFlush()

def input_mouse(button, state, x, y):
    global merah, hijau, biru
    global warna_objek
   
    # Saat mengklik kanan warna kotak akan berubah menjadi warna hijau dan biru
    if button == GLUT_RIGHT_BUTTON and state == GLUT_DOWN:
        if hijau < 1:
            merah = 0
            hijau = 1
            biru = 0
            warna_objek = "Hijau"
        elif biru < 1:
            merah = 0
            hijau = 0
            biru = 1
            warna_objek = "Biru"
        print("Klik Kanan ditekan ", "(", x, ",", y, ")")
     # Saat mengklik kiri warna kotak akan berubah menjadi warna merah dan hitam
    elif button == GLUT_LEFT_BUTTON and state == GLUT_DOWN:
        if merah < 1:
            merah = 1
            hijau = 0
            biru = 0
            warna_objek = "Merah"
        else:
            merah = 0
            hijau = 0
            biru = 0
            warna_objek = "Hitam"
           
        print("Klik Kiri ditekan ", "(", x, ",", y, ")")

def input_keyboard(key,x,y):
    global pos_x, pos_y
    global warna_background
    global teks_merah, teks_hijau, teks_biru

    # Untuk mengubah posisi kotak

    if key == GLUT_KEY_UP:
        pos_y += 5
        print("Tombol Atas ditekan ", "x : ", pos_x, " y : ", pos_y)
    elif key == GLUT_KEY_DOWN:
        pos_y -= 5
        print("Tombol Bawah ditekan ", "x : ", pos_x, " y : ", pos_y)
    elif key == GLUT_KEY_RIGHT:
        pos_x += 5
        print("Tombol Kanan ditekan ", "x : ", pos_x, " y : ", pos_y)
    elif key == GLUT_KEY_LEFT:
        pos_x -= 5
        print("Tombol Kiri ditekan ", "x : ", pos_x, " y : ", pos_y)

    # Untuk Mengubah Warna backgorund window
   
    # Background Kiri Atas berubah warna menjadi Merah
    if pos_x < 0 and pos_y > 0:
        glClearColor(1.0, 0.0, 0.0, 1.0)
        warna_background = "Merah"

        teks_merah = 0
        teks_hijau = 0
        teks_biru = 0

    # Background Kanan Atas berubah warna menjadi Hijau
    if pos_x > 0 and pos_y > 0:
        glClearColor(0.0, 1.0, 0.0, 1.0)
        warna_background = "Hijau"

        teks_merah = 0
        teks_hijau = 0
        teks_biru = 0

    # Background Kanan Bawah berubah warna menjadi Biru
    if pos_x > 0 and pos_y < 0:
        glClearColor(0.0,0.0,1.0,1.0)
        warna_background = "Biru"

        teks_merah = 1
        teks_hijau = 1
        teks_biru = 1

    # Background Kiri Bawah berubah warna menjadi Hitam
    if pos_x < 0 and pos_y < 0:
        glClearColor(0.0,0.0,0.0,1.0)
        warna_background = "Hitam"

        teks_merah = 1
        teks_hijau = 1
        teks_biru = 1
       

   

def update(value):
    glutPostRedisplay()
    glutTimerFunc(10,update,0)

def main():
    glutInit(sys.argv)
    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB)
    glutInitWindowSize(500,500)
    glutInitWindowPosition(100,100)
    glutCreateWindow("Tugas 9 Event Handling Mouse & keyboard, Font text")

    glutDisplayFunc(display)


    glutSpecialFunc(input_keyboard)
    glutMouseFunc(input_mouse)

    glutTimerFunc(50, update, 0)

   

    init()
    glutMainLoop()
   
main()

dan ini oututnya





SDemikian sedikit ilmu dari saya terrima kasih











Share:

Wednesday, May 6, 2020

Membuat Event Heading dengan OpenGL

Halo kawan-kawan saya berniat berbagi ilmu lagi dengan kalian tentang Membuat Event Heading dengan OpenGL. sebelum kita mylai tentunya kita harus tau Event Heading itu apa. Event Heading adalah fungsi di OpenGL yang menyediakan fungsi yang didefinisikan oleh user dan dipanggil pada saat ada event yang bersesuaian. OpenGL memonitor peralatan input, ketika ada sesuatu yang terjadi, misalkan saat mouse down, keypress, dan lain-lain.
Berikut adalah souce codenya

from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *

# Koordinat x dan y untuk posisi kotak
pos_x = 0
pos_y = 0

# Warna Kotak
merah = 0
hijau = 0
biru = 0


def init():
    glClearColor(0.0, 0.0, 0.0, 1.0)
    gluOrtho2D(-500.0, 500.0, -500.0, 500.0)

def kotak():
    global pos_x, pos_y
    glColor3f(merah,hijau,biru)
   
    glBegin(GL_POLYGON)
    # kuadran 1
    glVertex2f(50 + pos_x,-50 + pos_y)
    # kuadran 2
    glVertex2f(-50 + pos_x,-50 + pos_y)
    # kuadran 3
    glVertex2f(-50 + pos_x,50 + pos_y)
    # kuadran 4
    glVertex2f(50 + pos_x,50 + pos_y)
    glEnd()


def display():
    glClear(GL_COLOR_BUFFER_BIT)
    glColor3f(1.,1.0,1.0)
    glBegin(GL_LINES)
    glVertex2f(-500.0, 0.0)
    glVertex2f(500.0, 0.0)
    glVertex2f(0.0, 500.0)
    glVertex2f(0.0, -500.0)
    glEnd()

    glPushMatrix()
    kotak()
    glPopMatrix()


    glFlush()

def input_mouse(button, state, x, y):
    global merah, hijau, biru
    if button == GLUT_RIGHT_BUTTON and state == GLUT_DOWN:
        if hijau < 1:
            merah = 0
            hijau = 1
            biru = 0
        elif biru < 1:
            merah = 0
            hijau = 0
            biru = 1
        print("Klik Kanan ditekan ", "(", x, ",", y, ")")
    elif button == GLUT_LEFT_BUTTON and state == GLUT_DOWN:
        if merah < 1:
            merah = 1
            hijau = 0
            biru = 0
        else:
            merah = 0
            hijau = 0
            biru = 0
        print("Klik Kiri ditekan ", "(", x, ",", y, ")")

def input_keyboard(key,x,y):
    global pos_x, pos_y

    #disini algoritma untuk menentukan bachround tiap kuadran

       # Background kuadran 1 berubah warna menjadi Hijau
    if pos_x > 0 and pos_y > 0:
        glClearColor(0.0, 1.0, 0.0, 1.0)
       
    # Background kuadran 2 berubah warna menjadi Merah
    if pos_x < 0 and pos_y > 0:
        glClearColor(1.0, 0.0, 0.0, 1.0)

    # Background kuadran 3 berubah warna menjadi biru muda
    if pos_x < 0 and pos_y < 0:
        glClearColor(0.0,0.0,0.0,0.0)


    # Background kuadran 4 berubah warna menjadi Biru
    if pos_x > 0 and pos_y < 0:
        glClearColor(0.0,0.0,1.0,1.0)


#disini adalah algoritma untuk mengubah posisi kotak
    if key == GLUT_KEY_UP:
        pos_y += 5
        print("Tombol Atas ditekan ", "x : ", pos_x, " y : ", pos_y)
    elif key == GLUT_KEY_DOWN:
        pos_y -= 5
        print("Tombol Bawah ditekan ", "x : ", pos_x, " y : ", pos_y)
    elif key == GLUT_KEY_RIGHT:
        pos_x += 5
        print("Tombol Kanan ditekan ", "x : ", pos_x, " y : ", pos_y)
    elif key == GLUT_KEY_LEFT:
        pos_x -= 5
        print("Tombol Kiri ditekan ", "x : ", pos_x, " y : ", pos_y)


   

def update(value):
    glutPostRedisplay()
    glutTimerFunc(10,update,0)

def main():
    glutInit(sys.argv)
    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB)
    glutInitWindowSize(500,500)
    glutInitWindowPosition(100,100)
    glutCreateWindow("Event handling")
    glutDisplayFunc(display)

    glutSpecialFunc(input_keyboard)
    glutMouseFunc(input_mouse)

    glutTimerFunc(50, update, 0)

   

    init()
    glutMainLoop()
   
main()
 dan di situ telah terdapat beberapa penjelasan programnya

Berikut outputnya 
















Share:

Definition List

Unordered List

Support