コード例 #1
0
def setup():
  global window, frameTimer, fadeRectangle, carvedPumpkin, questionIcon, pumpkinHitbox, text, musicSound, icon1, creeperX, creeperY, houseOpen, output
  
  cleanup()

  setMediaPath(pickAFolder())
  window = gui.Display("Minecard", 640,480)
  
  baseState = gui.Icon(getMediaPath("baseState.jpg"),640,480)
  window.add(baseState, 0, 0)
  
  carvedPumpkin = gui.Icon(getMediaPath("croppedPumpkinCarved.png"),640,480)
  
  pumpkinHitbox = gui.Rectangle(103,272,190,334,gui.Color(0,0,0,0),true,0)
  pumpkinHitbox.onMouseDown(carvePumpkin)
  pumpkinHitbox.onMouseEnter(questionOn)
  pumpkinHitbox.onMouseExit(questionOff)
  window.add(pumpkinHitbox)
  
  houseOpen = gui.Icon(getMediaPath("lightOnFixed.png"),640,480)
  
  doorHitbox = gui.Rectangle(395,233,479,275,gui.Color(0,0,0,0),true,0)
  doorHitbox.onMouseDown(openDoor)
  doorHitbox.onMouseEnter(questionOn2)
  doorHitbox.onMouseExit(questionOff)
  window.add(doorHitbox)
  
  icon1=gui.Icon(getMediaPath("creeper_0.png"))
  icon2=gui.Icon(getMediaPath("creeper_1.png"))
  icon3=gui.Icon(getMediaPath("creeper_2.png"))
  icon4=gui.Icon(getMediaPath("creeper_3.png"))
  #create output list
  output.append(icon1)
  output.append(icon2)
  output.append(icon3)
  output.append(icon4)
  #creeper coordinates
  creeperX=400
  creeperY=270

  window.remove(icon2)
  window.remove(icon3)
  window.remove(icon4)
  window.add(icon1,creeperX,creeperY)
  icon1.onMouseDown(startCreeperAnimation)

  fadeRectangle = gui.Rectangle(0,0,640,480,gui.Color(0,0,0,255),true,0)
  fadeRectangle.onMouseEnter(fadeInRectangle)
  window.add(fadeRectangle)
  
  questionIcon = gui.Icon(getMediaPath("question.png"), 50, 50)
  
  text = gui.Icon(getMediaPath("text.png"), 500, 57)
  
  frameTimer = timer.Timer(1000/60, update, [], true)
  frameTimer.start()
  musicSound = makeAndPlay(getMediaPath("minecraftmusic.wav"))
コード例 #2
0
ファイル: simulator.py プロジェクト: codyn-net/codyn
def setup_gui(data):
    b = gui.Box(orientation=gui.Box.HORIZONTAL)
    b.background = gui.BoxTexture('gui.atlas:bar', [-1], [-1, 1])
    b.padding = gui.Rect(6, 6, 6, 6)
    b.alignment.y = 1
    b.fill.x = True
    b.homogeneous = False
    b.spacing = 6

    play = gui.Button(icon='gui.atlas:play')
    b.add(play)

    step = gui.Button(icon='gui.atlas:step')
    b.add(step)

    la = gui.Widget(alignment=gui.Alignment(1, 0.5), fill=gui.Fill(True, True))

    l = gui.Label(text='time: {:>6.3f}'.format(0))
    l.color = gui.Color(1, 1, 1, 1)
    l.padding = gui.Rect.uniform(3)
    l.alignment = gui.Alignment(1, 0.5)

    la.add(l)
    b.add(la)

    data.gui.add(b)
    data.lbl_time = l
コード例 #3
0
def fadeInRectangle(x,y):
  global isRectangleFading, howFaded
  if isRectangleFading == False:
    makeAndPlay(getMediaPath("thunder1.wav"))
    isRectangleFading = True
    howFaded = 120
    fadeRectangle.setColor(gui.Color(0,0,0,255))
コード例 #4
0
 def __init__(self,json):
    #For convenience
    path = os.path.dirname(os.path.realpath(__file__))
    #Keep references to all important information
    self.data = json
    self.name = json["name"]
    #Limit the length of the artist name.
    maxNameLength = 17
    if(len(self.name)>maxNameLength):
       self.name = self.name[0:maxNameLength] + "..."
    #Create the labels for use later
    self.nameLabel = gui.Label(self.name,gui.LEFT,gui.Color(255,255,255))
    self.nameLabel.setFont(gui.Font("Futura", gui.Font.ITALIC, 18))
    #Download and create an icon for the album art.
    getImage(json["images"][1]["url"], "albumArtCache.jpg")
    self.art = gui.Icon(path + "/cache/albumArtCache.jpg",60)
    self.totalTracks = json["total_tracks"]
    self.releaseDate = str(json["release_date"])
    self.albumID = str(json["id"])
    #Search and store the entire tracklist of the album.
    self.albumTracksSearch = spotify.album_tracks(self.albumID, limit=50, offset=0)
    self.tracks = []
    for trackData in self.albumTracksSearch["items"]:
       newTrack = AlbumTrack(trackData)
       self.tracks.append(newTrack)
    #Create an empty space for an AudioSample to go in later.
    self.aSample = None
    #Set up an event handler to the method previewSong.
    self.art.onMouseDown(self.previewSong)
    #Keep a reference to this object in the class.
    Album.albums.append(self)
    #Make sure we display only 3 albums.
    if(len(Album.albums)<=3):
       #Display the album!
       window.add(self.art,50,325+(len(Album.albums)-1)*75)
       window.add(self.nameLabel, 125, 350 +(len(Album.albums)-1)*75)
コード例 #5
0
def update():
  global fadeRectangle, isRectangleFading, isDoorOpen, isPumpkinCarved, howFaded, window, text, creeperAnimating, creeperFrame, creeperX, creeperY, output, creeperFrameDelay, textShown
  
  #Is our black screen fading in?
  if isRectangleFading == True:
    #If we should still be fading in, do
    if howFaded > 0:
      #Make a color based on how faded in we are
      fadeColor = gui.Color(0,0,0,(howFaded/120.0))
      fadeRectangle.setColor(fadeColor)
      #Make it more faded in
      howFaded = howFaded-1
    else:
      #We're done fading, so stop fading and delete the rectangle.
      isRectangleFading = False
      window.remove(fadeRectangle)
  
  #Check to make sure other elements have been clicked before showing text
  if isDoorOpen == true and isPumpkinCarved == true:
    if textShown == False:
      window.add(text, 80, 85)
      textShown = True
    
  #Change the creeper animation.
  if creeperAnimating == True:
    if creeperFrameDelay <= 0:
      lastCreeperFrame = creeperFrame
      creeperFrame=(creeperFrame+1)%4
      window.add(output[creeperFrame],creeperX,creeperY)
      window.remove(output[lastCreeperFrame])
      creeperFrameDelay = 4
    else:
      creeperFrameDelay = creeperFrameDelay-1
  #Run the update() function of every particle that exists currently.
  for particle in Particle.getParticles():
    particle.update()
コード例 #6
0
def randColor():
    r = randint(0, 255)
    g = randint(0, 255)
    b = randint(0, 255)
    color = gui.Color(r, g, b)
    return color
コード例 #7
0
import gui
from random import *
import timer
from time import sleep

#created by Kyra Moran and Patricia Chin
#created on 10/04/19
#JES 5
#This program creates a petri dish with animated microbes.

#create panel and petri dish
disp = gui.Display("petri dish", 500, 500, 0, 0, gui.Color.GRAY)
circle2 = gui.Oval(25, 25, 475, 475, gui.Color.WHITE, true)
disp.add(circle2)
circle = gui.Oval(40, 40, 460, 460, gui.Color(210, 180, 140), true)
disp.add(circle)


#define random color function
def randColor():
    r = randint(0, 255)
    g = randint(0, 255)
    b = randint(0, 255)
    color = gui.Color(r, g, b)
    return color


#create empty list to be appended later
MicrobeList = []

コード例 #8
0
def main():
   global window, requestWindow, artistField, removables
   if(window == None):
      window = gui.Display("spotiVis", getScreenWidth(), getScreenHeight(),0,0, gui.Color(60,60,60))
   #Run cleanup first, to make sure we have a clean slate to display on.
   cleanup()
   #Close the request window, the user shouldn't be asked to search once they already have!
   requestWindow.close()
   
   #Add a search button for future searches.
   searchButton = gui.Button("New Artist", searchRequest)
   window.add(searchButton, getScreenWidth()-155, 15)
   removables.append(searchButton)
   #Search for the artist on spotify
   searchName = artistField.getText()
   artistSearch = spotify.search(q='artist:' + searchName, type='artist')
   #If there aren't any results, start over!
   if(getMostPopularArtist(artistSearch) == -1):
      window = None
      searchRequest("That artist returned no results!", main)
      return -1
   artist = getMostPopularArtist(artistSearch)
   
   #Get number of followers
   artistFollowers = str(artist["followers"]["total"])
   
   #Get their icon
   artistImageURL = str(artist["images"][0]["url"])
   
   #Pulls the image from the internet. 
   getImage(artistImageURL, "artistImageCache.jpg")
   path = os.path.dirname(os.path.realpath(__file__))
   
   #Shorten the artists name if it happens to be too long
   artistName = str(artist["name"])
   maxNameLength = 15
   if(len(artistName)>maxNameLength):
      artistName = artistName[0:maxNameLength] + "..."
   
   #Add all static information to the window
   followerCount = gui.Label("Followers: "+ artistFollowers, gui.LEFT, gui.Color(255, 255, 255))
   followerCount.setFont(gui.Font("Futura", gui.Font.ITALIC, 24))
   artistImage = gui.Icon(path + "/cache/artistImageCache.jpg",300)
   artistLabel = gui.Label(artistName, gui.LEFT, gui.Color(255, 255, 255))
   artistLabel.setFont(gui.Font("Futura", gui.Font.BOLD, 100))
   genreLabel = gui.Label("Genre: " + str(artist["genres"][0]).title(), gui.LEFT, gui.Color(255, 255, 255))
   genreLabel.setFont(gui.Font("Futura", gui.Font.ITALIC, 36))
   
   window.add(artistImage, getScreenWidth() - 350, 50)
   window.add(artistLabel, 50, 20)
   window.add(genreLabel, 50, 150)
   window.add(followerCount, 50, 215)
   removables.append(artistImage)
   removables.append(artistLabel)
   removables.append(genreLabel)
   removables.append(followerCount)
   
   albumLabel = gui.Label("Top Albums:", gui.LEFT, gui.Color(255, 255, 255))
   albumLabel.setFont(gui.Font("Futura", gui.Font.BOLD, 20))
   window.add(albumLabel, 50, 275)
   removables.append(albumLabel)
   
   spotifyLogo = gui.Icon(path + "/spotifyLogo.png", 100)
   window.add(spotifyLogo, 50, getScreenHeight() - 250)
   removables.append(spotifyLogo)

   relatedArtistLabel = "Related Artists:"
   relatedLabel = gui.Label(relatedArtistLabel, gui.LEFT, gui.Color(255, 255, 255))
   relatedLabel.setFont(gui.Font("Futura", gui.Font.BOLD, 28))
   window.add(relatedLabel, getScreenWidth() - 550, 525)
   removables.append(relatedLabel)
   
   topTrackLabel="Top Tracks:"
   topLabel=gui.Label(topTrackLabel,gui.LEFT,gui.Color(255,255,255))
   topLabel.setFont(gui.Font("Futura",gui.Font.BOLD,20))
   window.add(topLabel, getScreenWidth()-1050, 275)
   removables.append(topLabel)
   
   #Find related artists from Spotify API
   relatedArtistSearch = spotify.artist_related_artists(artist["id"])
   relatedArtistSearch = relatedArtistSearch["artists"]
   relatedArtists = []
   #Only ever display 5 related artists, but allow fewer too.
   relatedArtistCount = None
   for relatedArtist in relatedArtistSearch:
      relatedArtists.append(relatedArtist)
   if(len(relatedArtists) >= 5):
         artistCount = 5
   else:
      artistCount = len(relatedArtists)
   #Display each related artist in a line, as well as their pictures.
   for i in range(artistCount):
      getImage(relatedArtists[i]["images"][0]["url"],"relatedArtistCache.jpg")
      relatedArtistIcon = gui.Icon(path + "/cache/relatedArtistCache.jpg",100)
      window.add(relatedArtistIcon, getScreenWidth() - 225 - i*125, 625)
      removables.append(relatedArtistIcon)
      relatedArtistName = relatedArtists[i]["name"]
      #Limit the length of the related artist name.
      maxNameLength = 10
      if(len(relatedArtistName)>maxNameLength):
         relatedArtistName = relatedArtistName[0:maxNameLength] + "..."
      relatedArtistNameLabel = gui.Label(relatedArtistName, gui.LEFT, gui.Color(255, 255, 255))
      window.add(relatedArtistNameLabel, getScreenWidth() - 225 - i*125, 600)
      removables.append(relatedArtistNameLabel)
   
   #Use the spotipy function to get JSON data for the artist's top tracks
   artistTrackSearch=spotify.artist_top_tracks(artist["id"],country='US')
   artistTracks=[]
   trackCount=None
   #Append all of the artist's top tracks to the list artistTracks
   for i in artistTrackSearch['tracks']:
      track= i
      artistTracks.append(i)
   #This loop is a safety in case the artist has less than 5 tracks released
   #Sets the number of tracks displayed to 5 unless there are less than 5, then set it to that number
   if(len(artistTracks)>=5):
      trackCount=5
   else:
      trackCount= len(artistTracks)
   #Incorporates GUI elemnts
   for i in range(trackCount):
      #pulls individual track names from the list artistTracks and gives them a number based on popularity
      trackName=str(i+1) + ". " + artistTracks[i]['name']
      maxNameLength = 25
      if(len(trackName)>maxNameLength):
         trackName = trackName[0:maxNameLength] + "..."
      trackNameLabel = gui.Label(trackName,gui.RIGHT,gui.Color(255,255,255))
      trackNameLabel.setFont(gui.Font("Futura", gui.Font.ITALIC, 20))
      window.add(trackNameLabel, getScreenWidth()-1050, 325 +i*50)
      removables.append(trackNameLabel)
   
   
   #Get the artists most recent albums in order.  
   artistAlbumSearch = spotify.artist_albums(artist["id"], album_type=None, country="US",limit=20,offset=0)
   artistAlbumSearch = artistAlbumSearch["items"]
   
   #Create a new Album object for each of these albums.
   for albumData in artistAlbumSearch:
      Album(albumData)
   
   #Return 0 if we are successful!
   return 0
コード例 #9
0
from random import randint

#----------------------------------------------
#    Config
#----------------------------------------------

config = {
    'name': 'Traptris',
    'worldSize': 500,
    'worldMarginX': 150,
    'worldMarginY': 20,
    'worldCenter': 250,
    'cellSize': 20,
    'columns': 10,
    'rows': 22,
    'background': gui.Color(50, 50, 50),
    'color': gui.Color(3, 248, 255)
}

#----------------------------------------------
#    Score Class
#----------------------------------------------


class Score:
    currentScore = 0
    scoreString = str(currentScore) + '           '
    scoreLabel = gui.Label(scoreString)
    fps = 1
    time = 0