Using Graph

You can share your experience with HMG. Share with some screenshots/project details so that others will also be benefited.

Moderator: Rathinagiri

User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Using Graph

Post by esgici »

Good work :)

Thanks to sharing, friend :)

Regards

--

Esgici
Viva INTERNATIONAL HMG :D
User avatar
nguyenchiduc
Posts: 78
Joined: Sat Nov 13, 2010 7:27 am

Re: Using Graph

Post by nguyenchiduc »

Image

Code: Select all

#include "hmg.ch"

function main

	define window mathematica at 0,0 ;
		width 800 ;
		height 600 ;
		title "Shapes Demo" ;
		main on init drawshapes()
   	end window

	mathematica.center

	mathematica.activate

return nil

function drawshapes
   LOCAL x1 := 0 , y1:= 0 , x2 := 0 , y2:= 0 , i := 0, j := 0      
   
   /* Truc X - TRUC Y */
   
   draw line in window mathematica at 500,0 to 500,800 pencolor {0,0,0} penwidth 2
   draw line in window mathematica at 0,400 to 600,400 pencolor {0,0,0} penwidth 2
   
   /* HINH HOP */ 
      
   draw line in window mathematica at 50,50 to 50,150 pencolor {0,0,0} penwidth 2
   draw line in window mathematica at 100,50 to 100,150 pencolor {0,0,0} penwidth 2
   draw line in window mathematica at 100,50 to 50,50 pencolor {0,0,0} penwidth 2
   draw line in window mathematica at 100,150 to 50,150 pencolor {0,0,0} penwidth 2
   
   draw line in window mathematica at 30,70 to 30,170 pencolor {0,0,0} penwidth 2
   draw line in window mathematica at 50,50 to 30,70 pencolor {0,0,0} penwidth 2
   draw line in window mathematica at 50,150 to 30,170 pencolor {0,0,0} penwidth 2
   
   draw line in window mathematica at 30,170 to 70,170 pencolor {0,0,0} penwidth 2
   draw line in window mathematica at 100,150 to 70,170 pencolor {0,0,0} penwidth 2
        
   /* HINH HOP CO HINH CHIEU */
   
   draw line in window mathematica at 150,50 to 150,150 pencolor {0,0,0} penwidth 2
   draw line in window mathematica at 200,50 to 200,150 pencolor {0,0,0} penwidth 2
   draw line in window mathematica at 200,50 to 150,50 pencolor {0,0,0} penwidth 2
   draw line in window mathematica at 200,150 to 150,150 pencolor {0,0,0} penwidth 2
   
   draw line in window mathematica at 130,70 to 130,170 pencolor {0,0,0} penwidth 2
   draw line in window mathematica at 150,50 to 130,70 pencolor {0,0,0} penwidth 2
   draw line in window mathematica at 150,150 to 130,170 pencolor {0,0,0} penwidth 2
   
   draw line in window mathematica at 130,170 to 170,170 pencolor {0,0,0} penwidth 2
   draw line in window mathematica at 200,150 to 170,170 pencolor {0,0,0} penwidth 2
   
   i:= 130
   
   DO WHILE i < 170
    draw line in window mathematica at i,70 to i+1,70 pencolor {0,0,0} penwidth 1
    i := i + 3
   ENDDO
   
   i:= 70
   
   DO WHILE i < 170
    draw line in window mathematica at 170,i to 170,i+1 pencolor {0,0,0} penwidth 1
    i := i + 3
   ENDDO
   
   i:= 200
   j:= 50
   
   DO WHILE j < 70
    draw line in window mathematica at i,j to i-1,j+1 pencolor {0,0,0} penwidth 1
    j := j + 2
    i := (i - 3)
   ENDDO
   
   /* TO MAU - COLOR OUT*/
   
   draw line in window mathematica at 250,50 to 250,150 pencolor {0,0,0} penwidth 2
   draw line in window mathematica at 300,50 to 300,150 pencolor {0,0,0} penwidth 2
   draw line in window mathematica at 300,50 to 250,50 pencolor {0,0,0} penwidth 2
   draw line in window mathematica at 300,150 to 250,150 pencolor {0,0,0} penwidth 2
   
   draw line in window mathematica at 230,70 to 230,170 pencolor {0,0,0} penwidth 2
   draw line in window mathematica at 250,50 to 230,70 pencolor {0,0,0} penwidth 2
   draw line in window mathematica at 250,150 to 230,170 pencolor {0,0,0} penwidth 2
   
   draw line in window mathematica at 230,170 to 270,170 pencolor {0,0,0} penwidth 2
   draw line in window mathematica at 300,150 to 270,170 pencolor {0,0,0} penwidth 2
   
   FOR i :=250 to 300
    draw line in window mathematica at i,50 to i,150 pencolor {255,0,0} penwidth 1
   ENDFOR
    
   j := 0   
   FOR i := 230 to 250
    draw line in window mathematica at i,70-j to i,170-j pencolor {0,0,255} penwidth 1
    j := j + 1
   ENDFOR
   
   i := 0   
   FOR j := 150 to 170
    draw line in window mathematica at 300-i,j to 250-i,j pencolor {255,113,255} penwidth 1
    i := i + 1
   ENDFOR
   
   /* NHIN VAO BEN TRONG - COLOR IN */
   
   draw line in window mathematica at 350,50 to 350,150 pencolor {0,0,0} penwidth 2
   draw line in window mathematica at 400,50 to 400,150 pencolor {0,0,0} penwidth 2
   draw line in window mathematica at 400,50 to 350,50 pencolor {0,0,0} penwidth 2
   draw line in window mathematica at 400,150 to 350,150 pencolor {0,0,0} penwidth 2
   
   draw line in window mathematica at 330,70 to 330,170 pencolor {0,0,0} penwidth 2
   draw line in window mathematica at 350,50 to 330,70 pencolor {0,0,0} penwidth 2
   draw line in window mathematica at 350,150 to 330,170 pencolor {0,0,0} penwidth 2
   
   draw line in window mathematica at 330,170 to 370,170 pencolor {0,0,0} penwidth 2
   draw line in window mathematica at 400,150 to 370,170 pencolor {0,0,0} penwidth 2
    
   i := 0   
   FOR j := 50 to 70
    draw line in window mathematica at 400-i,j to 350-i,j pencolor {255,113,255} penwidth 1
    i := i + 1
   ENDFOR   

  FOR i := 330 to 380
    draw line in window mathematica at i,70 to i,170 pencolor {255,0,0} penwidth 1
  ENDFOR    
   
   j := 0   
   FOR i := 330 to 350
    draw line in window mathematica at i,70-j to i,170-j pencolor {0,0,255} penwidth 1
    j := j + 1
   ENDFOR
   
   j := 0   
   FOR i := 380 to 400
    draw line in window mathematica at i,70-j to i,170-j pencolor {0,0,255} penwidth 1
    j := j + 1
   ENDFOR 
        

   i := 0   
   FOR j := 150 to 170
    draw line in window mathematica at 400-i,j to 350-i,j pencolor {255,113,255} penwidth 1
    i := i + 1
   ENDFOR
   
   FOR i := 400 to 450
    draw line in window mathematica at i,50 to i,150 pencolor {255,0,0} penwidth 1
   ENDFOR      

return nil
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Using Graph

Post by Rathinagiri »

Really nice. This would be great if we create a User Defined Function to draw cube/sphere etc., by passing on size and window parameters. :)
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
nguyenchiduc
Posts: 78
Joined: Sat Nov 13, 2010 7:27 am

Re: Using Graph

Post by nguyenchiduc »

motion of the face

Copy and run => fun :lol:

Image

Code: Select all

#include "hmg.ch"

FUNCTION MAIN

	define window math at 0,0 width 800 height 600 ;
    BACKCOLOR {235,235,235}   ;
    title "Shapes Demo"       ;
    main                      ;
    on init draw()            
 	  ON KEY ESCAPE ACTION quit 
  end window
	
  math.center
	math.activate

RETURN NIL

function draw
  LOCAL i := 0 , time := 0
  draw line in window math at 0,400 to 600,400 pencolor {0,0,0} penwidth 1
  draw ellipse in window math at i,300 to 100+i,400 pencolor {255,0,0} penwidth 2 fillcolor {0,0,255}  
  
  /* DRAW FACE */ 
  
  draw ellipse in window math at i+50,330 to i+60,340 pencolor {255,255,255} penwidth 2 fillcolor {255,255,255}
  draw ellipse in window math at i+50,380 to i+60,390 pencolor {255,255,255} penwidth 2 fillcolor {255,255,255}
  draw line in window math at i+60,360 to i+80,360 pencolor {255,255,255} penwidth 3
  draw line in window math at i+90,350 to i+90,370 pencolor {255,255,255} penwidth 3
  
  /* DRAW HMG */ 
  
  draw line in window math at i+20,330 to i+40,330 pencolor {255,255,255} penwidth 3    
  draw line in window math at i+30,330 to i+30,340 pencolor {255,255,255} penwidth 3
  draw line in window math at i+20,340 to i+40,340 pencolor {255,255,255} penwidth 3
  
  draw line in window math at i+20,350 to i+40,350 pencolor {255,255,255} penwidth 3
  draw line in window math at i+20,350 to i+40,355 pencolor {255,255,255} penwidth 3
  draw line in window math at i+20,360 to i+40,355 pencolor {255,255,255} penwidth 3
  draw line in window math at i+20,360 to i+40,360 pencolor {255,255,255} penwidth 3
  
  draw line in window math at i+20,370 to i+40,370 pencolor {255,255,255} penwidth 3
  draw line in window math at i+20,370 to i+20,380 pencolor {255,255,255} penwidth 3
  draw line in window math at i+40,370 to i+40,380 pencolor {255,255,255} penwidth 3
  draw line in window math at i+30,380 to i+40,380 pencolor {255,255,255} penwidth 3
  draw line in window math at i+30,375 to i+30,385 pencolor {255,255,255} penwidth 3
  
  
   DO WHILE .T.
    i := 0
    
    DO WHILE .T.
      time := SECONDS()
      DO WHILE (SECONDS() - time) < 0.2
      ENDDO  
    
      draw ellipse in window math at i,300 to 100+i,400 pencolor {235,235,235} penwidth 2 fillcolor {235,235,235}  
      draw ellipse in window math at 10+i,300 to 110+i,400 pencolor {255,0,0} penwidth 2 fillcolor {0,0,255}
  
      /* DRAW FACE */    
  
      draw ellipse in window math at i+50,330 to i+60,340 pencolor {255,255,255} penwidth 2 fillcolor {255,255,255}
      draw ellipse in window math at i+50,380 to i+60,390 pencolor {255,255,255} penwidth 2 fillcolor {255,255,255}
      draw line in window math at i+60,360 to i+80,360 pencolor {255,255,255} penwidth 3
      draw line in window math at i+90,350 to i+90,370 pencolor {255,255,255} penwidth 3
  
      /* DRAW HMG */ 
  
      draw line in window math at i+20,330 to i+40,330 pencolor {255,255,255} penwidth 3    
      draw line in window math at i+30,330 to i+30,340 pencolor {255,255,255} penwidth 3
      draw line in window math at i+20,340 to i+40,340 pencolor {255,255,255} penwidth 3
  
      draw line in window math at i+20,350 to i+40,350 pencolor {255,255,255} penwidth 3
      draw line in window math at i+20,350 to i+40,355 pencolor {255,255,255} penwidth 3
      draw line in window math at i+20,360 to i+40,355 pencolor {255,255,255} penwidth 3
      draw line in window math at i+20,360 to i+40,360 pencolor {255,255,255} penwidth 3
  
      draw line in window math at i+20,370 to i+40,370 pencolor {255,255,255} penwidth 3
      draw line in window math at i+20,370 to i+20,380 pencolor {255,255,255} penwidth 3
      draw line in window math at i+40,370 to i+40,380 pencolor {255,255,255} penwidth 3
      draw line in window math at i+30,380 to i+40,380 pencolor {255,255,255} penwidth 3
      draw line in window math at i+30,375 to i+30,385 pencolor {255,255,255} penwidth 3
    
      IF i > 450
        exit
      ELSE
        i  := i + 10
      ENDIF    
      
    ENDDO
  
    DO WHILE .T.
      time := SECONDS()
      DO WHILE (SECONDS() - time) < 0.2
      ENDDO  

      draw ellipse in window math at 10+i,300 to 110+i,400 pencolor {235,235,235} penwidth 2 fillcolor {235,235,235}
      draw ellipse in window math at i,300 to 100+i,400 pencolor {0,0,255} penwidth 2 fillcolor {255,0,0}  
       
      /* DRAW FACE */    
  
      draw ellipse in window math at i+50,310 to i+60,320 pencolor {255,255,255} penwidth 2 fillcolor {255,255,255}
      draw ellipse in window math at i+50,360 to i+60,370 pencolor {255,255,255} penwidth 2 fillcolor {255,255,255}
      draw line in window math at i+60,340 to i+80,340 pencolor {255,255,255} penwidth 3
      draw line in window math at i+90,330 to i+90,350 pencolor {255,255,255} penwidth 3
  
      /* DRAW HMG */ 
  
      draw line in window math at i+20,310 to i+40,310 pencolor {255,255,255} penwidth 3    
      draw line in window math at i+30,310 to i+30,320 pencolor {255,255,255} penwidth 3
      draw line in window math at i+20,320 to i+40,320 pencolor {255,255,255} penwidth 3
  
      draw line in window math at i+20,330 to i+40,330 pencolor {255,255,255} penwidth 3
      draw line in window math at i+20,330 to i+40,335 pencolor {255,255,255} penwidth 3
      draw line in window math at i+20,340 to i+40,335 pencolor {255,255,255} penwidth 3
      draw line in window math at i+20,340 to i+40,340 pencolor {255,255,255} penwidth 3
  
      draw line in window math at i+20,350 to i+40,350 pencolor {255,255,255} penwidth 3
      draw line in window math at i+20,350 to i+20,360 pencolor {255,255,255} penwidth 3
      draw line in window math at i+40,350 to i+40,360 pencolor {255,255,255} penwidth 3
      draw line in window math at i+30,360 to i+40,360 pencolor {255,255,255} penwidth 3
      draw line in window math at i+30,355 to i+30,365 pencolor {255,255,255} penwidth 3
      
      IF i < 10
        exit
      ELSE
        i  := i - 10
      ENDIF    
      
    ENDDO
  
  ENDDO
  
RETURN NIL
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Using Graph

Post by esgici »

Hi Rathi

DRAW / ERASE / PRINT GRAPH ... commands of HMG (participated by you) is really fantastic :D

Thanks a lot again :)

My only suggestion is: we need a DRAW POINT command ;)

Yes, drawing a line with 1 pixel width and 1 pixel hight will produce a 1 pixel point. But DRAW POINT command will be more convenient, I think.

Regards

--

Esgici
Viva INTERNATIONAL HMG :D
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Using Graph

Post by Rathinagiri »

Thanks Esgici. Yes, let us do that too. :)
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
Post Reply