
# graphics practice 1
# draw x and o
from pygame import *
screen = display.set_mode((800,600))
GREEN = (0,255,0)
RED = (255,0,0)
BLUE = (0,0,255)
running = True
while running:
for e in event.get():
print(e)
if e.type == QUIT:
running = False
mx,my = mouse.get_pos()
mb = mouse.get_pressed()
if mb[0]:
draw.line(screen,RED,(mx+20,my+20),(mx-20,my-20),2)
draw.line(screen,RED,(mx-20,my+20),(mx+20,my-20),2)
elif mb[2]:
draw.circle(screen,GREEN,(mx,my),20,2)
display.flip()
quit()

# graphics practice 2
# circles in square shape upon click
from pygame import *
screen = display.set_mode((800,600))
GREEN = (0,255,0)
RED = (255,0,0)
BLUE = (0,0,255)
running = True
while running:
for e in event.get():
print(e)
if e.type == QUIT:
running = False
mx,my = mouse.get_pos()
mb = mouse.get_pressed()
if mb[0]:
for i in range(5):
draw.circle(screen, GREEN, (mx - 20 + i * 10, my - 20), 4)
draw.circle(screen, GREEN, (mx - 20 + i * 10, my + 20), 4)
draw.circle(screen, GREEN, (mx - 20, my - 20 + i * 10), 4)
draw.circle(screen, GREEN, (mx + 20, my - 20 + i * 10), 4)
display.flip()
quit()

# graphics practice 3
# fill screen with diagonal lines in opposite directions
from pygame import *
screen = display.set_mode((800,600))
RED = (255,0,0)
GREEN = (0,255,0)
BLUE = (0, 255, 0)
running = True
while running:
# event loop
for e in event.get():
if e.type == QUIT:
running = False
#-----------------------------------------
for i in range(-600,800,10):
draw.line(screen, GREEN, (i,0), (600 + i, 600))
draw.line(screen, GREEN, (i,600), (600 + i, 0))
#----------------------------------------
display.flip()
quit()

# graphics practice 4
# lines crossing eachother across screen
from pygame import *
screen = display.set_mode((800,600))
GREEN = (0,255,0)
RED = (255,0,0)
BLUE = (0,0,255)
running = True
while running:
for e in event.get():
print(e)
if e.type == QUIT:
running = False
mx,my = mouse.get_pos()
mb = mouse.get_pressed()
screen.fill((0,0,0))
draw.line(screen, GREEN, (0,my ), (800,my))
draw.line(screen, GREEN, (mx,0), (mx,600))
display.flip()
quit()

# graphics practice 5
# lines in random colours upon press
from pygame import *
from random import *
screen = display.set_mode((800,600))
GREEN = (0,255,0)
RED = (255,0,0)
BLUE = (0,0,255)
running = True
while running:
for e in event.get():
print(e)
if e.type == QUIT:
running = False
mx,my = mouse.get_pos()
mb = mouse.get_pressed()
col = (randint(0,255)),(randint(0,255)),(randint(0,255))
if mb[0]:
draw.line(screen,col, (mx,my),(800,600))
draw.line(screen,col, (mx,my),(800,0))
draw.line(screen,col, (mx,my),(0,600))
draw.line(screen,col, (mx,my),(0,0))
display.flip()
quit()

# greaphics practice 6
# maze thing
from pygame import *
screen = display.set_mode((800,600))
RED = (255,0,0)
GREEN = (0,255,0)
BLUE = (0, 255, 0)
mouse.set_visible(False)
running = True
while running:
# event loop
for e in event.get():
if e.type == QUIT:
running = False
for off in range(0, 300, 10):
draw.line(screen, GREEN, (400 - off, 300 + off), (400 - off, 300 - off))
draw.line(screen, GREEN, (400 + off, 300 - off), (400+off, 300 + off))
draw.line(screen, GREEN, (400 - off, 300 + off), (400 + off, 300 + off))
draw.line(screen, GREEN, (400 + off, 300 - off), (400 - off, 300 - off))
display.flip()
quit()

# graphics pratice 7
from pygame import *
from random import *
screen = display.set_mode((800,600))
RED = (255, 0, 0)
GREEN = (0, 255, 0)
running = True
while running:
# event loop
for e in event.get():
if e.type == QUIT:
running = False
mx, my = mouse.get_pos()
mb = mouse.get_pressed()
for x in range(0, 800, 10):
cy = 0.004 * (x - 400) ** 2 + 100
for y in range(int(cy), 600, 10):
draw.circle(screen, GREEN, (x,y), 4)
display.flip()
quit()

# graphics practice 8
# lines in random colours upon press
from pygame import *
from random import *
screen = display.set_mode((800,600))
GREEN = (0,255,0)
RED = (255,0,0)
BLUE = (0,0,255)
running = True
while running:
for e in event.get():
print(e)
if e.type == QUIT:
running = False
mx,my = mouse.get_pos()
mb = mouse.get_pressed()
col = (randint(0,255)),(randint(0,255)),(randint(0,255))
if mb[0]:
if mx > 400 and my > 300:
draw.line(screen,col, (mx,my),(800,600))
elif mx > 400 and my < 300:
draw.line(screen,col, (mx,my),(800,0))
elif mx < 400 and my > 300:
draw.line(screen,col, (mx,my),(0,600))
elif mx < 400 and my < 300:
draw.line(screen,col, (mx,my),(0,0))
display.flip()
quit()

#graphics practice 9
from pygame import *
from math import *
'''
d = hypot(x2-x1, y2-y1)
d = dist((x1, y1), (x2, y2))
d = sqrt((x2-x1)**2 + (y2 - y1)**2)
'''
screen = display.set_mode((800,600))
RED = (255,0,0)
GREEN = (0,255,0)
BLUE = (0, 255, 0)
running = True
while running:
for e in event.get():
if e.type == QUIT:
running = False
mx,my= mouse.get_pos()
mb = mouse.get_pressed()
if mb[0]:
col = (randint(0,255),randint(0,255),randint(0,255))
d = hypot(400-mx, 300-my)/ 8
draw.circle(screen,(screen,col,(mx,my), d)
if mb[2]:
screen.fill((0,0,0))
display.flip()
quit()

# graphics 10
from pygame import *
screen = display.set_mode((1000,800))
RED = (255, 0, 0)
GREEN = (0, 255, 0)
running = True
while running:
# event loop
for e in event.get():
if e.type == QUIT:
running = False
mx, my = mouse.get_pos()
mb = mouse.get_pressed()
screen.fill(0)
for i in range(11):
draw.line(screen, GREEN, (i*100, 0), (mx-50+i*10, my-50))
draw.line(screen, GREEN, (i*100, 800), (mx-50+i*10, my+50))
draw.line(screen, GREEN, (0, i*80), (mx-50, my-50+i*10))
draw.line(screen, GREEN, (1000, i*80), (mx+50, my-50+i*10))
display.flip()
quit()