Advertisement
phjoe

Cur_IMG

Jan 28th, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import appuifw as A
  2. import graphics as G
  3. import keyboard
  4.  
  5. run=1
  6. kb=keyboard.Keyboard()
  7. W,H=G.sysinfo.display_pixels()
  8. img=G.Image.new((W,H))
  9.  
  10. gb=G.Image.open(u'e:\\Fotonya.jpg') # edit
  11.  
  12. def stop():
  13.  global run;run=0
  14.  
  15. def redraw(x):
  16.  if img:c.blit(img)
  17.  
  18. A.app.screen='full'
  19. c = A.Canvas(redraw_callback=redraw,event_callback=kb.handle_event)
  20. A.app.body=c
  21. A.app.exit_key_handler=stop
  22.  
  23. cx,cy=W/2,H/2
  24.  
  25. # kursor
  26. lebar,tinggi=40,40
  27. curx,cury=0,0
  28. posx,posy=0,0
  29. speed=2
  30.  
  31. def handle():
  32.  global curx,cury,posx,posy
  33.  if kb.is_down(0x34): # 4 kiri
  34.   curx-=speed
  35.   if curx <0:
  36.    curx=0
  37.    posx+=speed
  38.    if posx>0:
  39.     posx=0
  40.  elif kb.is_down(0x36): # 6 kanan
  41.   curx+=speed
  42.   if curx+lebar>W:
  43.    curx=W-lebar
  44.    posx-=speed
  45.    if posx<-(gb.size[0]-W):
  46.     posx=-(gb.size[0]-W)
  47.  if kb.is_down(0x32): # 2 atas
  48.   cury-=speed
  49.   if cury <0:
  50.    cury=0
  51.    posy+=speed
  52.    if posy>0:
  53.     posy=0
  54.  elif kb.is_down(0x38): # 8 bawah
  55.   cury+=speed
  56.   if cury+tinggi>H:
  57.    cury=H-tinggi
  58.    posy-=speed
  59.    if posy<-(gb.size[1]-H):
  60.     posy=-(gb.size[1]-H)
  61.  
  62. while run:
  63.  img.clear(0)
  64.  img.blit(gb,target=(posx,posy))
  65.  img.rectangle((curx,cury,curx+lebar,cury+tinggi),0xff0000)
  66.  redraw(0)
  67.  A.e32.ao_sleep(1e-04)
  68.  handle()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement