SlideShare a Scribd company logo
1 of 31
circ.db.db
circleserver(1).py
#!/usr/local/bin/python3
import wsgiref.simple_server
import urllib.parse
import sqlite3
import PIL.Image
import PIL.ImageDraw
def Mywebapp (environ, start_response) :
if environ['REQUEST_METHOD'] == "GET" :
if environ['PATH_INFO'] == '/' :
response = """
<html>
<head>
<title>Circles Are Us</title>
</head>
<body>
<h1> Welcome to the Circle Server </h1><br>
<p>
Welcome to our circle server. Please enter the
criteria<br>
for your circles below.
</p>
<form method="post">
Radius (5 - 50):
<input type="range" name="radius" min="5"
max="50" id="inputslider" value="25"
oninput="outputslider.value=inputslider.value" >
<output name="radiusout" id="outputslider" >
</output><br><br>
Color:
<select name="color" >
<option value="none"> None </option>
<option value="red"> Red </option>
<option value="green"> Green </option>
<option value="blue"> Blue </option>
<option value="orange"> Orange </option>
<option value="purple"> Purple </option>
<option value="pink"> Pink </option>
<option value="yellow"> Yellow </option>
<option value="black"> Black </option>
</select><br><br>
<input type="radio" name="fillval" value="1">
Filled<br>
<input type="radio" name="fillval" value="0">
Not Filled<br>
<input type="radio" name="fillval" value="-1"
checked> None<br><br>
<input type="submit" value="Get my circles">
</form>
</body>
</html>"""
response = response.encode('utf-8')
headers = [ ('Content-type', 'text/html, charset =
utf-8'), ('Content-length', str(len(response))) ]
else :
try :
response =
open(environ['PATH_INFO'][1:], "rb").read()
headers = [ ('Content-type', 'image/gif'),
('Content-length', str(len(response))) ]
except :
response = "Error - File not found"
response = response.encode('utf-8')
headers = [ ('Content-type', 'text/plain,
charset = utf-8'), ('Content-length', str(len(response))) ]
elif environ['REQUEST_METHOD'] == "POST" :
resplen = environ['CONTENT_LENGTH']
data = environ['wsgi.input'].read(int(resplen))
data = data.decode('utf-8')
datadict = urllib.parse.parse_qs(data)
db = sqlite3.connect("circ.db")
curs = db.cursor()
query = "select * from circles where radius >= " +
datadict['radius'][0]
if datadict['color'][0] != "none" :
query += " and color == '" + datadict['color'][0]
+ "'"
if datadict['fillval'][0] != '-1' :
query += " and fill == " + datadict['fillval'][0]
circles = curs.execute(query)
circleimage = PIL.Image.new('RGB', (640, 480),
color="grey")
drawer = PIL.ImageDraw.Draw(circleimage)
for circle in circles :
ulx = circle[0] - circle[2]
uly = circle[1] - circle[2]
lrx = circle[0] + circle[2]
lry = circle[1] + circle[2]
if circle[4] == 1 :
drawer.ellipse((ulx,uly,lrx,lry), outline =
circle[3], fill = circle[3])
else :
drawer.ellipse((ulx,uly,lrx,lry), outline =
circle[3])
circleimage.save("circimage.gif")
response = """
<html>
<head>
<title>Circles Are Us</title>
</head>
<body>
<h1> Welcome to the Circle Server </h1><br>
<p> Below is an image with your requested
circles </p>
<form method="get">
<input type="submit" value="Return to previous
page">
</form>
<img src="circimage.gif" alt="circle image"
width="640" height="480"/><br>
</body>
</html>"""
response = response.encode('utf-8')
headers = [ ('Content-type', 'text/html, charset = utf-
8'), ('Content-length', str(len(response))) ]
else :
response = "Error - bad request type"
response = response.encode('utf-8')
headers = [ ('Content-type', 'text/plain'), ('Content-
length', str(len(response))) ]
status = "200 ok"
start_response(status, headers)
return [ response ]
serv = wsgiref.simple_server.make_server("", 1234, Mywebapp)
serv.serve_forever()
makecircles(1).py
#!/usr/local/bin/python3
import tkinter
import tkinter.messagebox
import math
state = "nothing"
moveit = False
def hitbutton1 (ev) :
global moveit
global delid, centerx, centery
if state == "add" :
ulx = ev.x - radius.get()
uly = ev.y - radius.get()
lrx = ev.x + radius.get()
lry = ev.y + radius.get()
if checkfill.get() == 1 :
fillit = color.get()
else :
fillit = ""
circlecanvas.create_oval(ulx,uly,lrx,lry,outline =
color.get(), fill = fillit)
elif state == "delete" :
delid = circlecanvas.find_closest(ev.x, ev.y)
bbox = circlecanvas.coords(delid)
centerx = (bbox[0] + bbox[2])/2
centery = (bbox[1] + bbox[3])/2
if math.sqrt((centerx - ev.x) ** 2 + (centery - ev.y) **
2) < (centerx - bbox[0]) :
circlecanvas.delete(delid)
elif state == "move" :
delid = circlecanvas.find_closest(ev.x, ev.y)
bbox = circlecanvas.coords(delid)
centerx = (bbox[0] + bbox[2])/2
centery = (bbox[1] + bbox[3])/2
if math.sqrt((centerx - ev.x) ** 2 + (centery - ev.y) **
2) < (centerx - bbox[0]) :
moveit = True
else :
moveit = False
else :
print("Ignoring mouse click")
def hitbutton3 (ev) :
global moveit
if state == "move" and moveit == True :
circlecanvas.move(delid, ev.x - centerx, ev.y -
centery)
moveit = False
def hitkeya (ev) :
global state
state = "add"
def hitkeyd (ev) :
global state
state = "delete"
def hitkeym (ev) :
global state
state = "move"
rootwindow = tkinter.Tk()
rootwindow.title("Drawing Circles")
rootwindow.lift()
rootwindow.config(height = 200, width = 400, bg = "pink")
radiuslabel = tkinter.Label(rootwindow, text = "Radius:", bg =
"grey")
radiuslabel.grid(row = 0, column = 0, sticky = "wens")
rootwindow.columnconfigure(0, weight = 1)
rootwindow.rowconfigure(0, weight = 1)
radius = tkinter.IntVar()
radiusslider = tkinter.Scale(rootwindow, from_ = 5, to = 50,
variable = radius, bg = "green", orient = tkinter.HORIZONTAL)
radiusslider.grid(row = 0, column = 1, sticky = "wens")
rootwindow.columnconfigure(1, weight = 1)
colorlabel = tkinter.Label(rootwindow, text = "Color:", bg =
"grey")
colorlabel.grid(row = 0, column = 2, sticky = "wens")
rootwindow.columnconfigure(2, weight = 1)
color = tkinter.StringVar()
color.set("green")
colors = [ "red", "green", "blue", "orange", "yellow", "purple",
"pink" ]
colormenu = tkinter.OptionMenu(rootwindow, color, *colors)
colormenu.grid(row = 0, column = 3, sticky = "wens")
rootwindow.columnconfigure(3, weight = 1)
checkfill = tkinter.IntVar()
fillcheck = tkinter.Checkbutton(rootwindow, text = "Fill
Circle", variable = checkfill, bg = "grey")
fillcheck.grid(row = 0, column = 4, sticky = "wens")
rootwindow.columnconfigure(4, weight = 1)
circlecanvas = tkinter.Canvas(rootwindow, height = 400, width
= 600, bg = "grey")
circlecanvas.grid(row = 1, column = 0, columnspan = 5, sticky
= "wens")
rootwindow.rowconfigure(1, weight = 4)
circlecanvas.bind("<Button-1>", hitbutton1)
circlecanvas.bind("<Button-2>", hitbutton3)
circlecanvas.bind("a", hitkeya)
circlecanvas.bind("d", hitkeyd)
circlecanvas.bind("m", hitkeym)
circlecanvas.focus_set()
rootwindow.mainloop()
pongball(1).py
#!/usr/local/bin/python3
import tkinter
import tkinter.messagebox
import math
import PIL.Image
import PIL.ImageTk
import time
import random
random.seed()
i = 0
deltax = random.randint(1,3)
deltay = random.randint(-3,3)
def moveit2 () :
global loadedimage3, tkimage3, i, deltax, deltay
delay = 30
if i >= 24 :
i = 0
balllocation = circlecanvas.coords(imageid)
paddlelocation = circlecanvas.coords(paddleid)
if balllocation[1] > paddlelocation[1] - 20 and
balllocation[1] < paddlelocation[1] + 20 and balllocation[0] +
37 >= paddlelocation[0] - 2 :
deltax = -deltax
if balllocation[0] >= 565 :
circlecanvas.coords(imageid, (300,200))
deltax = random.randint(1,3)
deltay = random.randint(-3,3)
delay = 1000
if balllocation[0] <= 37 :
deltax = -deltax
if balllocation[1] >= 365 :
deltay = -deltay
if balllocation[1] <= 37 :
deltay = -deltay
loadedimage3.seek(i)
tkimage3 = PIL.ImageTk.PhotoImage(loadedimage3)
circlecanvas.itemconfig(imageid, image = tkimage3)
circlecanvas.move(imageid, deltax, deltay)
i += 1
rootwindow.after(delay, moveit2)
def moveit () :
rootwindow.after(1000, moveit2)
def hitkeyup (ev) :
circlecanvas.move(paddleid, 0, -8)
def hitkeydown (ev) :
circlecanvas.move(paddleid, 0, 8)
rootwindow = tkinter.Tk()
rootwindow.title("Pong")
rootwindow.lift()
rootwindow.config(height = 200, width = 400, bg = "pink")
loadedimage = PIL.Image.open("dummyimage.jpg")
loadedimage.thumbnail((40,40))
tkimage = PIL.ImageTk.PhotoImage(loadedimage)
radiuslabel = tkinter.Label(rootwindow, image = tkimage)
radiuslabel.grid(row = 0, column = 0, sticky = "wens")
rootwindow.columnconfigure(0, weight = 1)
rootwindow.rowconfigure(0, weight = 1)
loadedimage2 = PIL.Image.open("blob.png")
loadedimage2.thumbnail((30,30))
tkimage2 = PIL.ImageTk.PhotoImage(loadedimage2)
startbutton = tkinter.Button(rootwindow, image = tkimage2,
command = moveit)
startbutton.grid(row = 0, column = 1, sticky = "wens")
rootwindow.columnconfigure(1, weight = 1)
circlecanvas = tkinter.Canvas(rootwindow, height = 400, width
= 600, bg = "grey")
circlecanvas.grid(row = 1, column = 0, columnspan = 2, sticky
= "wens")
rootwindow.rowconfigure(1, weight = 4)
loadedimage3 = PIL.Image.open("Downloads/animated-ball-
image-0046.gif")
tkimage3 = PIL.ImageTk.PhotoImage(loadedimage3)
imageid = circlecanvas.create_image(300,200, image =
tkimage3)
paddleid = circlecanvas.create_image(500,200, image =
tkimage)
circlecanvas.bind("<Up>", hitkeyup)
circlecanvas.bind("<Down>", hitkeydown)
circlecanvas.focus_set()
rootwindow.mainloop()
pongball.py
#!/usr/local/bin/python3
import tkinter
import tkinter.messagebox
import math
import PIL.Image
import PIL.ImageTk
import time
# circlecanvas.move(delid, ev.x - centerx, ev.y -
centery)
def moveit () :
pass
#def hitkeya (ev) :
#global state
#state = "add"
rootwindow = tkinter.Tk()
rootwindow.title("Pong")
rootwindow.lift()
rootwindow.config(height = 200, width = 400, bg = "pink")
loadedimage = PIL.Image.open("dummyimage.jpg")
loadedimage.thumbnail((40,40))
tkimage = PIL.ImageTk.PhotoImage(loadedimage)
radiuslabel = tkinter.Label(rootwindow, image = tkimage)
radiuslabel.grid(row = 0, column = 0, sticky = "wens")
rootwindow.columnconfigure(0, weight = 1)
rootwindow.rowconfigure(0, weight = 1)
loadedimage2 = PIL.Image.open("blob.png")
loadedimage2.thumbnail((30,30))
tkimage2 = PIL.ImageTk.PhotoImage(loadedimage2)
startbutton = tkinter.Button(rootwindow, image = tkimage2,
command = moveit)
startbutton.grid(row = 0, column = 1, sticky = "wens")
rootwindow.columnconfigure(1, weight = 1)
circlecanvas = tkinter.Canvas(rootwindow, height = 400, width
= 600, bg = "grey")
circlecanvas.grid(row = 1, column = 0, columnspan = 2, sticky
= "wens")
rootwindow.rowconfigure(1, weight = 4)
loadedimage3 = PIL.Image.open("Downloads/animated-ball-
image-0046.gif")
for i in range (0,24) :
loadedimage3.seek(i)
tkimage3 = PIL.ImageTk.PhotoImage(loadedimage3)
circlecanvas.create_image(300,200, image = tkimage3)
#circlecanvas.bind("<Button-1>", hitbutton1)
#circlecanvas.bind("<Button-2>", hitbutton3)
#circlecanvas.bind("a", hitkeya)
#circlecanvas.bind("d", hitkeyd)
#circlecanvas.bind("m", hitkeym)
#circlecanvas.focus_set()
rootwindow.mainloop()
selectcircles.py
#!/usr/local/bin/python3
import sqlite3
import random
random.seed()
db = sqlite3.connect("circles.db")
curs = db.cursor()
#curs.execute("create table circles (x integer, y integer, r
integer, color text, fill integer)")
#circlist = []
#for i in range(0,100) :
#circlist.append((random.randint(0,600),
random.randint(0,400), random.randint(5,50),
random.choice(["red","blue","green","yellow","orange","purple"
,"pink","black"]), random.randint(0,1)))
#curs.executemany("insert into circles (x,y,r,color,fill) values
(?,?,?,?,?)", circlist)
#db.commit()
data = curs.execute("select * from circles where r > 25 or fill
== 1 order by r desc")
for item in data :
print("x =", item[0], "y =", item[1], "r =", item[2], "color
=", item[3], "fill =", item[4])
db.close()
showcircles(1).py
#!/usr/local/bin/python3
import tkinter
import tkinter.messagebox
import math
import sqlite3
import random
random.seed()
def createdb() :
db = sqlite3.connect("circles.db")
curs = db.cursor()
curs.execute("create table if not exists circles (x integer, y
integer, r integer, color text, fill integer)")
circlist = []
for i in range(0,100) :
circlist.append((random.randint(0,600),
random.randint(0,400), random.randint(5,50),
random.choice(["red","blue","green","yellow","orange","purple"
,"pink","black"]), random.randint(0,1)))
curs.executemany("insert into circles (x,y,r,color,fill)
values (?,?,?,?,?)", circlist)
db.commit()
db.close()
def selectdb() :
db = sqlite3.connect("circles.db")
curs = db.cursor()
query = "select * from circles where r >= " +
str(radius.get())
if color.get() != "none" :
query += " and color == '" + color.get() + "'"
if checkfill.get() != -1 :
query += " and fill == " + str(checkfill.get())
circlist = curs.execute(query)
circlecanvas.delete("all")
for circ in circlist :
ulx = circ[0] - circ[2]
uly = circ[1] - circ[2]
lrx = circ[0] + circ[2]
lry = circ[1] + circ[2]
if circ[4] :
fillit = circ[3]
else :
fillit = ""
circlecanvas.create_oval(ulx,uly,lrx,lry,outline =
circ[3], fill = fillit)
db.close()
rootwindow = tkinter.Tk()
rootwindow.title("Showing Circles")
rootwindow.lift()
rootwindow.config(height = 400, width = 600, bg = "pink")
radiuslabel = tkinter.Label(rootwindow, text = "Radius:", bg =
"grey")
radiuslabel.grid(row = 0, column = 0, sticky = "wens")
rootwindow.columnconfigure(0, weight = 1)
rootwindow.rowconfigure(0, weight = 1)
radius = tkinter.IntVar()
radiusslider = tkinter.Scale(rootwindow, from_ = 5, to = 50,
variable = radius, bg = "green", orient = tkinter.HORIZONTAL)
radiusslider.grid(row = 0, column = 1, sticky = "wens")
rootwindow.columnconfigure(1, weight = 1)
colorlabel = tkinter.Label(rootwindow, text = "Color:", bg =
"grey")
colorlabel.grid(row = 0, column = 2, sticky = "wens")
rootwindow.columnconfigure(2, weight = 1)
color = tkinter.StringVar()
color.set("none")
colors = [ "none", "red", "green", "blue", "orange", "yellow",
"purple", "pink", "black" ]
colormenu = tkinter.OptionMenu(rootwindow, color, *colors)
colormenu.grid(row = 0, column = 3, sticky = "wens")
rootwindow.columnconfigure(3, weight = 1)
checkfill = tkinter.IntVar()
fillcheck1 = tkinter.Radiobutton(rootwindow, text = "None",
variable = checkfill, value = -1, bg = "grey")
fillcheck1.grid(row = 0, column = 4, sticky = "wens")
rootwindow.columnconfigure(4, weight = 1)
fillcheck2 = tkinter.Radiobutton(rootwindow, text = "Filled",
variable = checkfill, value = 1, bg = "grey")
fillcheck2.grid(row = 0, column = 5, sticky = "wens")
rootwindow.columnconfigure(5, weight = 1)
fillcheck3 = tkinter.Radiobutton(rootwindow, text = "Not
Filled", variable = checkfill, value = 0, bg = "grey")
fillcheck3.grid(row = 0, column = 6, sticky = "wens")
rootwindow.columnconfigure(6, weight = 1)
startbutton = tkinter.Button(rootwindow, text = "Start",
command = createdb)
startbutton.grid(row = 0, column = 7, sticky = "wens")
rootwindow.columnconfigure(7, weight = 1)
getbutton = tkinter.Button(rootwindow, text = "Select",
command = selectdb)
getbutton.grid(row = 0, column = 8, sticky = "wens")
rootwindow.columnconfigure(8, weight = 1)
circlecanvas = tkinter.Canvas(rootwindow, height = 400, width
= 600, bg = "grey")
circlecanvas.grid(row = 1, column = 0, columnspan = 9, sticky
= "wens")
rootwindow.rowconfigure(1, weight = 4)
rootwindow.mainloop()
weathergui(1).py
#!/usr/local/bin/python3
import tkinter
import tkinter.messagebox
import urllib.request
import json
def getreport () :
if len(zipcode.get()) == 5 and zipcode.get().isdigit() :
requesturl =
"http://api.openweathermap.org/data/2.5/weather?zip="+zipcode
.get()+",us&mode=json&units=metric&APPID=b0d45b8cc18faf
92d77e9825fd5aae74"
try :
urlobject = urllib.request.urlopen(requesturl)
except BaseException as e:
tkinter.messagebox.showerror("Url Error", "Bad
Url" + e + ". Try again.")
return
if urlobject.getcode() == 200:
response = urlobject.read()
response = response.decode("utf-8")
jsonresponse = json.loads(response)
temperature = jsonresponse['main']['temp']
humidity = jsonresponse['main']['humidity']
pressure = jsonresponse['main']['pressure']
place = jsonresponse['name']
windspeed = jsonresponse['wind']['speed']
if 'deg' in jsonresponse['wind'].keys() :
winddir = jsonresponse['wind']['deg']
windnames = ['N', 'NNE', 'NE', 'ENE', 'E',
'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW',
'NNW', 'N' ]
index = int((winddir + 11.25) / 22.5)
windname = windnames[index]
else :
windname = "nowhere"
outstring = "The weather conditions in " + place
+ "n"
outstring += "Temperature = " + str(temperature)
+ " degrees Celciusn"
outstring += "Humidity = " + str(humidity) + "
%n"
outstring += "Barometric pressure = " +
str(pressure) + " millibarsn"
outstring += "Wind is at " + str(windspeed) + "
km/h from " + windname
weatherreport.set(outstring)
else :
tkinter.messagebox.showerror("Zipcode Error", "The
value you entered -" + zipcode.get() + "- is not a valid zipcode.
Try again.")
rootwindow = tkinter.Tk()
rootwindow.title("The Weather Reporter")
rootwindow.lift()
rootwindow.config(height = 200, width = 400, bg = "pink")
instructions = tkinter.Label(rootwindow, text = "Welcome to the
weather reporter. Please enter a zipcode for the location of your
weather report.", wraplength = 300, justify = "left")
instructions.grid(row = 0, column = 0, columnspan = 3, sticky =
"wens")
rootwindow.columnconfigure(0, weight = 1)
rootwindow.rowconfigure(0, weight = 1)
ziplabel = tkinter.Label(rootwindow, text = "Zipcode:", bg =
"green")
ziplabel.grid(row = 1, column = 0, sticky = "wens")
rootwindow.rowconfigure(1, weight = 2)
zipcode = tkinter.StringVar()
zipentry = tkinter.Entry(rootwindow, bg = "blue", fg = "red",
textvariable = zipcode)
zipentry.grid(row = 1, column = 1, sticky = "wens")
rootwindow.columnconfigure(1, weight = 1)
gobutton = tkinter.Button(rootwindow, text = "Hit Me",
command = getreport)
gobutton.grid(row = 1, column = 2, sticky = "wens")
rootwindow.columnconfigure(2, weight = 1)
weatherreport = tkinter.StringVar()
outputreport = tkinter.Message(rootwindow, textvariable =
weatherreport, width=300)
outputreport.grid(row = 2, column = 0, columnspan = 3, sticky
= "wens")
rootwindow.rowconfigure(2, weight = 3)
rootwindow.mainloop()
Michael Lay
G00129687
Lab 2
Grantham University
Introduction
The purpose of this lab exercise is to build a half wave rectifier
and a full wave rectifier in MULTISIM and on a breadboard.
The various output voltage are to be measured. The myDAQ is
to be used for data acquisition from the breadboard to the
MULTISIM software. The calculate values are to be compared
with the measured values to check for consistency.
Equipment/components used
Materials:
1. Simulated Parts (Multisim):
1. 10:1 center-tapped transformer
1. Two diodes 1N4001
1. Two 2.2 kΩ resistors
1. One 100 μF, 50 V electrolytic capacitor
1. One fuse (any rating is fine since it is for simulation only)
1. Hardware Parts (In the Toolbox):
1. Two diodes 1N4001
1. Two 2.2 kΩ resistors
1. One 100 μF, 50 V electrolytic capacitor
1. Virtual Instruments (Multisim):
1. Function Generator (Multisim)
1. Function Generator (NI Elvisms Instrument Launcher)
1. Arbitrary Waveform Generator (NI Elvismx Instrument
Launcher)
1. Tektronix oscilloscope (Multisim)
1. Oscilloscope (NI Elvismx Instrument Launcher)
1. Hardware Equipment:
1. Breadboard
1. NI myDAQ Instrument Device
1. Screw Driver
1. Screw Terminal connector
1. Jumper wires
Problem statement
The circuits shown in the figure below both for the half-wave
rectifier and a full wave rectifier are to be constructed in
MULTISIM and on a breadboard.
Theoretical solution
For the half wave rectifier the calculations are done as follows:
Without filter capacitor
The input voltage is 30V rms. The transformer has a turn-ratio
of 10:1
The secondary RMS voltage is: 30V/10=3VRMS
The peak secondary voltage is equal to 3*sqrt(2)= 4.2426V
The peak load voltage is equal to 4.2426-0.7V=3.5426
The RMS load voltage is equal to
The average DC voltage is equal to
The peak to peak ripple voltage is equal to: 3.5426-0=3.5426V
The ripple frequency is equal to the source frequency=60Hz
Half wave rectifier with the filter capacitor:
The filter capacitor is equal to 100uF:
The ripple voltage is equal to
FULL wave rectifier calculations:
The source voltage is equal to 30V rms. The turns-ratio of the
transformer is 10:1
The secondary voltage is equal to 30V/(10*2)=1.5V
The peak secondary voltage is equal to 1.5*sqrt(2)= 2.1213V
The peak load voltage is equal to 2.1213-0.7=1.4213V
The RMS load voltage is equal to 1.4213/sqrt(2)=1.005V
The average DC load voltage is equal to: 0.637*1.4213=
0.9054V
The peak to peak ripple voltage is equal to 1.4213V-
0V=1.4213V
With the filter capacitor
The ripple frequency is equal to 2*F=1*60Hz=120Hz
The peak to peak ripple voltage is equal to
Experimental procedure
Circuit design
The half wave rectifier is constructed as shown in the figure
below:
The full-wave rectifier circuit is constructed as shown below:
Execution/results
Half wave rectifier MULTISIM measurements
1. RMS secondary voltage
1. RMS load voltage
1. Peak to peak ripple voltage
1. Ripple frequency
1. Peak to peak ripple voltage with the filter capacitor
1. Ripple frequency
Half wave rectifier myDAQ measurements
1. Load voltage measurement
1. Secondary voltage measurement
1. Load voltage measurement with the filter capacitor
Full wave rectifier MULTISIM measurements
1. RMS load voltage
1. Peak to peak ripple voltage
1. Ripple frequency
1. Peak to peak voltage with filter capacitor
1. Ripple frequency
Full wave rectifier myDAQ measurements
1. Load voltage without the filter capacitor
1. Load voltage with the filter capacitor
Analysis
The measured and the calculated values were summarized in the
tables below:
1. Half –wave rectifier
Parameter
Calculated value
Multisim value
NI myDAQ value
RMS load voltage
1.7713V
1.4V
1.756V
RMS secondary voltage
3V
3V
3V
Ripple voltage
3.5426V
3.68V
3.682V
Ripple frequency
60Hz
60Hz
60Hz
Ripple voltage with capacitor
267mV
217mV
216.85mV
Ripple frequency with capacitor
60Hz
60Hz
60Hz
1. Full wave rectifier values
Parameter
Calculated value
Multisim value
NI myDAQ value
RMS load voltage
1.005V
561mV
1.046V
RMS secondary voltage
1.5V
1.5V
1.5V
Ripple voltage
1.4213V
1.6V
1.594V
Ripple frequency
120Hz
120Hz
120Hz
Ripple voltage with capacitor
53.8mV
40.7mV
40.45mV
Ripple frequency with capacitor
120Hz
120Hz
120Hz
Review questions
Part 1
1. What is the purpose of having a half-wave rectifier in the
circuit?
It converts the positive going cycles of an alternating AC
voltage into a pulsating DC voltage.
1. Describe the procedure in this lab to arrive at the final design
of both the hardware portion and the software portion to achieve
the design objectives?
The connections on the breadboard and in the MULTISIM
software were done as per the connection diagram.
1. Discuss the impact of having the capacitor on the output
voltage and the effect of additional load on the ripple voltage.
The function of the capacitor is to reduce the ripples in the
output voltage and make it more like a DC voltage.
Part 2
1. What is the purpose of having a full-wave rectifier in the
circuit?
A full-wave rectifier converts the alternating AC voltage into a
pulsating DC voltage. It conducts for both the positive going
cycle and the negative going cycle.
1. Describe the procedure in this lab to arrive at the final design
of both the hardware portion and the software portion to achieve
the design objectives?
The connections on the breadboard and in the MULTISIM
software were done as per the connection diagram.
1. Discuss the impact of having the capacitor on the output
voltage and the effect of additional load on the ripple voltage.
The function of the capacitor is to reduce the ripples in the
output voltage and make it more like a DC voltage.
1. How is the output of the full-wave rectifier different from
half-wave rectifier?
The output voltage of a full wave rectifier is more linear than
the output voltage of a half wave rectifier.
Conclusion
This lab exercise was a good insight in the study and design of a
half wave rectifier and a full wave rectifier. The measured
values and the calculated values were very close to each other
and thus the lab exercise was a success.
Electronics I and Lab
Bridge Rectifier
Introduction:
Week 3 lab is based on the previous lab from week 2 on half-
wave and full-wave rectifiers and taking that knowledge to
build a bridge rectifier.
Materials and Equipment:
Materials:
· Simulated Parts (Multisim):
. A 30/3 Vrms center-tapped transformer
. Two diodes 1N4001
. Two 2.2 kΩ resistors
. One 100 μF, 50 V electrolytic capacitor (any voltage rating is
fine since is simulation only)
. One fuse (any rating is fine since is simulation only)
Equipment:
· Virtual Instruments (Multisim):
. Tektronix Oscilloscope
. Agilent Multimeter
. Agilent Function generator
Procedure:
*** This lab has to be implemented only in software (running
simulations on Multisim)***
1. Construct the bridge rectifier circuit shown in Figure 1.
Notice that no terminal of the transformer secondary is at
ground potential (some simulation software will not run if it is
not connected to the ground, check yours). The input voltage to
the bridge, VSEC, is not referenced to ground. Make sure to
include resistor tolerance of 5%.
2. Use a function generator to provide VAC and run the
simulation.
3. Use a multimeter to measure VSEC (rms) and then use the
oscilloscope to measure the peak output voltage (VLOAD)
without a filter capacitor. Tabulate all data gathered.
Figure 1
4. Connect the 100 μF capacitor in parallel with the load
resistor. Measure VLOAD, the peak-to-peak ripple voltage
VRIPPLE, and the ripple frequency. Tabulate all data gathered
and compare the results with and without the filter capacitor.
Without the capacitor
With the capacitor
Output load voltage VLOAD
Peak-to-peak ripple voltage VRIPPLE
Ripple frequency
5. Choose a diode among the four connected to the bridge and
open it. Simulate an open diode in the bridge and explain what
happens to the output voltage, the ripple voltage and the ripple
frequency?
6. Investigate the effect of the load resistor on the ripple
voltage by connecting a second 2.2 kΩ, 5% tolerance, and load
resistor in parallel with RL and C1 in the full-wave circuit of
Figure 3. Measure the ripple voltage. Captures a screenshot.
Review questions:
1. Compare a bridge rectifier circuit with full-wave rectifier
center-tapped circuit which you did in Lab 2. Which circuit has
the higher output voltage?
2. Explain how you could measure the ripple frequency to
determine if a diode were open in a bridge rectifier circuit.
3. What is the maximum dc voltage you could expect to obtain
from a transformer with a 3 Vrms secondary using a bridge
circuit with a filter capacitor?
Deliverables:
1. Measure the voltage VSEC and the output load voltage,
VLOAD without a filter capacitor. Capture the screenshots of
your measurements.
2. Measure the output load voltage, VLOAD, with the capacitor
and the peak-to-peak ripple voltage, VRIPPLE, in the output.
Capture the screenshots of your measurements. Also, measure
the ripple frequency. Table with all the data gathered for the
circuit with and without the capacitor.
3. Follow the template “Lab Report Template” to compile the
report and make sure to check the report against the grading
rubric below. The template can be found in the “Tools and
Templates” link in the navigation center.
4. Make sure to include the table, calculations, screenshots of
the measurements and the answer to the questions. Save the
document as Lab2YourGID.docx (ex: Lab3G00000000.docx).
Grading Criteria
Points
Construct bridge rectifier circuit in Multisim without a
capacitor
15
Measurement of VSEC and VLOAD voltages with screenshots
10
Construct bridge rectifier circuit in Multisim with a capacitor
10
Measurement of VSEC, VLOAD and VRIPPLE voltages with
screenshots
15
Simulation with an open diode and measurement with
screenshots
20
Including 5% tolerances in the measurements
10
Review Questions
10
Report format (Proper use of template)
10
TOTAL
100

More Related Content

Similar to circ.db.dbcircleserver(1).py#!usrlocalbinpython3im.docx

Python 내장 함수
Python 내장 함수Python 내장 함수
Python 내장 함수용 최
 
The Ring programming language version 1.5.2 book - Part 43 of 181
The Ring programming language version 1.5.2 book - Part 43 of 181The Ring programming language version 1.5.2 book - Part 43 of 181
The Ring programming language version 1.5.2 book - Part 43 of 181Mahmoud Samir Fayed
 
밑바닥부터 시작하는 의료 AI
밑바닥부터 시작하는 의료 AI밑바닥부터 시작하는 의료 AI
밑바닥부터 시작하는 의료 AINAVER Engineering
 
The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 46 of 185
The Ring programming language version 1.5.4 book - Part 46 of 185The Ring programming language version 1.5.4 book - Part 46 of 185
The Ring programming language version 1.5.4 book - Part 46 of 185Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 46 of 189
The Ring programming language version 1.6 book - Part 46 of 189The Ring programming language version 1.6 book - Part 46 of 189
The Ring programming language version 1.6 book - Part 46 of 189Mahmoud Samir Fayed
 
Assignment7.pdf
Assignment7.pdfAssignment7.pdf
Assignment7.pdfdash41
 
TechShift: There’s light beyond LAMP
TechShift: There’s light beyond LAMPTechShift: There’s light beyond LAMP
TechShift: There’s light beyond LAMPStephen Tallamy
 
CSS Algorithms - v3.6.1 @ Strange Loop
CSS Algorithms - v3.6.1 @ Strange LoopCSS Algorithms - v3.6.1 @ Strange Loop
CSS Algorithms - v3.6.1 @ Strange LoopLara Schenck
 
The Ring programming language version 1.5.2 book - Part 52 of 181
The Ring programming language version 1.5.2 book - Part 52 of 181The Ring programming language version 1.5.2 book - Part 52 of 181
The Ring programming language version 1.5.2 book - Part 52 of 181Mahmoud Samir Fayed
 
Ruby is Awesome
Ruby is AwesomeRuby is Awesome
Ruby is AwesomeAstrails
 
CS101- Introduction to Computing- Lecture 41
CS101- Introduction to Computing- Lecture 41CS101- Introduction to Computing- Lecture 41
CS101- Introduction to Computing- Lecture 41Bilal Ahmed
 
D3 svg & angular
D3 svg & angularD3 svg & angular
D3 svg & angular500Tech
 
SVG, CSS3, and D3 for Beginners
SVG, CSS3, and D3 for BeginnersSVG, CSS3, and D3 for Beginners
SVG, CSS3, and D3 for BeginnersOswald Campesato
 
CSS3 Takes on the World
CSS3 Takes on the WorldCSS3 Takes on the World
CSS3 Takes on the WorldJonathan Snook
 
The Ring programming language version 1.5.3 book - Part 57 of 184
The Ring programming language version 1.5.3 book - Part 57 of 184The Ring programming language version 1.5.3 book - Part 57 of 184
The Ring programming language version 1.5.3 book - Part 57 of 184Mahmoud Samir Fayed
 

Similar to circ.db.dbcircleserver(1).py#!usrlocalbinpython3im.docx (20)

Python 내장 함수
Python 내장 함수Python 내장 함수
Python 내장 함수
 
The Ring programming language version 1.5.2 book - Part 43 of 181
The Ring programming language version 1.5.2 book - Part 43 of 181The Ring programming language version 1.5.2 book - Part 43 of 181
The Ring programming language version 1.5.2 book - Part 43 of 181
 
Ahmad faizun
Ahmad faizunAhmad faizun
Ahmad faizun
 
D3
D3D3
D3
 
밑바닥부터 시작하는 의료 AI
밑바닥부터 시작하는 의료 AI밑바닥부터 시작하는 의료 AI
밑바닥부터 시작하는 의료 AI
 
14709302.ppt
14709302.ppt14709302.ppt
14709302.ppt
 
The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31
 
The Ring programming language version 1.5.4 book - Part 46 of 185
The Ring programming language version 1.5.4 book - Part 46 of 185The Ring programming language version 1.5.4 book - Part 46 of 185
The Ring programming language version 1.5.4 book - Part 46 of 185
 
The Ring programming language version 1.6 book - Part 46 of 189
The Ring programming language version 1.6 book - Part 46 of 189The Ring programming language version 1.6 book - Part 46 of 189
The Ring programming language version 1.6 book - Part 46 of 189
 
Assignment7.pdf
Assignment7.pdfAssignment7.pdf
Assignment7.pdf
 
TechShift: There’s light beyond LAMP
TechShift: There’s light beyond LAMPTechShift: There’s light beyond LAMP
TechShift: There’s light beyond LAMP
 
CSS Algorithms - v3.6.1 @ Strange Loop
CSS Algorithms - v3.6.1 @ Strange LoopCSS Algorithms - v3.6.1 @ Strange Loop
CSS Algorithms - v3.6.1 @ Strange Loop
 
The Ring programming language version 1.5.2 book - Part 52 of 181
The Ring programming language version 1.5.2 book - Part 52 of 181The Ring programming language version 1.5.2 book - Part 52 of 181
The Ring programming language version 1.5.2 book - Part 52 of 181
 
Ruby is Awesome
Ruby is AwesomeRuby is Awesome
Ruby is Awesome
 
CS101- Introduction to Computing- Lecture 41
CS101- Introduction to Computing- Lecture 41CS101- Introduction to Computing- Lecture 41
CS101- Introduction to Computing- Lecture 41
 
D3 svg & angular
D3 svg & angularD3 svg & angular
D3 svg & angular
 
SVG, CSS3, and D3 for Beginners
SVG, CSS3, and D3 for BeginnersSVG, CSS3, and D3 for Beginners
SVG, CSS3, and D3 for Beginners
 
CSS3 Takes on the World
CSS3 Takes on the WorldCSS3 Takes on the World
CSS3 Takes on the World
 
Scrollytelling
ScrollytellingScrollytelling
Scrollytelling
 
The Ring programming language version 1.5.3 book - Part 57 of 184
The Ring programming language version 1.5.3 book - Part 57 of 184The Ring programming language version 1.5.3 book - Part 57 of 184
The Ring programming language version 1.5.3 book - Part 57 of 184
 

More from christinemaritza

ENG315                                    Professional Scenari.docx
ENG315                                    Professional Scenari.docxENG315                                    Professional Scenari.docx
ENG315                                    Professional Scenari.docxchristinemaritza
 
ENG122 – Research Paper Peer Review InstructionsApply each of .docx
ENG122 – Research Paper Peer Review InstructionsApply each of .docxENG122 – Research Paper Peer Review InstructionsApply each of .docx
ENG122 – Research Paper Peer Review InstructionsApply each of .docxchristinemaritza
 
ENG122 – Research Paper Peer Review InstructionsApply each of th.docx
ENG122 – Research Paper Peer Review InstructionsApply each of th.docxENG122 – Research Paper Peer Review InstructionsApply each of th.docx
ENG122 – Research Paper Peer Review InstructionsApply each of th.docxchristinemaritza
 
ENG115ASSIGNMENT2STANCEESSAYDRAFTDueWeek.docx
ENG115ASSIGNMENT2STANCEESSAYDRAFTDueWeek.docxENG115ASSIGNMENT2STANCEESSAYDRAFTDueWeek.docx
ENG115ASSIGNMENT2STANCEESSAYDRAFTDueWeek.docxchristinemaritza
 
ENG 510 Final Project Milestone Three Guidelines and Rubric .docx
ENG 510 Final Project Milestone Three Guidelines and Rubric .docxENG 510 Final Project Milestone Three Guidelines and Rubric .docx
ENG 510 Final Project Milestone Three Guidelines and Rubric .docxchristinemaritza
 
ENG-105 Peer Review Worksheet Rhetorical Analysis of a Public.docx
ENG-105 Peer Review Worksheet Rhetorical Analysis of a Public.docxENG-105 Peer Review Worksheet Rhetorical Analysis of a Public.docx
ENG-105 Peer Review Worksheet Rhetorical Analysis of a Public.docxchristinemaritza
 
ENG 272-0Objective The purpose of this essay is t.docx
ENG 272-0Objective  The purpose of this essay is t.docxENG 272-0Objective  The purpose of this essay is t.docx
ENG 272-0Objective The purpose of this essay is t.docxchristinemaritza
 
ENG 360 01 American PoetrySpring 2019TuesdayFriday 800 –.docx
ENG 360 01 American PoetrySpring 2019TuesdayFriday 800 –.docxENG 360 01 American PoetrySpring 2019TuesdayFriday 800 –.docx
ENG 360 01 American PoetrySpring 2019TuesdayFriday 800 –.docxchristinemaritza
 
ENG 4034AHamlet Final AssessmentDUE DATE WEDNESDAY, 1220, 1.docx
ENG 4034AHamlet Final AssessmentDUE DATE WEDNESDAY, 1220, 1.docxENG 4034AHamlet Final AssessmentDUE DATE WEDNESDAY, 1220, 1.docx
ENG 4034AHamlet Final AssessmentDUE DATE WEDNESDAY, 1220, 1.docxchristinemaritza
 
ENG 3107 Writing for the Professions—Business & Social Scienc.docx
ENG 3107 Writing for the Professions—Business & Social Scienc.docxENG 3107 Writing for the Professions—Business & Social Scienc.docx
ENG 3107 Writing for the Professions—Business & Social Scienc.docxchristinemaritza
 
ENG 271Plato and Aristotlea Classical Greek philosophe.docx
ENG 271Plato and Aristotlea Classical Greek philosophe.docxENG 271Plato and Aristotlea Classical Greek philosophe.docx
ENG 271Plato and Aristotlea Classical Greek philosophe.docxchristinemaritza
 
ENG 315 Professional Communication Week 4 Discussion Deliver.docx
ENG 315 Professional Communication Week 4 Discussion Deliver.docxENG 315 Professional Communication Week 4 Discussion Deliver.docx
ENG 315 Professional Communication Week 4 Discussion Deliver.docxchristinemaritza
 
ENG 315 Professional Communication Week 9Professional Exp.docx
ENG 315 Professional Communication Week 9Professional Exp.docxENG 315 Professional Communication Week 9Professional Exp.docx
ENG 315 Professional Communication Week 9Professional Exp.docxchristinemaritza
 
ENG 202 Questions about Point of View in Ursula K. Le Guin’s .docx
ENG 202 Questions about Point of View in Ursula K. Le Guin’s .docxENG 202 Questions about Point of View in Ursula K. Le Guin’s .docx
ENG 202 Questions about Point of View in Ursula K. Le Guin’s .docxchristinemaritza
 
ENG 220250 Lab Report Requirements Version 0.8 -- 0813201.docx
ENG 220250 Lab Report Requirements Version 0.8 -- 0813201.docxENG 220250 Lab Report Requirements Version 0.8 -- 0813201.docx
ENG 220250 Lab Report Requirements Version 0.8 -- 0813201.docxchristinemaritza
 
ENG 203 Short Article Response 2 Sample Answer (Worth 13 mark.docx
ENG 203 Short Article Response 2 Sample Answer (Worth 13 mark.docxENG 203 Short Article Response 2 Sample Answer (Worth 13 mark.docx
ENG 203 Short Article Response 2 Sample Answer (Worth 13 mark.docxchristinemaritza
 
ENG 130 Literature and Comp ENG 130 Argumentative Resear.docx
ENG 130 Literature and Comp ENG 130 Argumentative Resear.docxENG 130 Literature and Comp ENG 130 Argumentative Resear.docx
ENG 130 Literature and Comp ENG 130 Argumentative Resear.docxchristinemaritza
 
ENG 132What’s Wrong With HoldenHere’s What You Should Do, .docx
ENG 132What’s Wrong With HoldenHere’s What You Should Do, .docxENG 132What’s Wrong With HoldenHere’s What You Should Do, .docx
ENG 132What’s Wrong With HoldenHere’s What You Should Do, .docxchristinemaritza
 
ENG 130- Literature and Comp Literary Response for Setting.docx
ENG 130- Literature and Comp Literary Response for Setting.docxENG 130- Literature and Comp Literary Response for Setting.docx
ENG 130- Literature and Comp Literary Response for Setting.docxchristinemaritza
 
ENG 130 Literature and Comp Literary Response for Point o.docx
ENG 130 Literature and Comp Literary Response for Point o.docxENG 130 Literature and Comp Literary Response for Point o.docx
ENG 130 Literature and Comp Literary Response for Point o.docxchristinemaritza
 

More from christinemaritza (20)

ENG315                                    Professional Scenari.docx
ENG315                                    Professional Scenari.docxENG315                                    Professional Scenari.docx
ENG315                                    Professional Scenari.docx
 
ENG122 – Research Paper Peer Review InstructionsApply each of .docx
ENG122 – Research Paper Peer Review InstructionsApply each of .docxENG122 – Research Paper Peer Review InstructionsApply each of .docx
ENG122 – Research Paper Peer Review InstructionsApply each of .docx
 
ENG122 – Research Paper Peer Review InstructionsApply each of th.docx
ENG122 – Research Paper Peer Review InstructionsApply each of th.docxENG122 – Research Paper Peer Review InstructionsApply each of th.docx
ENG122 – Research Paper Peer Review InstructionsApply each of th.docx
 
ENG115ASSIGNMENT2STANCEESSAYDRAFTDueWeek.docx
ENG115ASSIGNMENT2STANCEESSAYDRAFTDueWeek.docxENG115ASSIGNMENT2STANCEESSAYDRAFTDueWeek.docx
ENG115ASSIGNMENT2STANCEESSAYDRAFTDueWeek.docx
 
ENG 510 Final Project Milestone Three Guidelines and Rubric .docx
ENG 510 Final Project Milestone Three Guidelines and Rubric .docxENG 510 Final Project Milestone Three Guidelines and Rubric .docx
ENG 510 Final Project Milestone Three Guidelines and Rubric .docx
 
ENG-105 Peer Review Worksheet Rhetorical Analysis of a Public.docx
ENG-105 Peer Review Worksheet Rhetorical Analysis of a Public.docxENG-105 Peer Review Worksheet Rhetorical Analysis of a Public.docx
ENG-105 Peer Review Worksheet Rhetorical Analysis of a Public.docx
 
ENG 272-0Objective The purpose of this essay is t.docx
ENG 272-0Objective  The purpose of this essay is t.docxENG 272-0Objective  The purpose of this essay is t.docx
ENG 272-0Objective The purpose of this essay is t.docx
 
ENG 360 01 American PoetrySpring 2019TuesdayFriday 800 –.docx
ENG 360 01 American PoetrySpring 2019TuesdayFriday 800 –.docxENG 360 01 American PoetrySpring 2019TuesdayFriday 800 –.docx
ENG 360 01 American PoetrySpring 2019TuesdayFriday 800 –.docx
 
ENG 4034AHamlet Final AssessmentDUE DATE WEDNESDAY, 1220, 1.docx
ENG 4034AHamlet Final AssessmentDUE DATE WEDNESDAY, 1220, 1.docxENG 4034AHamlet Final AssessmentDUE DATE WEDNESDAY, 1220, 1.docx
ENG 4034AHamlet Final AssessmentDUE DATE WEDNESDAY, 1220, 1.docx
 
ENG 3107 Writing for the Professions—Business & Social Scienc.docx
ENG 3107 Writing for the Professions—Business & Social Scienc.docxENG 3107 Writing for the Professions—Business & Social Scienc.docx
ENG 3107 Writing for the Professions—Business & Social Scienc.docx
 
ENG 271Plato and Aristotlea Classical Greek philosophe.docx
ENG 271Plato and Aristotlea Classical Greek philosophe.docxENG 271Plato and Aristotlea Classical Greek philosophe.docx
ENG 271Plato and Aristotlea Classical Greek philosophe.docx
 
ENG 315 Professional Communication Week 4 Discussion Deliver.docx
ENG 315 Professional Communication Week 4 Discussion Deliver.docxENG 315 Professional Communication Week 4 Discussion Deliver.docx
ENG 315 Professional Communication Week 4 Discussion Deliver.docx
 
ENG 315 Professional Communication Week 9Professional Exp.docx
ENG 315 Professional Communication Week 9Professional Exp.docxENG 315 Professional Communication Week 9Professional Exp.docx
ENG 315 Professional Communication Week 9Professional Exp.docx
 
ENG 202 Questions about Point of View in Ursula K. Le Guin’s .docx
ENG 202 Questions about Point of View in Ursula K. Le Guin’s .docxENG 202 Questions about Point of View in Ursula K. Le Guin’s .docx
ENG 202 Questions about Point of View in Ursula K. Le Guin’s .docx
 
ENG 220250 Lab Report Requirements Version 0.8 -- 0813201.docx
ENG 220250 Lab Report Requirements Version 0.8 -- 0813201.docxENG 220250 Lab Report Requirements Version 0.8 -- 0813201.docx
ENG 220250 Lab Report Requirements Version 0.8 -- 0813201.docx
 
ENG 203 Short Article Response 2 Sample Answer (Worth 13 mark.docx
ENG 203 Short Article Response 2 Sample Answer (Worth 13 mark.docxENG 203 Short Article Response 2 Sample Answer (Worth 13 mark.docx
ENG 203 Short Article Response 2 Sample Answer (Worth 13 mark.docx
 
ENG 130 Literature and Comp ENG 130 Argumentative Resear.docx
ENG 130 Literature and Comp ENG 130 Argumentative Resear.docxENG 130 Literature and Comp ENG 130 Argumentative Resear.docx
ENG 130 Literature and Comp ENG 130 Argumentative Resear.docx
 
ENG 132What’s Wrong With HoldenHere’s What You Should Do, .docx
ENG 132What’s Wrong With HoldenHere’s What You Should Do, .docxENG 132What’s Wrong With HoldenHere’s What You Should Do, .docx
ENG 132What’s Wrong With HoldenHere’s What You Should Do, .docx
 
ENG 130- Literature and Comp Literary Response for Setting.docx
ENG 130- Literature and Comp Literary Response for Setting.docxENG 130- Literature and Comp Literary Response for Setting.docx
ENG 130- Literature and Comp Literary Response for Setting.docx
 
ENG 130 Literature and Comp Literary Response for Point o.docx
ENG 130 Literature and Comp Literary Response for Point o.docxENG 130 Literature and Comp Literary Response for Point o.docx
ENG 130 Literature and Comp Literary Response for Point o.docx
 

Recently uploaded

Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111GangaMaiya1
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...EADTU
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningMarc Dusseiller Dusjagr
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptNishitharanjan Rout
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 

Recently uploaded (20)

Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
Our Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdfOur Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdf
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 

circ.db.dbcircleserver(1).py#!usrlocalbinpython3im.docx

  • 1. circ.db.db circleserver(1).py #!/usr/local/bin/python3 import wsgiref.simple_server import urllib.parse import sqlite3 import PIL.Image import PIL.ImageDraw def Mywebapp (environ, start_response) : if environ['REQUEST_METHOD'] == "GET" : if environ['PATH_INFO'] == '/' : response = """ <html> <head> <title>Circles Are Us</title> </head> <body> <h1> Welcome to the Circle Server </h1><br> <p> Welcome to our circle server. Please enter the criteria<br> for your circles below. </p> <form method="post"> Radius (5 - 50): <input type="range" name="radius" min="5" max="50" id="inputslider" value="25"
  • 2. oninput="outputslider.value=inputslider.value" > <output name="radiusout" id="outputslider" > </output><br><br> Color: <select name="color" > <option value="none"> None </option> <option value="red"> Red </option> <option value="green"> Green </option> <option value="blue"> Blue </option> <option value="orange"> Orange </option> <option value="purple"> Purple </option> <option value="pink"> Pink </option> <option value="yellow"> Yellow </option> <option value="black"> Black </option> </select><br><br> <input type="radio" name="fillval" value="1"> Filled<br> <input type="radio" name="fillval" value="0"> Not Filled<br> <input type="radio" name="fillval" value="-1" checked> None<br><br> <input type="submit" value="Get my circles"> </form> </body> </html>""" response = response.encode('utf-8') headers = [ ('Content-type', 'text/html, charset = utf-8'), ('Content-length', str(len(response))) ] else : try : response = open(environ['PATH_INFO'][1:], "rb").read() headers = [ ('Content-type', 'image/gif'), ('Content-length', str(len(response))) ] except : response = "Error - File not found"
  • 3. response = response.encode('utf-8') headers = [ ('Content-type', 'text/plain, charset = utf-8'), ('Content-length', str(len(response))) ] elif environ['REQUEST_METHOD'] == "POST" : resplen = environ['CONTENT_LENGTH'] data = environ['wsgi.input'].read(int(resplen)) data = data.decode('utf-8') datadict = urllib.parse.parse_qs(data) db = sqlite3.connect("circ.db") curs = db.cursor() query = "select * from circles where radius >= " + datadict['radius'][0] if datadict['color'][0] != "none" : query += " and color == '" + datadict['color'][0] + "'" if datadict['fillval'][0] != '-1' : query += " and fill == " + datadict['fillval'][0] circles = curs.execute(query) circleimage = PIL.Image.new('RGB', (640, 480), color="grey") drawer = PIL.ImageDraw.Draw(circleimage) for circle in circles : ulx = circle[0] - circle[2] uly = circle[1] - circle[2] lrx = circle[0] + circle[2] lry = circle[1] + circle[2] if circle[4] == 1 : drawer.ellipse((ulx,uly,lrx,lry), outline =
  • 4. circle[3], fill = circle[3]) else : drawer.ellipse((ulx,uly,lrx,lry), outline = circle[3]) circleimage.save("circimage.gif") response = """ <html> <head> <title>Circles Are Us</title> </head> <body> <h1> Welcome to the Circle Server </h1><br> <p> Below is an image with your requested circles </p> <form method="get"> <input type="submit" value="Return to previous page"> </form> <img src="circimage.gif" alt="circle image" width="640" height="480"/><br> </body> </html>""" response = response.encode('utf-8') headers = [ ('Content-type', 'text/html, charset = utf- 8'), ('Content-length', str(len(response))) ] else : response = "Error - bad request type" response = response.encode('utf-8') headers = [ ('Content-type', 'text/plain'), ('Content- length', str(len(response))) ] status = "200 ok"
  • 5. start_response(status, headers) return [ response ] serv = wsgiref.simple_server.make_server("", 1234, Mywebapp) serv.serve_forever() makecircles(1).py #!/usr/local/bin/python3 import tkinter import tkinter.messagebox import math state = "nothing" moveit = False def hitbutton1 (ev) : global moveit global delid, centerx, centery if state == "add" : ulx = ev.x - radius.get() uly = ev.y - radius.get() lrx = ev.x + radius.get() lry = ev.y + radius.get() if checkfill.get() == 1 : fillit = color.get() else : fillit = "" circlecanvas.create_oval(ulx,uly,lrx,lry,outline = color.get(), fill = fillit) elif state == "delete" : delid = circlecanvas.find_closest(ev.x, ev.y)
  • 6. bbox = circlecanvas.coords(delid) centerx = (bbox[0] + bbox[2])/2 centery = (bbox[1] + bbox[3])/2 if math.sqrt((centerx - ev.x) ** 2 + (centery - ev.y) ** 2) < (centerx - bbox[0]) : circlecanvas.delete(delid) elif state == "move" : delid = circlecanvas.find_closest(ev.x, ev.y) bbox = circlecanvas.coords(delid) centerx = (bbox[0] + bbox[2])/2 centery = (bbox[1] + bbox[3])/2 if math.sqrt((centerx - ev.x) ** 2 + (centery - ev.y) ** 2) < (centerx - bbox[0]) : moveit = True else : moveit = False else : print("Ignoring mouse click") def hitbutton3 (ev) : global moveit if state == "move" and moveit == True : circlecanvas.move(delid, ev.x - centerx, ev.y - centery) moveit = False def hitkeya (ev) : global state state = "add" def hitkeyd (ev) : global state
  • 7. state = "delete" def hitkeym (ev) : global state state = "move" rootwindow = tkinter.Tk() rootwindow.title("Drawing Circles") rootwindow.lift() rootwindow.config(height = 200, width = 400, bg = "pink") radiuslabel = tkinter.Label(rootwindow, text = "Radius:", bg = "grey") radiuslabel.grid(row = 0, column = 0, sticky = "wens") rootwindow.columnconfigure(0, weight = 1) rootwindow.rowconfigure(0, weight = 1) radius = tkinter.IntVar() radiusslider = tkinter.Scale(rootwindow, from_ = 5, to = 50, variable = radius, bg = "green", orient = tkinter.HORIZONTAL) radiusslider.grid(row = 0, column = 1, sticky = "wens") rootwindow.columnconfigure(1, weight = 1) colorlabel = tkinter.Label(rootwindow, text = "Color:", bg = "grey") colorlabel.grid(row = 0, column = 2, sticky = "wens") rootwindow.columnconfigure(2, weight = 1) color = tkinter.StringVar() color.set("green") colors = [ "red", "green", "blue", "orange", "yellow", "purple", "pink" ] colormenu = tkinter.OptionMenu(rootwindow, color, *colors) colormenu.grid(row = 0, column = 3, sticky = "wens") rootwindow.columnconfigure(3, weight = 1)
  • 8. checkfill = tkinter.IntVar() fillcheck = tkinter.Checkbutton(rootwindow, text = "Fill Circle", variable = checkfill, bg = "grey") fillcheck.grid(row = 0, column = 4, sticky = "wens") rootwindow.columnconfigure(4, weight = 1) circlecanvas = tkinter.Canvas(rootwindow, height = 400, width = 600, bg = "grey") circlecanvas.grid(row = 1, column = 0, columnspan = 5, sticky = "wens") rootwindow.rowconfigure(1, weight = 4) circlecanvas.bind("<Button-1>", hitbutton1) circlecanvas.bind("<Button-2>", hitbutton3) circlecanvas.bind("a", hitkeya) circlecanvas.bind("d", hitkeyd) circlecanvas.bind("m", hitkeym) circlecanvas.focus_set() rootwindow.mainloop() pongball(1).py #!/usr/local/bin/python3 import tkinter import tkinter.messagebox import math import PIL.Image import PIL.ImageTk import time import random random.seed()
  • 9. i = 0 deltax = random.randint(1,3) deltay = random.randint(-3,3) def moveit2 () : global loadedimage3, tkimage3, i, deltax, deltay delay = 30 if i >= 24 : i = 0 balllocation = circlecanvas.coords(imageid) paddlelocation = circlecanvas.coords(paddleid) if balllocation[1] > paddlelocation[1] - 20 and balllocation[1] < paddlelocation[1] + 20 and balllocation[0] + 37 >= paddlelocation[0] - 2 : deltax = -deltax if balllocation[0] >= 565 : circlecanvas.coords(imageid, (300,200)) deltax = random.randint(1,3) deltay = random.randint(-3,3) delay = 1000 if balllocation[0] <= 37 : deltax = -deltax if balllocation[1] >= 365 : deltay = -deltay if balllocation[1] <= 37 : deltay = -deltay
  • 10. loadedimage3.seek(i) tkimage3 = PIL.ImageTk.PhotoImage(loadedimage3) circlecanvas.itemconfig(imageid, image = tkimage3) circlecanvas.move(imageid, deltax, deltay) i += 1 rootwindow.after(delay, moveit2) def moveit () : rootwindow.after(1000, moveit2) def hitkeyup (ev) : circlecanvas.move(paddleid, 0, -8) def hitkeydown (ev) : circlecanvas.move(paddleid, 0, 8) rootwindow = tkinter.Tk() rootwindow.title("Pong") rootwindow.lift() rootwindow.config(height = 200, width = 400, bg = "pink") loadedimage = PIL.Image.open("dummyimage.jpg") loadedimage.thumbnail((40,40)) tkimage = PIL.ImageTk.PhotoImage(loadedimage) radiuslabel = tkinter.Label(rootwindow, image = tkimage) radiuslabel.grid(row = 0, column = 0, sticky = "wens") rootwindow.columnconfigure(0, weight = 1) rootwindow.rowconfigure(0, weight = 1) loadedimage2 = PIL.Image.open("blob.png") loadedimage2.thumbnail((30,30)) tkimage2 = PIL.ImageTk.PhotoImage(loadedimage2)
  • 11. startbutton = tkinter.Button(rootwindow, image = tkimage2, command = moveit) startbutton.grid(row = 0, column = 1, sticky = "wens") rootwindow.columnconfigure(1, weight = 1) circlecanvas = tkinter.Canvas(rootwindow, height = 400, width = 600, bg = "grey") circlecanvas.grid(row = 1, column = 0, columnspan = 2, sticky = "wens") rootwindow.rowconfigure(1, weight = 4) loadedimage3 = PIL.Image.open("Downloads/animated-ball- image-0046.gif") tkimage3 = PIL.ImageTk.PhotoImage(loadedimage3) imageid = circlecanvas.create_image(300,200, image = tkimage3) paddleid = circlecanvas.create_image(500,200, image = tkimage) circlecanvas.bind("<Up>", hitkeyup) circlecanvas.bind("<Down>", hitkeydown) circlecanvas.focus_set() rootwindow.mainloop() pongball.py #!/usr/local/bin/python3 import tkinter import tkinter.messagebox import math import PIL.Image
  • 12. import PIL.ImageTk import time # circlecanvas.move(delid, ev.x - centerx, ev.y - centery) def moveit () : pass #def hitkeya (ev) : #global state #state = "add" rootwindow = tkinter.Tk() rootwindow.title("Pong") rootwindow.lift() rootwindow.config(height = 200, width = 400, bg = "pink") loadedimage = PIL.Image.open("dummyimage.jpg") loadedimage.thumbnail((40,40)) tkimage = PIL.ImageTk.PhotoImage(loadedimage) radiuslabel = tkinter.Label(rootwindow, image = tkimage) radiuslabel.grid(row = 0, column = 0, sticky = "wens") rootwindow.columnconfigure(0, weight = 1) rootwindow.rowconfigure(0, weight = 1) loadedimage2 = PIL.Image.open("blob.png") loadedimage2.thumbnail((30,30)) tkimage2 = PIL.ImageTk.PhotoImage(loadedimage2) startbutton = tkinter.Button(rootwindow, image = tkimage2, command = moveit) startbutton.grid(row = 0, column = 1, sticky = "wens") rootwindow.columnconfigure(1, weight = 1)
  • 13. circlecanvas = tkinter.Canvas(rootwindow, height = 400, width = 600, bg = "grey") circlecanvas.grid(row = 1, column = 0, columnspan = 2, sticky = "wens") rootwindow.rowconfigure(1, weight = 4) loadedimage3 = PIL.Image.open("Downloads/animated-ball- image-0046.gif") for i in range (0,24) : loadedimage3.seek(i) tkimage3 = PIL.ImageTk.PhotoImage(loadedimage3) circlecanvas.create_image(300,200, image = tkimage3) #circlecanvas.bind("<Button-1>", hitbutton1) #circlecanvas.bind("<Button-2>", hitbutton3) #circlecanvas.bind("a", hitkeya) #circlecanvas.bind("d", hitkeyd) #circlecanvas.bind("m", hitkeym) #circlecanvas.focus_set() rootwindow.mainloop() selectcircles.py #!/usr/local/bin/python3 import sqlite3 import random random.seed() db = sqlite3.connect("circles.db") curs = db.cursor()
  • 14. #curs.execute("create table circles (x integer, y integer, r integer, color text, fill integer)") #circlist = [] #for i in range(0,100) : #circlist.append((random.randint(0,600), random.randint(0,400), random.randint(5,50), random.choice(["red","blue","green","yellow","orange","purple" ,"pink","black"]), random.randint(0,1))) #curs.executemany("insert into circles (x,y,r,color,fill) values (?,?,?,?,?)", circlist) #db.commit() data = curs.execute("select * from circles where r > 25 or fill == 1 order by r desc") for item in data : print("x =", item[0], "y =", item[1], "r =", item[2], "color =", item[3], "fill =", item[4]) db.close() showcircles(1).py #!/usr/local/bin/python3 import tkinter import tkinter.messagebox import math import sqlite3 import random
  • 15. random.seed() def createdb() : db = sqlite3.connect("circles.db") curs = db.cursor() curs.execute("create table if not exists circles (x integer, y integer, r integer, color text, fill integer)") circlist = [] for i in range(0,100) : circlist.append((random.randint(0,600), random.randint(0,400), random.randint(5,50), random.choice(["red","blue","green","yellow","orange","purple" ,"pink","black"]), random.randint(0,1))) curs.executemany("insert into circles (x,y,r,color,fill) values (?,?,?,?,?)", circlist) db.commit() db.close() def selectdb() : db = sqlite3.connect("circles.db") curs = db.cursor() query = "select * from circles where r >= " + str(radius.get()) if color.get() != "none" : query += " and color == '" + color.get() + "'" if checkfill.get() != -1 :
  • 16. query += " and fill == " + str(checkfill.get()) circlist = curs.execute(query) circlecanvas.delete("all") for circ in circlist : ulx = circ[0] - circ[2] uly = circ[1] - circ[2] lrx = circ[0] + circ[2] lry = circ[1] + circ[2] if circ[4] : fillit = circ[3] else : fillit = "" circlecanvas.create_oval(ulx,uly,lrx,lry,outline = circ[3], fill = fillit) db.close() rootwindow = tkinter.Tk() rootwindow.title("Showing Circles") rootwindow.lift() rootwindow.config(height = 400, width = 600, bg = "pink") radiuslabel = tkinter.Label(rootwindow, text = "Radius:", bg = "grey") radiuslabel.grid(row = 0, column = 0, sticky = "wens") rootwindow.columnconfigure(0, weight = 1) rootwindow.rowconfigure(0, weight = 1) radius = tkinter.IntVar() radiusslider = tkinter.Scale(rootwindow, from_ = 5, to = 50, variable = radius, bg = "green", orient = tkinter.HORIZONTAL) radiusslider.grid(row = 0, column = 1, sticky = "wens") rootwindow.columnconfigure(1, weight = 1)
  • 17. colorlabel = tkinter.Label(rootwindow, text = "Color:", bg = "grey") colorlabel.grid(row = 0, column = 2, sticky = "wens") rootwindow.columnconfigure(2, weight = 1) color = tkinter.StringVar() color.set("none") colors = [ "none", "red", "green", "blue", "orange", "yellow", "purple", "pink", "black" ] colormenu = tkinter.OptionMenu(rootwindow, color, *colors) colormenu.grid(row = 0, column = 3, sticky = "wens") rootwindow.columnconfigure(3, weight = 1) checkfill = tkinter.IntVar() fillcheck1 = tkinter.Radiobutton(rootwindow, text = "None", variable = checkfill, value = -1, bg = "grey") fillcheck1.grid(row = 0, column = 4, sticky = "wens") rootwindow.columnconfigure(4, weight = 1) fillcheck2 = tkinter.Radiobutton(rootwindow, text = "Filled", variable = checkfill, value = 1, bg = "grey") fillcheck2.grid(row = 0, column = 5, sticky = "wens") rootwindow.columnconfigure(5, weight = 1) fillcheck3 = tkinter.Radiobutton(rootwindow, text = "Not Filled", variable = checkfill, value = 0, bg = "grey") fillcheck3.grid(row = 0, column = 6, sticky = "wens") rootwindow.columnconfigure(6, weight = 1) startbutton = tkinter.Button(rootwindow, text = "Start", command = createdb) startbutton.grid(row = 0, column = 7, sticky = "wens") rootwindow.columnconfigure(7, weight = 1) getbutton = tkinter.Button(rootwindow, text = "Select", command = selectdb) getbutton.grid(row = 0, column = 8, sticky = "wens")
  • 18. rootwindow.columnconfigure(8, weight = 1) circlecanvas = tkinter.Canvas(rootwindow, height = 400, width = 600, bg = "grey") circlecanvas.grid(row = 1, column = 0, columnspan = 9, sticky = "wens") rootwindow.rowconfigure(1, weight = 4) rootwindow.mainloop() weathergui(1).py #!/usr/local/bin/python3 import tkinter import tkinter.messagebox import urllib.request import json def getreport () : if len(zipcode.get()) == 5 and zipcode.get().isdigit() : requesturl = "http://api.openweathermap.org/data/2.5/weather?zip="+zipcode .get()+",us&mode=json&units=metric&APPID=b0d45b8cc18faf 92d77e9825fd5aae74" try : urlobject = urllib.request.urlopen(requesturl) except BaseException as e: tkinter.messagebox.showerror("Url Error", "Bad Url" + e + ". Try again.") return if urlobject.getcode() == 200: response = urlobject.read()
  • 19. response = response.decode("utf-8") jsonresponse = json.loads(response) temperature = jsonresponse['main']['temp'] humidity = jsonresponse['main']['humidity'] pressure = jsonresponse['main']['pressure'] place = jsonresponse['name'] windspeed = jsonresponse['wind']['speed'] if 'deg' in jsonresponse['wind'].keys() : winddir = jsonresponse['wind']['deg'] windnames = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW', 'N' ] index = int((winddir + 11.25) / 22.5) windname = windnames[index] else : windname = "nowhere" outstring = "The weather conditions in " + place + "n" outstring += "Temperature = " + str(temperature) + " degrees Celciusn" outstring += "Humidity = " + str(humidity) + " %n" outstring += "Barometric pressure = " + str(pressure) + " millibarsn" outstring += "Wind is at " + str(windspeed) + " km/h from " + windname weatherreport.set(outstring) else : tkinter.messagebox.showerror("Zipcode Error", "The value you entered -" + zipcode.get() + "- is not a valid zipcode. Try again.") rootwindow = tkinter.Tk() rootwindow.title("The Weather Reporter")
  • 20. rootwindow.lift() rootwindow.config(height = 200, width = 400, bg = "pink") instructions = tkinter.Label(rootwindow, text = "Welcome to the weather reporter. Please enter a zipcode for the location of your weather report.", wraplength = 300, justify = "left") instructions.grid(row = 0, column = 0, columnspan = 3, sticky = "wens") rootwindow.columnconfigure(0, weight = 1) rootwindow.rowconfigure(0, weight = 1) ziplabel = tkinter.Label(rootwindow, text = "Zipcode:", bg = "green") ziplabel.grid(row = 1, column = 0, sticky = "wens") rootwindow.rowconfigure(1, weight = 2) zipcode = tkinter.StringVar() zipentry = tkinter.Entry(rootwindow, bg = "blue", fg = "red", textvariable = zipcode) zipentry.grid(row = 1, column = 1, sticky = "wens") rootwindow.columnconfigure(1, weight = 1) gobutton = tkinter.Button(rootwindow, text = "Hit Me", command = getreport) gobutton.grid(row = 1, column = 2, sticky = "wens") rootwindow.columnconfigure(2, weight = 1) weatherreport = tkinter.StringVar() outputreport = tkinter.Message(rootwindow, textvariable = weatherreport, width=300) outputreport.grid(row = 2, column = 0, columnspan = 3, sticky = "wens") rootwindow.rowconfigure(2, weight = 3) rootwindow.mainloop()
  • 21. Michael Lay G00129687 Lab 2 Grantham University Introduction The purpose of this lab exercise is to build a half wave rectifier and a full wave rectifier in MULTISIM and on a breadboard. The various output voltage are to be measured. The myDAQ is to be used for data acquisition from the breadboard to the MULTISIM software. The calculate values are to be compared with the measured values to check for consistency. Equipment/components used Materials: 1. Simulated Parts (Multisim): 1. 10:1 center-tapped transformer
  • 22. 1. Two diodes 1N4001 1. Two 2.2 kΩ resistors 1. One 100 μF, 50 V electrolytic capacitor 1. One fuse (any rating is fine since it is for simulation only) 1. Hardware Parts (In the Toolbox): 1. Two diodes 1N4001 1. Two 2.2 kΩ resistors 1. One 100 μF, 50 V electrolytic capacitor 1. Virtual Instruments (Multisim): 1. Function Generator (Multisim) 1. Function Generator (NI Elvisms Instrument Launcher) 1. Arbitrary Waveform Generator (NI Elvismx Instrument Launcher) 1. Tektronix oscilloscope (Multisim) 1. Oscilloscope (NI Elvismx Instrument Launcher) 1. Hardware Equipment: 1. Breadboard 1. NI myDAQ Instrument Device 1. Screw Driver 1. Screw Terminal connector 1. Jumper wires Problem statement The circuits shown in the figure below both for the half-wave rectifier and a full wave rectifier are to be constructed in MULTISIM and on a breadboard. Theoretical solution For the half wave rectifier the calculations are done as follows: Without filter capacitor The input voltage is 30V rms. The transformer has a turn-ratio of 10:1 The secondary RMS voltage is: 30V/10=3VRMS The peak secondary voltage is equal to 3*sqrt(2)= 4.2426V The peak load voltage is equal to 4.2426-0.7V=3.5426
  • 23. The RMS load voltage is equal to The average DC voltage is equal to The peak to peak ripple voltage is equal to: 3.5426-0=3.5426V The ripple frequency is equal to the source frequency=60Hz Half wave rectifier with the filter capacitor: The filter capacitor is equal to 100uF: The ripple voltage is equal to FULL wave rectifier calculations: The source voltage is equal to 30V rms. The turns-ratio of the transformer is 10:1 The secondary voltage is equal to 30V/(10*2)=1.5V The peak secondary voltage is equal to 1.5*sqrt(2)= 2.1213V The peak load voltage is equal to 2.1213-0.7=1.4213V The RMS load voltage is equal to 1.4213/sqrt(2)=1.005V The average DC load voltage is equal to: 0.637*1.4213= 0.9054V The peak to peak ripple voltage is equal to 1.4213V- 0V=1.4213V With the filter capacitor The ripple frequency is equal to 2*F=1*60Hz=120Hz The peak to peak ripple voltage is equal to Experimental procedure Circuit design The half wave rectifier is constructed as shown in the figure below: The full-wave rectifier circuit is constructed as shown below: Execution/results Half wave rectifier MULTISIM measurements 1. RMS secondary voltage
  • 24. 1. RMS load voltage 1. Peak to peak ripple voltage 1. Ripple frequency 1. Peak to peak ripple voltage with the filter capacitor 1. Ripple frequency Half wave rectifier myDAQ measurements 1. Load voltage measurement 1. Secondary voltage measurement 1. Load voltage measurement with the filter capacitor Full wave rectifier MULTISIM measurements 1. RMS load voltage 1. Peak to peak ripple voltage 1. Ripple frequency 1. Peak to peak voltage with filter capacitor 1. Ripple frequency Full wave rectifier myDAQ measurements 1. Load voltage without the filter capacitor 1. Load voltage with the filter capacitor Analysis
  • 25. The measured and the calculated values were summarized in the tables below: 1. Half –wave rectifier Parameter Calculated value Multisim value NI myDAQ value RMS load voltage 1.7713V 1.4V 1.756V RMS secondary voltage 3V 3V 3V Ripple voltage 3.5426V 3.68V 3.682V Ripple frequency 60Hz 60Hz 60Hz Ripple voltage with capacitor 267mV 217mV 216.85mV Ripple frequency with capacitor 60Hz 60Hz 60Hz
  • 26. 1. Full wave rectifier values Parameter Calculated value Multisim value NI myDAQ value RMS load voltage 1.005V 561mV 1.046V RMS secondary voltage 1.5V 1.5V 1.5V Ripple voltage 1.4213V 1.6V 1.594V Ripple frequency 120Hz 120Hz 120Hz Ripple voltage with capacitor 53.8mV 40.7mV 40.45mV Ripple frequency with capacitor 120Hz 120Hz 120Hz Review questions Part 1 1. What is the purpose of having a half-wave rectifier in the
  • 27. circuit? It converts the positive going cycles of an alternating AC voltage into a pulsating DC voltage. 1. Describe the procedure in this lab to arrive at the final design of both the hardware portion and the software portion to achieve the design objectives? The connections on the breadboard and in the MULTISIM software were done as per the connection diagram. 1. Discuss the impact of having the capacitor on the output voltage and the effect of additional load on the ripple voltage. The function of the capacitor is to reduce the ripples in the output voltage and make it more like a DC voltage. Part 2 1. What is the purpose of having a full-wave rectifier in the circuit? A full-wave rectifier converts the alternating AC voltage into a pulsating DC voltage. It conducts for both the positive going cycle and the negative going cycle. 1. Describe the procedure in this lab to arrive at the final design of both the hardware portion and the software portion to achieve the design objectives? The connections on the breadboard and in the MULTISIM software were done as per the connection diagram. 1. Discuss the impact of having the capacitor on the output voltage and the effect of additional load on the ripple voltage. The function of the capacitor is to reduce the ripples in the output voltage and make it more like a DC voltage. 1. How is the output of the full-wave rectifier different from half-wave rectifier? The output voltage of a full wave rectifier is more linear than the output voltage of a half wave rectifier. Conclusion
  • 28. This lab exercise was a good insight in the study and design of a half wave rectifier and a full wave rectifier. The measured values and the calculated values were very close to each other and thus the lab exercise was a success. Electronics I and Lab Bridge Rectifier Introduction: Week 3 lab is based on the previous lab from week 2 on half- wave and full-wave rectifiers and taking that knowledge to build a bridge rectifier. Materials and Equipment: Materials: · Simulated Parts (Multisim): . A 30/3 Vrms center-tapped transformer . Two diodes 1N4001 . Two 2.2 kΩ resistors . One 100 μF, 50 V electrolytic capacitor (any voltage rating is fine since is simulation only) . One fuse (any rating is fine since is simulation only) Equipment: · Virtual Instruments (Multisim): . Tektronix Oscilloscope . Agilent Multimeter . Agilent Function generator Procedure: *** This lab has to be implemented only in software (running simulations on Multisim)*** 1. Construct the bridge rectifier circuit shown in Figure 1. Notice that no terminal of the transformer secondary is at ground potential (some simulation software will not run if it is not connected to the ground, check yours). The input voltage to the bridge, VSEC, is not referenced to ground. Make sure to include resistor tolerance of 5%. 2. Use a function generator to provide VAC and run the
  • 29. simulation. 3. Use a multimeter to measure VSEC (rms) and then use the oscilloscope to measure the peak output voltage (VLOAD) without a filter capacitor. Tabulate all data gathered. Figure 1 4. Connect the 100 μF capacitor in parallel with the load resistor. Measure VLOAD, the peak-to-peak ripple voltage VRIPPLE, and the ripple frequency. Tabulate all data gathered and compare the results with and without the filter capacitor. Without the capacitor With the capacitor Output load voltage VLOAD Peak-to-peak ripple voltage VRIPPLE Ripple frequency 5. Choose a diode among the four connected to the bridge and open it. Simulate an open diode in the bridge and explain what happens to the output voltage, the ripple voltage and the ripple frequency? 6. Investigate the effect of the load resistor on the ripple voltage by connecting a second 2.2 kΩ, 5% tolerance, and load resistor in parallel with RL and C1 in the full-wave circuit of Figure 3. Measure the ripple voltage. Captures a screenshot. Review questions: 1. Compare a bridge rectifier circuit with full-wave rectifier center-tapped circuit which you did in Lab 2. Which circuit has the higher output voltage? 2. Explain how you could measure the ripple frequency to determine if a diode were open in a bridge rectifier circuit.
  • 30. 3. What is the maximum dc voltage you could expect to obtain from a transformer with a 3 Vrms secondary using a bridge circuit with a filter capacitor? Deliverables: 1. Measure the voltage VSEC and the output load voltage, VLOAD without a filter capacitor. Capture the screenshots of your measurements. 2. Measure the output load voltage, VLOAD, with the capacitor and the peak-to-peak ripple voltage, VRIPPLE, in the output. Capture the screenshots of your measurements. Also, measure the ripple frequency. Table with all the data gathered for the circuit with and without the capacitor. 3. Follow the template “Lab Report Template” to compile the report and make sure to check the report against the grading rubric below. The template can be found in the “Tools and Templates” link in the navigation center. 4. Make sure to include the table, calculations, screenshots of the measurements and the answer to the questions. Save the document as Lab2YourGID.docx (ex: Lab3G00000000.docx). Grading Criteria Points Construct bridge rectifier circuit in Multisim without a capacitor 15 Measurement of VSEC and VLOAD voltages with screenshots 10 Construct bridge rectifier circuit in Multisim with a capacitor 10 Measurement of VSEC, VLOAD and VRIPPLE voltages with screenshots 15 Simulation with an open diode and measurement with screenshots 20 Including 5% tolerances in the measurements 10
  • 31. Review Questions 10 Report format (Proper use of template) 10 TOTAL 100