Re: [Tutor] images

2018-07-25 Thread Beck, Caroline
Hi! I am a student working on a game in which I am trying to use a gif as my 
turtle. Currently, the turtle moves around the screen with the arrow keys, but 
the gif does not move with it. Below is how I have tried to tell the code that 
the gif is the turtle, but the code is not reading that the gif is my turtle. I 
was wondering if I could have some help with making the gif in my code to read 
as my turtle.
Thank you!

Here is my code so far:
import random
import turtle as t

screen = t.Screen()
screen.setup(1250,900)
screen.bgpic("newbackground.gif")

screen.addshape("shark.gif")
t.shape("shark.gif")
shark = t.Turtle()
shark.speed(0)
shark.penup()
shark.hideturtle()

leaf = t.Turtle()
leaf_shape = ((0,0), (14,2), (18,6), (20,20),(6,18), (2,14))
t.register_shape('leaf', leaf_shape)
leaf.shape('leaf')
leaf.color('orange')
leaf.penup()
leaf.hideturtle()
leaf.speed(0)


game_started = False
text_turtle = t.Turtle()
text_turtle.write('Press SPACE to start', align='center', 
font=('Arial',16,'bold'))
text_turtle.hideturtle()

score_turtle = t.Turtle()
score_turtle.hideturtle()
score_turtle.speed(0)

def outside_window():
left_wall = -t.window_width() / 2
right_wall = t.window_width() / 2
top_wall = t.window_height() / 2
bottom_wall = -t.window_height() / 2
(x,y) = t.pos()
outside = \
x< left_wall or \
x> right_wall or \
y< bottom_wall or \
y> top_wall
return outside

def game_over():
t.penup()
t.hideturtle()
t.write('GAME OVER!', align='center', font=('Arial', 30, 'normal'))

def display_score(current_score):
score_turtle.clear()
score_turtle.penup()
x = (t.window_width()/2) - 50
y = (t.window_height()/2) - 50
score_turtle.setpos(x, y)
score_turtle.write(str(current_score), align='right',font=('Arial', 40, 
'bold'))

def place_leaf():
leaf.ht()
leaf.setx(random.randint(-200,200))
leaf.sety(random.randint(-200,200))
leaf.st()

def start_game():
global game_started
if game_started:
return
game_started = True

score=0
text_turtle.clear

shark_speed = 2
shark_length = 3
shark.shapesize(1, shark_length,1)
shark.showturtle()
display_score(score)
place_leaf()

while True:
shark.forward(shark_speed)
if shark.distance(leaf) < 20:
place_leaf()
#shark_length=t_length + 1
#shark.shapesize(1, t_length, 1)
shark_speed=shark_speed + 1
score = score + 10
display_score(score)
if outside_window():
game_over()
break

def move_up():
if shark.heading() == 0 or shark.heading() == 180:
shark.setheading(90)

def move_down():
if shark.heading() == 0 or shark.heading() == 180:
shark.setheading(270)

def move_left():
if shark.heading() == 90 or shark.heading() == 270:
shark.setheading(180)

def move_right():
if shark.heading() == 90 or shark.heading() == 270:
shark.setheading(0)
t.onkey(start_game, 'space')
t.onkey(move_up, 'Up')
t.onkey(move_right, 'Right')
t.onkey(move_down, 'Down')
t.onkey(move_left, 'Left')
t.listen()
t.mainloop()

From: Crystal Frommert 
Sent: Tuesday, July 24, 2018 1:11 PM
To: Beck, Caroline 
Subject: images

Try a gif image instead of png
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Images on Python 3k

2010-01-16 Thread Alan Gauld


Luhmann luhmann...@yahoo.com wrote

I have only started using python after Py3 was released, so this is is 
the only version I know. I have tried to make my code work in 
Python 2 so I could use PIL, 


This is one of the biggest barriers to adopting Python 3. Until PIL 
gets ported it's a non starter for many folks.


And why Tk doesn't support formats other than GIF and PPM for 
its PhotoImage widget is a long standing mystery! Thee has been 
much talk of supporting JPG but nothing has ever materialised.


Alan G.


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Images, and other things.

2009-10-02 Thread Kent Johnson
On Tue, Sep 29, 2009 at 7:00 PM, Corey Richardson kb1...@aim.com wrote:
 I haven't looked into this, but could you make a real time image using
 python? I think it would be most hard
 Anyway, I am having trouble with int(). I am trying to int(raw_input(some
 number)), but it returns
 Traceback (most recent call last):
  File C:/Users/Quick-Start/Documents/Python Doc's/Game_File, line 94, in
 module
   fatness = int(raw_input(How many candies do you want to eat? :))
 TypeError: 'int' object is not callable

You probably have a line like
  int = 3
in your program which rebinds the built-in int() function to a
(non-callable) int object.

Showing the whole program would help.

Kent
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Images, and other things.

2009-09-29 Thread Luke Paireepinart
On Tue, Sep 29, 2009 at 6:00 PM, Corey Richardson kb1...@aim.com wrote:

 I haven't looked into this, but could you make a real time image using
 python? I think it would be most hard

I haven't looked into this, but perhaps your questions are too vague?  I
think that may be the case
 What do you mean by real-time image?

Anyway, I am having trouble with int(). I am trying to int(raw_input(some
 number)), but it returns
 Traceback (most recent call last):
  File C:/Users/Quick-Start/Documents/Python Doc's/Game_File, line 94, in
 module
   fatness = int(raw_input(How many candies do you want to eat? :))
 TypeError: 'int' object is not callable


 Do I need to import a module or something? I am using 2.6.2, possibly
 upgrading to 3.x later...

Give us your whole code, not just the traceback, and we will be more able to
help you.

Also, read  http://catb.org/~esr/faqs/smart-questions.html .  It will help
you get better, less sarcastic answers to your questions.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Images, and other things.

2009-09-29 Thread Luke Paireepinart
On Wed, Sep 30, 2009 at 1:29 AM, Corey Richardson kb1...@aim.com wrote:

 One of my friends was asking if you could make a game using python, but he
 meant a Graphics, not text game. I was wondering if that was doable.


Yes, there are many libraries available for doing this.  Pyglet is my
favorite, but Pygame and PyOGRE and Panda and many others exist.  It's not
just doable, it's probably preferable to write a game in Python.  It'll be
much quicker to finish it than most other languages.


 Anywaymy code.
 name = raw_input(What is your name?)
 print Hello, , name
 int = 10  #Define the abilities.

... and here's your problem.  You defined  a variable named int and you
hid the int function so when you tried to call int(something) you were
using this variable you just defined instead of the conversion function.

 str = 10

This is also a bad function name because str is the function to convert a
value to a string.

Also, make sure you reply using reply-all so your message goes to the list
rather than directly to me.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] images

2007-11-04 Thread John Fouhy
On 05/11/2007, SwartMumba snake [EMAIL PROTECTED] wrote:
 Hi

 I would like to know which is the best module to use, with regard to my
 needs:

 - I would like to read an image off a website
 e.g. http://www.examplecom/image/1/PNG/

 - I would then like to read the pixels and do other things to the image

For manipulating the image, your best bet is probably PIL (the Python
Image Library).

To get the image, if you know its URL, you can just use urllib or
urllib2 (in the standard library).  If you will need to do some
parsing to figure out what image you want, you could look into
BeautifulSoup.

HTH.

-- 
John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] images in pygame

2006-07-23 Thread R. Alan Monroe
Dunno if this is the best way, but it works...
Replace this:

 if events.key == K_DOWN:

with this:

 if events.key == K_DOWN and not imagerect.colliderect(imagerects):


Alan

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] images in pygame

2006-07-23 Thread Luke Paireepinart
the tutor mailing list didn't like the zip I attached, so here's the 
text of the e-mail I wrote to
Joe without the zip included.

start-
Pygame-specific questions should be posted to the pygame mailing list, 
not tutor, probably.
Joe F wrote:
 Hello, I have a code here. and I want to make the 
 rockwholescreen.gif blocked, but still displayed.  I want it so 
 001.png can't walk through that gif.  any ideas?

 import pygame, os, sys
 from pygame.locals import *
  
  
 pygame.init( )
  
 def _loadImages_ ( path, name ):
 image_obj   = os.path.join( path, name )
 image_load = pygame.image.load( image_obj )
  
 return image_load
why do you have underscores in the name of this function?
Usually underscores denote functions that are supposed to be private to 
a class,
I believe, and this function's not in a class at all!
also,there's no reason to create an 'image_load' variable.
return pygame.image.load( image_obj )
would do just as well.

  
 images_path  = './img/'
 images_dict= {}
 image_names = { 1:001.png, 2:rockwholescreen.gif }
  
 for dir, name in image_names.items( ):
 images_dict[dir] = _loadImages_( images_path, name )
this strikes me as a very odd way to handle image-loading.
if you're using integers as a reference for a dict why not just use
list indices?
#---
images_path = './img/'
image_names = ['001.png','rockwholescreen.gif']
images = [_loadImages_(images_path,name) for name in image_names]
#---
It took me a minute to figure out what you
were doing, and this way I think your intent is more clear.
  
 setwinsize = ( 640, 480 )
 windows= pygame.display.set_mode( setwinsize )
I'm guessing you're using a global 'setwinsize' so you don't hard-code 
in your resolution.
If you're going to do this, why not just put your globals at the top, so 
they're easier to change?
If you have to go hunting through your code for a global you want, it's 
just barely
better than hunting through your code to find the place where you need 
to change
the hardcoded value.
  
 #load First Image
 imageload  = images_dict[1]
 imagerect   = imageload.get_rect( 0, 0, * windows.get_size( ))
why not just use setwinsize here also instead of getting the size of the 
display surface?
it'll probably be faster.
also, I don't understand why you're doing get_rect on (0,0,640,480)
does get_rect select a subsurface of the image?
  
 #load Second Image
 imageloads = images_dict[2]
 imagerects  = pygame.Rect( 0, 448, * windows.get_size( ))
if you find yourself appending letters to variable names to distinguish 
them you're
probably at the point where you should be using lists.
If someone weren't reading your code very carefully they may get 
confused here
and think these variables are the same as the ones above.
Also, later in your code, you might get confused and use the wrong one
of these variables without even realizing and give yourself debugging 
headaches.
I don't understand what the * here is doing.  it doesn't seem to work 
for me.


  
 while True:
 events = pygame.event.wait( )
I'm pretty sure pygame.event.wait() blocks until if gets an event.
Think about this, is this really what you want?
If the user sits there not sending any events, the screen won't update,
but if they move their mouse, you'll get a lot of mousemovement events
and such, and then your program will be rapidly filling the whole screen
with the color (25,110,189) and re-blitting everything even though 
nothing moved.

  
 if events.type == pygame.QUIT:
 break
  
 if events.type == pygame.KEYDOWN:
 if events.key == K_DOWN:
 imagerect.move_ip( 0, 10 ); imageload = images_dict[1]
 if events.key == K_UP:
 imagerect.move_ip( 0, -10 ); imageload = images_dict[1]
 if events.key == K_RIGHT:
 imagerect.move_ip( 10, 0 ); imageload = images_dict[1]
 if events.key == K_LEFT:
 imagerect.move_ip( -10, 0 ); imageload = images_dict[1]

I don't think the escape key raises a pygame.QUIT so if you want the 
user to be
able to exit with the escape key, you should put
also, since you imported everything from pygame.locals you don't need a 
'pygame.' here
#--
if events.key == K_ESCAPE: break
#-
to get this effect.
  
  
 windows.fill(( 25, 110, 189 ))
 windows.blit( imageload, imagerect )
 windows.blit( imageloads, imagerects )
 pygame.display.flip( )
here you're not doing dirty-rect animation. you're just updating the 
whole screen every time
you get an event.
This is okay for an example but for a real game you'll need to use some 
form of
dirty-rect updating method if it needs good performance.
  
 print Image One Rect: %s \n % imagerect
 print Image Two Rect: %s \n % imagerects

 fonts = pygame.font.Font(None, 26)

 _colors_ = { black : (0, 0, 0),
 red : (255, 0, 0)
 }
again, why the underlines?  Are you trying to avoid a namespace collision?
 _text_ =