You are on page 1of 16

Algorithm Assignment

Ritajit Majumdar
Mtech 1st semester
Computer Science and Engineering
Class Roll: 1
Exam Roll: 97/CSM/140001
Registration No: 0029169 of 2008-2009
March 26, 2015

Contents
1 Problem 1
1.1 Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.2 Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1
1
2

2 Problem 2
2.1 Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2 Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3
3
4

3 Problem 3
3.1 Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.2 Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4
4
5

4 Problem 4
4.1 Visualization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.2 Remarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

6
6
8

5 Problem 5
8
5.1 Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
5.2 Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
6 Problem 6
10
6.1 Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
6.2 Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

Problem 1

Given n-points in the plane and the sequence of h points, write a program to determine if these h
points are the points generating the convex hull in counter-clockwise order.

1.1

Code

from a s t import l i t e r a l e v a l
def c o n v e x h u l l ( p o i n t s ) :
# sort points lexicographically
# t a k i n g s e t t o remove d u p l i c a t e s
points = sorted ( set ( points ))
i f l e n ( p o i n t s ) <= 1 :
return p o i n t s
# 2d c r o s s p r o d u c t o f OA and OB v e c t o r s
# p o s i t i v e v a l u e i f OAB makes a counter c l o c k w i s e t u r n
# n e g a t i v e f o r c l o c k w i s e turn , z e r o f o r c o l l i n e a r
def c r o s s ( o , a , b ) :
return ( a [0] o [ 0 ] ) ( b [1] o [ 1 ] ) ( a [1] o [ 1 ] ) ( b [0] o [ 0 ] )
# b u i l d upper h u l l
upper = [ ]
for p in r e v e r s e d ( p o i n t s ) :
while l e n ( upper ) >= 2 and c r o s s ( upper [ 2 ] , upper [ 1 ] , p ) <= 0 :
upper . pop ( )
upper . append ( p )
# b u i l d lower h u l l
lower = [ ]
for p in p o i n t s :
while l e n ( l o w e r ) >= 2 and c r o s s ( l o w e r [ 2 ] , l o w e r [ 1 ] , p ) <= 0 :
l o w e r . pop ( )
l o w e r . append ( p )
# c o n c a t e n a t i o n o f l o w e r and upper h u l l
# l a s t p o i n t o f each l i s t i s o m i t t e d b e c a u s e i t i s r e p e a t e d
# at the beginning of other
return l o w e r [ : 1 ] + upper [ : 1 ]
#t o t a k e t h e i n p u t p o i n t s
def g e t c o o r d s ( ) :
print Enter a l i s t o f p o i n t s . For example ( 0 , 0 ) , ( 0 , 1 ) , ( 1 , 1 ) , ( 1 , 0 )
points = raw input ()
try :
return l i s t ( l i t e r a l e v a l ( p o i n t s ) )
except SyntaxError :
1

print The c o o r d i n a t e s s h o u l d be e n t e r e d i n p r e s c r i b e d form


#c o n v e x h u l l ( [ ( i /10 , i %10) f o r i i n range ( 1 0 0 ) ] )
print Enter t he s e t o f n p o i n t s
points = get coords ()
print The p o i n t s you gave a r e
print p o i n t s
hull = convex hull ( points )
print \nThe convex h u l l f o r t he p o i n t s you p r o v i d e d :
print h u l l
print \ nEnter t he h u l l p o i n t s h t o be checked
h = get coords ()
print The p o i n t s you p r o v i d e d as h u l l p o i n t s
print h
i s p r e s e n t = False
i f l e n ( h u l l ) == l e n ( h ) :
i s p r e s e n t = True
for i in range ( l e n ( h u l l ) ) :
i f h [ i ] not in h u l l :
i s p r e s e n t = False
break
i f i s p r e s e n t == True :
print \nThe p o i n t s you p r o v i d e d a r e h u l l p o i n t s \
i n co unt er c l o c k w i s e o r d e r
else :
print \nThe p o i n t s you p r o v i d e d a r e not h u l l p o i n t s \
i n co unt er c l o c k w i s e o r d e r

1.2

Output

A snapshot of the output is attached below.

Problem 2

Write a program for finding the convex hull in two-dimensional space using divide and conquer
strategy.

2.1

Code

from numpy . random import rand


import m a t p l o t l i b . p y p l o t as p l t
from o p e r a t o r import i t e m g e t t e r
from numpy import c o n c a t e n a t e
print The p o i n t s a r e g e n e r a t e d randomly
r a w i n p u t ( P r e s s e n t e r t o g e n e r a t e t he convex h u l l )
p o i n t s = rand ( 5 0 , 2 )
def c r o s s ( o , a , b ) :
return ( a [0] o [ 0 ] ) ( b [1] o [ 1 ] ) ( a [1] o [ 1 ] ) ( b [0] o [ 0 ] )
def mergeHull ( l e f t h u l l , r i g h t h u l l ) :
l p o i n t s = l e f t h u l l . s o r t ( key=i t e m g e t t e r ( 0 ) )
r p o i n t s = r i g h t h u l l . s o r t ( key=i t e m g e t t e r ( 0 ) )
idx1 = l p o i n t s [ len ( l p o i n t s ) ] . index ( )
idx2 = r p o i n t s [ 0 ] . index ( )
while c r o s s ( l p o i n t s [ i d x 2 ] , r p o i n t s [ i d x 1 ] , r p o i n t s [ i d x 1 +1]) <= 0 :
i d x 1 += 1
while c r o s s ( r p o i n t s [ i d x 1 ] , l p o i n t s [ i d x 2 ] , l p o i n t s [ idx2 1]) >= 0 :
i d x 2 = 1
return l p o i n t s [ : i d x 1 ] + r p o i n t s [ i d x 2 : ]
def ConvexHull ( p o i n t s ) :
points = sorted ( set ( points ))
i f l e n ( p o i n t s ) <= 1 :
return p o i n t s
else :
mid = l e n ( p o i n t s )/ 2
l e f t h u l l = ConvexHull ( p o i n t s [ : mid ] )
r i g h t h u l l = ConvexHull ( p o i n t s [ mid : ] )
return mergeHull ( l e f t h u l l , r i g h t h u l l )
h u l l = ConvexHull ( p o i n t s )
plt . plot ( points [ : , 0 ] , points [ : , 1 ] , o )
for s in h u l l . s i m p l i c e s :
p l t . p l o t ( p o i n t s [ s , 0 ] , p o i n t s [ s , 1 ] , k )
p l t . p l o t ( p o i n t s [ h u l l . v e r t i c e s , 0 ] , p o i n t s [ h u l l . v e r t i c e s , 1 ] , r , lw=2)
p l t . p l o t ( points [ h u l l . v e r t i c e s [ 0 ] , 0 ] , points [ h u l l . v e r t i c e s [ 0 ] , 1 ] , ro )
3

p l t . t i t l e ( Convex H u l l )
#p l t . show ( )
p l t . s a v e f i g ( / U s e r s / mindSpace / Desktop / ch . png )

2.2

Output

The previous code is written to plot the points and also show the convex hull of the points. The plot
of the output is attached below.

Problem 3

Implement the divide and conquer closest pair algorithm in language of your choice.

3.1

Code

from math import s q r t , pow


from a s t import l i t e r a l e v a l
def d i s t a n c e ( a , b ) :
return s q r t ( pow ( a [0] b [ 0 ] , 2 ) + pow ( a [1] b [ 1 ] , 2 ) )
def bruteMin ( p o i n t s , c u r r e n t=f l o a t ( i n f ) ) :
4

i f len ( points ) < 2:


return c u r r e n t
else :
head = p o i n t s [ 0 ]
del p o i n t s [ 0 ]
newMin = min ( [ d i s t a n c e ( head , x ) for x in p o i n t s ] )
newCurrent = min ( [ newMin , c u r r e n t ] )
return bruteMin ( p o i n t s , newCurrent )
def divideMin ( p o i n t s ) :
half = len ( sorted ( points ))/2
minimum = min ( [ bruteMin ( p o i n t s [ : h a l f ] ) , bruteMin ( p o i n t s [ h a l f : ] ) ] )
n e a r L i n e = f i l t e r (lambda x : x [ 0 ] > h a l f minimum and \
x [ 0 ] < h a l f + minimum , p o i n t s )
return round ( min ( [ bruteMin ( n e a r L i n e ) , minimum ] ) , 2 )
def g e t c o o r d s ( ) :
print Enter a l i s t o f p o i n t s . \
For example ( 0 , 0 ) , ( 0 , 1 ) , ( 1 , 1 ) , ( 1 , 0 )
points = raw input ()
try :
return l i s t ( l i t e r a l e v a l ( p o i n t s ) )
except SyntaxError :
print The c o o r d i n a t e s s h o u l d be e n t e r e d i n p r e s c r i b e d form

print Enter t he s e t o f n p o i n t s
points = get coords ()
print The p o i n t s you gave a r e
print p o i n t s
minimum = divideMin ( p o i n t s )
print \nThe minimum d i s t a n c e between t he p o i n t s you p r o v i d e d i s
print minimum

3.2

Output

The snapshot of the output is attached below.

Problem 4

Find a visualization of an algorithm for the closest pair problem on the web.

4.1

Visualization

Visualization of closest pair problem is available at the site http://alvie.algoritmica.org/alvie3/


visualizations. This website contains visualization for many algorithms, closest pair being one of
them. However, in the visualization page, the video is not ready for playing. From this page, we
need to go to downloads page http://alvie.algoritmica.org/alvie3/downoads.
In this page, all the videos, which are in .swf format, are available for both viewing and downloading. At the closest pair algorithm, clicking on the view option leads us to the url Visulaization
of closest pair.
The visualization shows all the steps of the algorithm as they occur. It is not possible to give all
the snapshots. So I am only attaching 4 screenshots which will hopefully give an essence of how the
algorithm works.

4.2

Remarks

These screenshots hopefully provides an essence of how the algorithm works and the major steps
of its implementation. Every step is shown in the video. For better understanding, refer to the url
provided.

Problem 5

Implement the maximum flow algorithm in a network with a language of your choice. Consider both
direct and reverse flow direction.

5.1

Code

c l a s s Edge ( o b j e c t ) :
i n i t ( s e l f , u , v ,w ) :
def
s e l f . source = u
s e l f . sink = v
s e l f . capacity = w
def

repr ( self ):
return %s > %s : %s % ( s e l f . s o u r c e , s e l f . s i n k , s e l f . c a p a c i t y )

c l a s s FlowNetwork ( o b j e c t ) :
def
init ( self ):
s e l f . a d j = {}
s e l f . f l o w = {}
def a d d v e r t e x ( s e l f , v e r t e x ) :
8

s e l f . adj [ vertex ] = [ ]
def g e t e d g e s ( s e l f , v ) :
return s e l f . a d j [ v ]
def add edge ( s e l f , u , v ,w=0):
i f u == v :
r a i s e Val ueErro r ( Same v e r t e x . Edge not p o s s i b l e )
edge = Edge ( u , v ,w)
r e d g e = Edge ( v , u , 0 )
edge . r e d g e = r e d g e
r e d g e . r e d g e = edge
s e l f . a d j [ u ] . append ( edge )
s e l f . a d j [ v ] . append ( r e d g e )
s e l f . f l o w [ edge ] = 0
s e l f . flow [ r edge ] = 0
def f i n d p a t h ( s e l f , s o u r c e , s i n k , path ) :
i f s o u r c e == s i n k :
return path
for edge in s e l f . g e t e d g e s ( s o u r c e ) :
r e s i d u a l = edge . c a p a c i t y s e l f . f l o w [ edge ]
i f r e s i d u a l > 0 and edge not in path :
r e s u l t = s e l f . f i n d p a t h ( edge . s i n k , s i n k , path +[ edge ] )
i f r e s u l t != None :
return r e s u l t
def max flow ( s e l f , s o u r c e , s i n k ) :
path = s e l f . f i n d p a t h ( s o u r c e , s i n k , [ ] )
while path != None :
r e s i d u a l s = [ edge . c a p a c i t y s e l f . f l o w [ edge ] for edge in path ]
f l o w = min ( r e s i d u a l s )
for edge in path :
s e l f . f l o w [ edge ] += f l o w
s e l f . f l o w [ edge . r e d g e ] = f l o w
path = s e l f . f i n d p a t h ( s o u r c e , s i n k , [ ] )
return sum ( s e l f . f l o w [ edge ] for edge in s e l f . g e t e d g e s ( s o u r c e ) )

if

name
== m a i n :
g = FlowNetwork ( )
[ g . a d d v e r t e x ( v ) for v in s o p q r t ]
g . add vertex (v)
g . add edge ( s , o , 3 )
g . add edge ( s , p , 3 )
g . add edge ( o , p , 2 )
g . add edge ( o , q , 3 )
g . add edge ( p , r , 2 )
g . add edge ( r , t , 3 )
g . add edge ( q , r , 4 )
9

g . add
print
print
print
print
print
print
print
print
print
print
print
print

5.2

edge ( q , t , 2 )
\nThe graph i s s o p q r t
The s o u r c e i s s and t he s i n k i s t
The f l o w through e d g e s i s :
s o > 3
s p > 3
o p > 2
o q > 3
p r > 2
r t > 3
q r > 4
q t > 2\n
The maximum f l o w through t h i s network i s , g . max flow ( s , t )

Output

The snapshot of the output is attached below.

Problem 6

Write a program that accepts mouse clicks in a window and draws the convex hull of the points
clicked.

6.1

Code

There are two different programs - one to implement the gui and the other to implement the convex
hull

ConvexHull.py
def c o n v e x H u l l ( p o i n t s L i s t ) :
lowerHull = [ ]
upperHull = [ ]
i f l e n ( p o i n t s L i s t ) <= 0 :
10

return p o i n t s L i s t
#have t o s o r t l i s t f i r s t
p o i n t s L i s t . s o r t ( key=lambda tup : tup [ 0 ] )
n = len ( pointsList )
j = 0
#t h e n c a l c u l a t e l o w e r h u l l
for i d x in range ( n ) :
#c h e c k i n g f o r c o u n t e r c l o c k w i s e n e s s
while l e n ( l o w e r H u l l ) >= 2 and \
c r o s s ( l o w e r H u l l [ j 2 ] , l o w e r H u l l [ j 1 ] , p o i n t s L i s t [ i d x ] ) <= 0
l o w e r H u l l . pop ( )
j = 1
l o w e r H u l l . append ( p o i n t s L i s t [ i d x ] )
j += 1

j = 0
idx = n 1
#t h e n upper h u l l from r e v e r s e o f p o i n t s L i s t
for i in range ( n ) :
while l e n ( u p p e r H u l l ) >= 2 and \
c r o s s ( u p p e r H u l l [ j 2 ] , u p p e r H u l l [ j 1 ] , p o i n t s L i s t [ i d x ] ) <= 0
u p p e r H u l l . pop ( )
j = 1
u p p e r H u l l . append ( p o i n t s L i s t [ i d x ] )
i d x = 1
j += 1

#pop l o w e r h u l l b / c i t c o n t a i n s t h e 1 s t p o i n t t h e n combine w i t h upper and r e


l o w e r H u l l . pop ( )
return l o w e r H u l l + u p p e r H u l l
def c r o s s (O, A, B ) :
return (A [ 0 ] O[ 0 ] ) (B [ 1 ] O[ 1 ] ) (A [ 1 ] O[ 1 ] ) (B [ 0 ] O[ 0 ] )

launch.py
import pygame
from pygame . l o c a l s import
from c o n v e x H u l l import c o n v e x H u l l

c l a s s Button :
i n i t ( s e l f , button message , c o o r d i n a t e s ) :
def
s e l f . c a p t i o n = +b u t t o n m e s s a g e
s e l f . b t n w i d t h = 90
s e l f . b t n h e i g h t = 30
s e l f . r e c t = pygame . Rect ( c o o r d i n a t e s [ 0 ] , c o o r d i n a t e s [ 1 ] , s e l f . btn width ,
s e l f . s u r f a c e = pygame . S u r f a c e ( s e l f . r e c t . s i z e )
s e l f . b g c o l o r = pygame . Color ( b l i g h t g r a y )
s e l f . f g c o l o r = pygame . Color ( b b l a c k )
pygame . f o n t . i n i t ( )
11

s e l f . f o n t = pygame . f o n t . Font ( f r e e s a n s b o l d . t t f , 1 4)
s e l f . update ( )

def p r e s s e d ( s e l f , mouse ) :
# i f mouse r i g h t or l e f t i s w i t h i n t h e b u t t o n
i f mouse [ 0 ] > s e l f . r e c t . t o p l e f t [ 0 ] and mouse [ 1 ] > s e l f . r e c t . t o p l e f t [ 1 ] :
i f mouse [ 0 ] < s e l f . r e c t . b o t t o m r i g h t [ 0 ] and mouse [ 1 ] < s e l f . r e c t . b o t
return True
return F a l s e
def draw ( s e l f , d i s p l a y s u r f a c e ) :
display surface . b l i t ( s e l f . surface , s e l f . rect )
def

update ( s e l f ) :
w = s e l f . r e c t . width
h = s e l f . rect . height
# f i l l t h e b u t t o n background
s e l f . surface . f i l l ( s e l f . bg color )
# r e n d e r t h e c a p t i o n and r e t u r n a r e c t a n g l e
c a p t i o n s u r f = s e l f . f o n t . r e n d e r ( s e l f . c a p t i o n , True , s e l f . f g c o l o r , s e l f
caption rect = caption surf . get rect ()
# i n f l a t e i n p l a c e , moves t h e t e x t t o a more p l e a s i n g s p o t i n t h e b u t t o
c a p t i o n r e c t . i n f l a t e i p ( 10 , 17)
# commits t h e c a p t i o n
s e l f . surface . blit ( caption surf , caption rect )

# draw b o r d e r f o r normal b u t t o n
pygame . draw . r e c t ( s e l f . s u r f a c e , pygame . Color ( b b l a c k ) , pygame . Rect ( ( 0 ,
pygame . draw . l i n e ( s e l f . s u r f a c e , pygame . Color ( b white ) , ( 1 , 1 ) , (w 2 ,
pygame . draw . l i n e ( s e l f . s u r f a c e , pygame . Color ( b white ) , ( 1 , 1 ) , ( 1 , h
pygame . draw . l i n e ( s e l f . s u r f a c e , pygame . Color ( b darkgray ) , ( 1 , h 1 ) , (
pygame . draw . l i n e ( s e l f . s u r f a c e , pygame . Color ( b darkgray ) , (w 1 , 1 ) , (
pygame . draw . l i n e ( s e l f . s u r f a c e , pygame . Color ( b gray ) , ( 2 , h 2 ) , (w
pygame . draw . l i n e ( s e l f . s u r f a c e , pygame . Color ( b gray ) , (w 2 , 2 ) , (w

c l a s s App :
init ( self ):
def
s e l f . b u t t o n w i d t h = 20
s e l f . b u t t o n s p a c i n g = 100
self . button offset = 0
s e l f . b u t t o n r i g h t m o s t = 840
s e l f . m s g d i s p l a y t o p l e f t = 2 0 , 25
s e l f . running = True
s e l f . d i s p l a y s u r f = None
s e l f . s i z e = s e l f . weight , s e l f . h e i g h t = 9 6 0 , 720
s e l f . b g c o l o r = None
s e l f . p o i n t c o l o r = None
s e l f . h u l l c o l o r = None
12

s e l f . mouse x , s e l f . mouse y = 0 , 0
s e l f . f o n t o b j = None
s e l f . points = [ ]
s e l f . ch points = [ ]
s e l f . msg = C l i c k p o i n t s then Get H u l l
#s e l f . b t n i n t e r a c t i v e = Button ( I n t e r a c t i v e , ( s e l f . b u t t o n r i g h t m o s t
#s e l f . b u t t o n o f f s e t = s e l f . b u t t o n s p a c i n g
s e l f . b t n r e s e t = Button ( Reset , ( s e l f . b u t t o n r i g h t m o s t s e l f . b u t t o n
s e l f . b u t t o n o f f s e t += s e l f . b u t t o n s p a c i n g
s e l f . b t n g e t c o n v e x = Button ( Get H u l l , ( s e l f . b u t t o n r i g h t m o s t s e l f

def o n i n i t ( s e l f ) :
pygame . i n i t ( )
s e l f . f o n t o b j = pygame . f o n t . Font ( f r e e s a n s b o l d . t t f , 24 )
#s e l f . f o n t o b j = pygame . f o n t . SysFont ( FreeMono . t t f , 24)
s e l f . b g c o l o r = pygame . Color ( 0 , 0 , 0 )
s e l f . p o i n t c o l o r = pygame . Color ( 2 5 5 , 2 5 5 , 255)
s e l f . h u l l c o l o r = pygame . Color ( b re d )
s e l f . d i s p l a y s u r f = pygame . d i s p l a y . set mode ( s e l f . s i z e )
s e l f . d i s p l a y s u r f = pygame . d i s p l a y . set mode ( ( 1 0 2 4 , 6 0 0 ) , HWSURFACE|DOUB
s e l f . running = True
def o n e v e n t ( s e l f , e v e n t ) :
i f e v e n t . type == QUIT :
s e l f . running = F a l s e
e l i f e v e n t . type == MOUSEBUTTONUP and e v e n t . button in ( 1 , 2 , 3 ) :
# i f e v e n t i s b u t t o n , make h u l l or r e s e t s c r e e n , e l s e add t o p o i n t
i f s e l f . b t n g e t c o n v e x . p r e s s e d ( e v e n t . pos ) :
s e l f . msg = Convex H u l l
del s e l f . c h p o i n t s [ : ]
s e l f . c h p o i n t s = convexHull ( s e l f . points )
e l i f s e l f . b t n r e s e t . p r e s s e d ( e v e n t . pos ) :
del s e l f . p o i n t s [ : ]
del s e l f . c h p o i n t s [ : ]
s e l f . msg = C l i c k p o i n t s then Get H u l l
else :
s e l f . p o i n t s . append ( e v e n t . pos )
s e l f . msg = x , y : + s t r ( e v e n t . pos )
def o n l o o p ( s e l f ) :
s e l f . display surf . f i l l ( s e l f . bg color )
s e l f . b t n g e t c o n v e x . draw ( s e l f . d i s p l a y s u r f )
s e l f . b t n r e s e t . draw ( s e l f . d i s p l a y s u r f )
# s e l f . b t n i n t e r a c t i v e . draw ( s e l f . d i s p l a y s u r f )

# draws o u t t h e r e g u l a r c o o r d i n a t e d o t s i f p o p u l a t e d
for coord in s e l f . p o i n t s :
pygame . draw . c i r c l e ( s e l f . d i s p l a y s u r f , s e l f . p o i n t c o l o r , coord , 3 , 0
# draws o u t t h e convex h u l l c o o r d i n a t e d o t s i f p o p u l a t e d
for coord in s e l f . c h p o i n t s :
13

pygame . draw . c i r c l e ( s e l f . d i s p l a y s u r f , s e l f . h u l l c o l o r , coord , 3 , 0 )


# draws t h e e d g e s t o show t h e convex h u l l i f p o p u l a t e d
i f len ( s e l f . ch points ) > 0:
pygame . draw . l i n e s ( s e l f . d i s p l a y s u r f , s e l f . h u l l c o l o r , True , s e l f . c h

# message d i s p l a y window
m s g s u r f a c e o b j = s e l f . f o n t o b j . r e n d e r ( s e l f . msg , F a l s e , s e l f . p o i n t c o l o
msg rect obj = msg surface obj . get rect ()
msg rect obj . topleft = ( s e l f . msg display top left [ 0 ] , s e l f . msg display
s e l f . display surf . b l i t ( msg surface obj , msg rect obj )
def o n r e n d e r ( s e l f ) :
pygame . d i s p l a y . update ( )
def o n c l e a n u p ( s e l f ) :
pygame . q u i t ( )
def e x e c u t e ( s e l f ) :
s e l f . on init ()
while s e l f . running :
for e v e n t in pygame . e v e n t . g e t ( ) :
s e l f . on event ( event )
s e l f . on loop ()
s e l f . on render ()
s e l f . on cleanup ()
if

6.2

name
== m a i n
l e t s g o = App ( )
l e t s g o . execute ()

Output

Two snapshots of the output are provided below.

14

The above snapshot shows how the points are taken as input via mouse click.

In this snapshot we show how clicking the Get Hull button generates the convex hull.s

15

You might also like