Formulir Kontak

 

Spiral Heart [PYTHON]

Modul yang digunakan :

  • PyOpenGL
  • numpy

Source Code : 

from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
import numpy as np

def init():
    glClearColor(0.00.00.00.0)
    gluOrtho2D(-2.02.0, -2.02.0)

def heart_spiral_object():
    glBegin(GL_LINE_STRIP)
    glColor3f(0.70.00.0)
    x = -1.140

    while(x <= 1.140):
        delta = np.cbrt(x*x) * np.sqrt(x*x) - 4*x*x + 4
        y1 = (np.cbrt(x*x) + np.sqrt(delta)) / 2
        y2 = (np.cbrt(x*x) - np.sqrt(delta)) / 2
        glVertex2f(x, y1)
        glVertex2f(x, y2)
        x += 0.001
    glEnd()

def plotpoints():
    glClear(GL_COLOR_BUFFER_BIT)
    glColor3f(11.01.0)
    glPointSize(15)
    glBegin(GL_LINES)
    glVertex2f(-5000)
    glVertex2f(5000)
    glVertex2f(0, -500)
    glVertex2f(0500)
    glEnd()
    heart_spiral_object()
    glFlush()

def main():
    glutInit(sys.argv)
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
    glutInitWindowSize(500500)
    glutInitWindowPosition(100100)
    glutCreateWindow("Pertemuan 5 - Spiral Heart")
    glutDisplayFunc(plotpoints)
    init()
    glutMainLoop()
main()

Output :


Total comment

Author

kangmasrizqi

0   komentar

Posting Komentar

Cancel Reply