# [Edu-sig] Introducing Python to Engineering Students

Warren Sande warren.sande at rogers.com
Tue Mar 11 05:20:02 CET 2008

```David,

For output graphics, you might want to have a look at Pygame.
It is a wrapper for the SDL library.  It has functionality for creating
graphics windows, drawing, sprites, etc.  But what might be of interest
for you is the simple set_at(x,y) method, to set the color of
individual pixels in a window.

I have found the Pygame documentation to be pretty good.

Here is a simple example of plotting a sinewave using set_at()

#-----------------------------
import pygame, sys, math
screen = pygame.display.set_mode([640,480])
for x in range(0, 640):
y = int(math.sin(x/640.0 * 4 * math.pi) * 200 + 240)

screen.set_at([x, y],[255,0,0])
pygame.display.flip()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
#------------------------------

Warren Sande

----- Original Message ----
From: David MacQuigg <macquigg at ece.arizona.edu>
To: edu-sig at python.org
Sent: Monday, March 10, 2008 10:28:21 PM
Subject: [Edu-sig] Introducing Python to Engineering Students

I've
been
to
give
an
intro
to
Python
for
a
freshman
class
with
150
students
at
University
of
Arizona.
The
class
is
taught
in
the
Electrical
and
Computer
Engineering
Department,
and
is
titled
Computer
Programming
for
Engineering
Applications.
The
language
is
C
(Hanly
&
Koffman,
Problem
Solving
and
Program
Design
in
C).

I
think
a
nice
way
to
do
this
will
be
an
application
where
we
can
show
the
of
both
languages
-
the
computation
of
Mandelbrot
images
http://en.wikipedia.org/wiki/Mandelbrot_set.
Python
will
provide
the
high-level
"glue"
which
brings
everything
together
in
a
nice
programming
environment,
and
C
will
provide
the
raw
power
for
the
loop
that
actually
computes
the
pixels.
My
initial
tests
show
this
loop
running
100
times
faster
in
C
than
in
Python.

The
challenge
is
to
do
this
without
overwhelming
the
students.
The
plan
is
to
make
everything
as
simple
as
possible,
just
the
instructions,
except
the
loop
itself,
which
the
students
will
write
in
C,
based
on
what
I
have
written
in
Python.
See
http://ece.arizona.edu/~edatools/ece175/projects/mandelbrots/mbrotHW.html.

Suggestions
are
welcome.
Has
anyone
done
something
like
this
before?
Can
you
improve
on
my
code
(I'm
not
a
Python
expert),
or
even
suggest
something
entirely
different?

There
is
one
major
piece
I
would
like
to
to
what
I
have
so
far
-
output
graphics.
This
demo
would
really
be
cool
if
the
students
could
see
these
glorious
images
appear
on
their
screen
of
an
array
of
numbers.
I
looked
at
the
Python
Imaging
Library
http://www.pythonware.com/products/pil/index.htm,
and
I
don't
see
any
examples
that
I
can
work
from
in
converting
an
array
of
numbers
into
an
image,
just
a
lot
of
dense
reference
material
that
assumes
I
know
these
image
data
formats.
Maybe
there
is
a
simpler
way.
Help
from
someone
with
experience
in
Python
graphics
would
be
most
appreciated.

--
Dave

_______________________________________________
Edu-sig
mailing
list
Edu-sig at python.org
http://mail.python.org/mailman/listinfo/edu-sig

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/edu-sig/attachments/20080310/ce6f8f1e/attachment.htm
```