Facebook
From nabil13007, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 70
  1. #include <stdio.h>
  2. #include <GL/gl.h>
  3. #include <GL/glut.h>
  4.  
  5. float x=0,y,x2,y2,m,i,j,p;
  6. int dx=0,dy=0,r,k,d;
  7. void display(void)
  8. {
  9.     glClear (GL_COLOR_BUFFER_BIT);
  10.  
  11.     glEnd();
  12.  
  13.     //front wheel
  14.     r=150;
  15.     for(r=r; r>=140; r=r-10)
  16.     {
  17.         y=r;
  18.         x=0;
  19.  
  20.         d = r/10;
  21.         k = d%2;
  22.  
  23.         if(k==0)
  24.         {
  25.             glColor3f (1.0, 1.0, 1.0);
  26.             glBegin(GL_POLYGON);
  27.         }
  28.         else{
  29.             glColor3f (0.0, 0.0, 0.0);
  30.             glBegin(GL_POLYGON);
  31.         }
  32.  
  33.         p=1-r;
  34.         while((x<=y))
  35.         {
  36.             if(p<0)
  37.             {
  38.                 x=x+1;
  39.                 y=y;
  40.                 p=p+(2*x)+1;
  41.             }
  42.             else
  43.             {
  44.                 x=x+1;
  45.                 y=y-1;
  46.                 p=p+(2*x)+1-(2*y);
  47.             }
  48.             glVertex2f (x-300, y-300);
  49.             glVertex2f (y-300, x-300);
  50.             glVertex2f (-x-300, -y-300);
  51.             glVertex2f (-x-300, y-300);
  52.             glVertex2f (x-300, -y-300);
  53.             glVertex2f (y-300, -x-300);
  54.             glVertex2f (-y-300, -x-300);
  55.             glVertex2f (-y-300, x-300);
  56.         }
  57.         glEnd();
  58.     }
  59.  
  60.     //front wheel spikes
  61.     glColor3f (0.0, 0.0, 0.0);
  62.     glBegin(GL_LINES);
  63.  
  64.     glVertex2f (-300, -450);
  65.     glVertex2f (-300, -150);
  66.  
  67.     glVertex2f (-450, -300);
  68.     glVertex2f (-150, -300);
  69.  
  70.     glVertex2f (-375, -225);
  71.     glVertex2f (-225, -375);
  72.  
  73.     glVertex2f (-225, -225);
  74.     glVertex2f (-375, -375);
  75.  
  76.     glEnd();
  77.  
  78.     //front mid point
  79.     r=30;
  80.     y=r;
  81.     x=0;
  82.     glColor3f (0.0, 0.0, 0.0);
  83.     glBegin(GL_POLYGON);
  84.     p=1-r;
  85.     while((x<=y))
  86.     {
  87.         if(p<0)
  88.         {
  89.             x=x+1;
  90.             y=y;
  91.             p=p+(2*x)+1;
  92.         }
  93.         else
  94.         {
  95.             x=x+1;
  96.             y=y-1;
  97.             p=p+(2*x)+1-(2*y);
  98.         }
  99.         glVertex2f (x-300, y-300);
  100.         glVertex2f (y-300, x-300);
  101.         glVertex2f (-x-300, -y-300);
  102.         glVertex2f (-x-300, y-300);
  103.         glVertex2f (x-300, -y-300);
  104.         glVertex2f (y-300, -x-300);
  105.         glVertex2f (-y-300, -x-300);
  106.         glVertex2f (-y-300, x-300);
  107.     }
  108.     glEnd();
  109.     //rear wheel
  110.     r=150;
  111.     for(r=r; r>=140; r=r-10)
  112.     {
  113.         y=r;
  114.         x=0;
  115.  
  116.         d = r/10;
  117.         k = d%2;
  118.  
  119.         if(k==0)
  120.         {
  121.             glColor3f (1.0, 1.0, 1.0);
  122.             glBegin(GL_POLYGON);
  123.         }
  124.         else{
  125.             glColor3f (0.0, 0.0, 0.0);
  126.             glBegin(GL_POLYGON);
  127.         }
  128.  
  129.         p=1-r;
  130.         while((x<=y))
  131.         {
  132.             if(p<0)
  133.             {
  134.                 x=x+1;
  135.                 y=y;
  136.                 p=p+(2*x)+1;
  137.             }
  138.             else
  139.             {
  140.                 x=x+1;
  141.                 y=y-1;
  142.                 p=p+(2*x)+1-(2*y);
  143.             }
  144.             glVertex2f (x+300, y-300);
  145.             glVertex2f (y+300, x-300);
  146.             glVertex2f (-x+300, -y-300);
  147.             glVertex2f (-x+300, y-300);
  148.             glVertex2f (x+300, -y-300);
  149.             glVertex2f (y+300, -x-300);
  150.             glVertex2f (-y+300, -x-300);
  151.             glVertex2f (-y+300, x-300);
  152.         }
  153.         glEnd();
  154.     }
  155.  
  156.     //rear wheel spikes
  157.     glColor3f (0.0, 0.0, 0.0);
  158.     glBegin(GL_LINES);
  159.  
  160.     glVertex2f (300, -450);
  161.     glVertex2f (300, -150);
  162.  
  163.     glVertex2f (450, -300);
  164.     glVertex2f (150, -300);
  165.  
  166.     glVertex2f (375, -225);
  167.     glVertex2f (225, -375);
  168.  
  169.     glVertex2f (225, -225);
  170.     glVertex2f (375, -375);
  171.  
  172.     glEnd();
  173.  
  174.     //rear mid point
  175.     r=30;
  176.     y=r;
  177.     x=0;
  178.     glColor3f (0.0, 0.0, 0.0);
  179.     glBegin(GL_POLYGON);
  180.     p=1-r;
  181.     while((x<=y))
  182.     {
  183.         if(p<0)
  184.         {
  185.             x=x+1;
  186.             y=y;
  187.             p=p+(2*x)+1;
  188.         }
  189.         else
  190.         {
  191.             x=x+1;
  192.             y=y-1;
  193.             p=p+(2*x)+1-(2*y);
  194.         }
  195.         glVertex2f (x+300, y-300);
  196.         glVertex2f (y+300, x-300);
  197.         glVertex2f (-x+300, -y-300);
  198.         glVertex2f (-x+300, y-300);
  199.         glVertex2f (x+300, -y-300);
  200.         glVertex2f (y+300, -x-300);
  201.         glVertex2f (-y+300, -x-300);
  202.         glVertex2f (-y+300, x-300);
  203.     }
  204.     glEnd();
  205.  
  206.     //front rod
  207.     glColor3f (0.0, 0.0, 0.0);
  208.     glBegin(GL_POLYGON);
  209.     glVertex2f (-10, -300);
  210.     glVertex2f (10, -300);
  211.     glVertex2f (-140, 0);
  212.     glVertex2f (-160, 0);
  213.     glEnd();
  214.  
  215.     //seat rod
  216.     glColor3f (0.0, 0.0, 0.0);
  217.     glBegin(GL_POLYGON);
  218.     glVertex2f (-10, -300);
  219.     glVertex2f (10, -300);
  220.     glVertex2f (235, 150);
  221.     glVertex2f (215, 150);
  222.     glEnd();
  223.  
  224.     //paddle
  225.     glColor3f (0.0, 0.0, 0.0);
  226.     glBegin(GL_POLYGON);
  227.     glVertex2f (-10, -200);
  228.     glVertex2f (10, -200);
  229.     glVertex2f (10, -400);
  230.     glVertex2f (-10, -400);
  231.     glEnd();
  232.  
  233.     //upper part
  234.     glColor3f (0.0, 0.0, 0.0);
  235.     glBegin(GL_POLYGON);
  236.     glVertex2f (-30, -200);
  237.     glVertex2f (30, -200);
  238.     glVertex2f (30, -180);
  239.     glVertex2f (-30, -180);
  240.     glEnd();
  241.  
  242.     //lower part
  243.     glColor3f (0.0, 0.0, 0.0);
  244.     glBegin(GL_POLYGON);
  245.     glVertex2f (-30, -400);
  246.     glVertex2f (30, -400);
  247.     glVertex2f (30, -420);
  248.     glVertex2f (-30, -420);
  249.     glEnd();
  250.  
  251.     //chain
  252.     r=60;
  253.     for(r=r; r>=40; r=r-10)
  254.     {
  255.         y=r;
  256.         x=0;
  257.  
  258.         d = r/10;
  259.         k = d%2;
  260.  
  261.         if(k==0)
  262.         {
  263.             glColor3f (0.0, 0.0, 0.0);
  264.             glBegin(GL_POLYGON);
  265.         }
  266.         else{
  267.             glColor3f (1.0, 1.0, 1.0);
  268.             glBegin(GL_POLYGON);
  269.         }
  270.  
  271.         p=1-r;
  272.         while((x<=y))
  273.         {
  274.             if(p<0)
  275.             {
  276.                 x=x+1;
  277.                 y=y;
  278.                 p=p+(2*x)+1;
  279.             }
  280.             else
  281.             {
  282.                 x=x+1;
  283.                 y=y-1;
  284.                 p=p+(2*x)+1-(2*y);
  285.             }
  286.             glVertex2f (x, y-300);
  287.             glVertex2f (y, x-300);
  288.             glVertex2f (-x, -y-300);
  289.             glVertex2f (-x, y-300);
  290.             glVertex2f (x, -y-300);
  291.             glVertex2f (y, -x-300);
  292.             glVertex2f (-y, -x-300);
  293.             glVertex2f (-y, x-300);
  294.         }
  295.         glEnd();
  296.     }
  297.     //back rod
  298.     glColor3f (0.0, 0.0, 0.0);
  299.     glBegin(GL_POLYGON);
  300.     glVertex2f (310, -310);
  301.     glVertex2f (290, -310);
  302.     glVertex2f (140, 0);
  303.     glVertex2f (160, 0);
  304.     glEnd();
  305.  
  306.     //ground rod
  307.     glColor3f (0.0, 0.0, 0.0);
  308.     glBegin(GL_POLYGON);
  309.     glVertex2f (300, -310);
  310.     glVertex2f (300, -290);
  311.     glVertex2f (55, -290);
  312.     glVertex2f (55, -310);
  313.     glEnd();
  314.  
  315.     //upper rod
  316.     glColor3f (0.0, 0.0, 0.0);
  317.     glBegin(GL_POLYGON);
  318.     glVertex2f (140, 0);
  319.     glVertex2f (160, -20);
  320.     glVertex2f (-140, -20);
  321.     glVertex2f (-160, 0);
  322.     glEnd();
  323.  
  324.     //handle rod
  325.     glColor3f (0.0, 0.0, 0.0);
  326.     glBegin(GL_POLYGON);
  327.     glVertex2f (-290, -300);
  328.     glVertex2f (-310, -300);
  329.     glVertex2f (-65, 180);
  330.     glVertex2f (-45, 180);
  331.     glEnd();
  332.  
  333.     //handle
  334.     glColor3f (0.0, 0.0, 0.0);
  335.     glBegin(GL_POLYGON);
  336.     glVertex2f (-65, 180);
  337.     glVertex2f (-45, 180);
  338.     glVertex2f (-115, 230);
  339.     glVertex2f (-135, 230);
  340.     glEnd();
  341.  
  342.     glColor3f (0.0, 0.0, 0.0);
  343.     glBegin(GL_POLYGON);
  344.     glVertex2f (-115, 230);
  345.     glVertex2f (-135, 230);
  346.     glVertex2f (-100, 270);
  347.     glVertex2f (-80, 270);
  348.     glEnd();
  349.  
  350.     glColor3f (0.0, 0.0, 0.0);
  351.     glBegin(GL_POLYGON);
  352.     glVertex2f (-100, 270);
  353.     glVertex2f (-100, 260);
  354.     glVertex2f (-20, 260);
  355.     glVertex2f (-20, 270);
  356.     glEnd();
  357.  
  358.     //seat
  359.     glColor3f (0.0, 0.0, 0.0);
  360.     glBegin(GL_POLYGON);
  361.     glVertex2f (235, 150);
  362.     glVertex2f (215, 150);
  363.     glVertex2f (145, 170);
  364.     glVertex2f (165, 170);
  365.     glEnd();
  366.  
  367.     glColor3f (0.0, 0.0, 0.0);
  368.     glBegin(GL_POLYGON);
  369.     glVertex2f (145, 170);
  370.     glVertex2f (165, 170);
  371.     glVertex2f (185, 180);
  372.     glVertex2f (165, 180);
  373.     glEnd();
  374.  
  375.     glColor3f (0.0, 0.0, 0.0);
  376.     glBegin(GL_POLYGON);
  377.     glVertex2f (165, 180);
  378.     glVertex2f (165, 175);
  379.     glVertex2f (295, 175);
  380.     glVertex2f (295, 180);
  381.     glEnd();
  382.  
  383.     glColor3f (0.0, 0.0, 0.0);
  384.     glBegin(GL_POLYGON);
  385.     glVertex2f (235, 150);
  386.     glVertex2f (215, 150);
  387.     glVertex2f (275, 160);
  388.     glVertex2f (285, 160);
  389.     glEnd();
  390.  
  391.     glColor3f (0.0, 0.0, 0.0);
  392.     glBegin(GL_POLYGON);
  393.     glVertex2f (275, 160);
  394.     glVertex2f (285, 160);
  395.     glVertex2f (300, 170);
  396.     glVertex2f (295, 170);
  397.     glEnd();
  398.  
  399.     glColor3f (0.0, 0.0, 0.0);
  400.     glBegin(GL_POLYGON);
  401.     glVertex2f (300, 170);
  402.     glVertex2f (295, 170);
  403.     glVertex2f (295, 180);
  404.     glVertex2f (285, 180);
  405.     glEnd();
  406.  
  407.     //basket
  408.     glColor3f (0.0, 0.0, 0.0);
  409.     glBegin(GL_POLYGON);
  410.     glVertex2f (-85, 180);
  411.     glVertex2f (-250, 180);
  412.     glVertex2f (-190, 0);
  413.     glVertex2f (-145, 0);
  414.     glEnd();
  415.  
  416.     glColor3f (1.0, 1.0, 1.0);
  417.     glBegin(GL_LINES);
  418.  
  419.     glVertex2f (-168, 180);
  420.     glVertex2f (-168, 0);
  421.  
  422.     glVertex2f (-127, 180);
  423.     glVertex2f (-150, 0);
  424.  
  425.     glVertex2f (-209, 180);
  426.     glVertex2f (-180, 0);
  427.  
  428.     glEnd();
  429.  
  430.     glFlush ();
  431.  
  432. }
  433. void init (void)
  434. {
  435.     glClearColor (1.0, 1.0, 1.0, 1.0);
  436.     glMatrixMode(GL_PROJECTION);
  437.     glLoadIdentity();
  438.     gluOrtho2D(-600.0, 600.0, -600.0, 600.0);
  439. }
  440.  
  441. int main(int argc, char** argv)
  442. {
  443.     glutInit(&argc, argv);
  444.     glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
  445.     glutInitWindowSize (600, 600);
  446.     glutInitWindowPosition (100, 100);
  447.     glutCreateWindow ("171-15-9263");
  448.     init ();
  449.     glutDisplayFunc(display);
  450.     glutMainLoop();
  451.     return 0;
  452. }
  453.