document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. from OpenGL.GL import *
  2. from OpenGL.GLU import *
  3. from OpenGL.GLUT import *
  4. import math
  5. from math import sin, cos, tan, sqrt
  6.  
  7.  
  8. def init():
  9.     glClearColor(0.0, 0.0, 0.0, 0.0)
  10.     gluOrtho2D(-500.0, 500.0, -500.0, 500.0)
  11.  
  12.  
  13. def plotpoints():
  14.     glClear(GL_COLOR_BUFFER_BIT)
  15.     glColor3f(1, 1.0, 1.0)
  16.     glPointSize(13)
  17.     glBegin(GL_LINES)
  18.     glVertex2f(-500, 0)
  19.     glVertex2f(500, 0)
  20.  
  21.     glVertex2f(0, -500)
  22.     glVertex2f(0, 500)
  23.  
  24.     glEnd()
  25.     heart_shape(0, 0, 20, 100)
  26.     glFlush()
  27.  
  28.  
  29. def heart_shape(x_center, y_center, r, n):
  30.     glBegin(GL_POLYGON)
  31.  
  32.     # Rumus:
  33.     # x = 16 * (sin t) ^ 3
  34.     # y = 13 * cos t - 5 * cos 2t - 2 * cos 3t - cos 4t
  35.  
  36.     # \'t\' adalah sudut, di sini kita menyebutnya \'a\'
  37.     # Kalikan \'i\' dengan \'a\' agar sudut yang didapat tidak bersifat statis
  38.  
  39.     a = (2 * math.pi) / n
  40.     i = 0
  41.  
  42.     while(i < n):
  43.         x = x_center + r * (16 * (sin(i * a) ** 3))
  44.         y = y_center + r * (13 * cos(i * a) - 5 * cos(2 * i * a) - 2 *
  45.                             cos(3 * i * a) - cos(4 * i * a))
  46.  
  47.         glVertex2d(x, y)
  48.  
  49.         i += 1
  50.  
  51.     glEnd()
  52.  
  53.  
  54. def main():
  55.     glutInit(sys.argv)
  56.     glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
  57.     glutInitWindowSize(500, 500)
  58.     glutInitWindowPosition(100, 100)
  59.     glutCreateWindow("Heart Shape")
  60.     glutDisplayFunc(plotpoints)
  61.  
  62.     init()
  63.     glutMainLoop()
  64.  
  65.  
  66. main()
');