omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular
    1. Home
    2. themusicman
    3. Posts

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    • Profile
    • Following 0
    • Followers 0
    • Topics 9
    • Posts 26
    • Best 1
    • Controversial 0
    • Groups 0

    Posts made by themusicman

    • RE: Transfer folder from iphone to ipad

      You can also use iCloud to share / move your Pythonista files between your iPhone, iPad and Mac. 👍

      posted in Pythonista
      themusicman
      themusicman
    • RE: Syntax for scene_drawing module...

      Thanks @jonb much appreciated. I’ve now managed to get the webIDE up and running, too!

      So, I have done some stuff using the spritenode system, and managed to pretty much successfully (well at least for me!) to get a version of connect4 coded and working using the default game/animation template as the start. However, I couldn’t find any way of drawing a simple line... surely I am missing something here Jon, and one should easily be able to do that somehow? Any pointers?

      posted in Pythonista
      themusicman
      themusicman
    • RE: How to add image(s) from iPad camera roll to Pythonista image library

      Thanks @cvp - when I checked originally, after adding the files via the method you describe, I wasn't seeing any files in the +, images, files area. However, and very typically... when I checked immediately after reading your last reply they are indeed there.

      Thanks again.

      posted in Pythonista
      themusicman
      themusicman
    • RE: How to add image(s) from iPad camera roll to Pythonista image library

      @cvp said:

      When you use the bottom right + button, you don’t import the icon but only it’s name that you can use as ui.Image. named(‘xxx’)

      Aha... thanks for the clarification. Is there a way one can add to the library of images/sounds etc available within Pythonista?

      I am not planning on using he UI module in this particular script, but have found a way of displaying and possibly using an image for a screen background using the PIL image library.

      posted in Pythonista
      themusicman
      themusicman
    • RE: How to add image(s) from iPad camera roll to Pythonista image library

      So @cvp - I have done this but I am not sure where the image I allegedly imported has been stored within Pythonista. When I try to select that image as I would for any image selection, the image does not appear anywhere.

      So, say I want to use 'emj:Black_Circle' as an image, when I click the bottom right to get the Pythonista dialogue box for adding new image / sound / colour / font etc, the image I just imported is nowhere to be found.

      Specifically, I want to add an image from my photo library to use as the background image for a Pythonista app.

      Am I doing this correctly?

      posted in Pythonista
      themusicman
      themusicman
    • Syntax for scene_drawing module...

      Hi All

      So I am trying to draw a simple line in Pythonista. I have selected a new game type template and the documentation states;

      scene_drawing — Drawing Functions for the scene module
      The functions in this module can be used within the scene.Scene.draw() method when using the classic render loop mode of the scene module.
      

      The default game/animation template is thus;

      from scene import *
      import sound
      import random
      import math
      
      A = Action
      
      class MyScene(Scene):
      	def setup(self):
      		pass
      
      	def did_change_size(self):
      		pass
      
      	def update(self):
      		pass
      
      	def touch_began(self, touch):
      		pass
      
      	def touch_moved(self, touch):
      		pass
      
      	def touch_ended(self, touch):
      		pass
      
      if __name__ == '__main__':
      	run(MyScene(), show_fps=False)
      
      

      From the documentation I think I need to set up a def draw(self): function, but I am not sure what the documentation means when it refers to the scene.Scene.draw() method when using the classic render loop mode of the scene module.

      Could someone help explain the syntax of what I need to include where please. Many thanks.

      posted in Pythonista
      themusicman
      themusicman
    • RE: [SOLVED] Calling methods every n seconds in scene.update()

      @Splefix said:

      @themusicman Haha brother, God just helped me figure that out myself! Thank you very much though for your answer! God bless you abundantly and may peace be with you!!!

      Nice meeting you brother!

      You're very welcome matey...

      posted in Pythonista
      themusicman
      themusicman
    • RE: [SOLVED] Calling methods every n seconds in scene.update()

      @Splefix - specifically for your example...

      # you will need the time module, so...
      import time
      
      # set the variable for your single timer
      last_task1=time.time()
      
      # then execute task1 every 1 second if 'your_statement' is true
      if your_statement == True:
          if time.time()-last_task1>=1:
              # run whatever code you need to execute every 1 second here
              # put your code for task1 here
      
              # then reset the timer for this task1
              last_task1=time.time()
      
      posted in Pythonista
      themusicman
      themusicman
    • RE: [SOLVED] Calling methods every n seconds in scene.update()

      So @Splefix - I have done something similar previously, where I needed to run different tasks at different intervals. Specifically, it was to upload IoT data from a pressure/temp/humidity sensor I have here, to an online MQTT server - but that is by the by.

      This script shows how to set up 3 separate timers for task1, task2 and task3 (obviously amend the number of variables for your specific requirements)

      # you will need the time module, so...
      import time
      
      # Then simply set up timers for each task you wish to run
      last_task1=time.time()
      last_task2=time.time()
      last_task3=time.time()
      
      # Execute specific tasks within each variable you have set up above
      
      # to execute task1 every 5 seconds
      if time.time()-last_task1>=5: 
          # run whatever code you need to execute every 5 seconds here
          # put your code for task1 here
          
          # then reset the timer for this task1
          last_task1=time.time()
          
      
      # to execute task2 every 300 seconds
      if time.time()-last_task2>300: 
          # run whatever code you need to execute every 300 seconds here
          # put your code for task2 here
      
          # then reset the timer for this task2
          last_task2=time.time()
          
      
      # to execute task3 every 3 seconds
      if time.time()-last_task3>3: 
          # run whatever code you need to execute every 300 seconds here
          # put your code for task2 here
      
          # then reset the timer for this task3
          last_task3=time.time()
      

      Hope this helps.

      posted in Pythonista
      themusicman
      themusicman
    • RE: How to get a SpriteNode to change image / colour on screen-touching another Sprite?

      Absolutely loving the help and support from experts on here, thanks so much guys and gals.

      @Splefix - that's an awesome idea, thanks for the suggestion.

      @JonB - yep, this is exactly what I ended up doing, Jon. Once I had my head around the logic and syntax, even this old chap managed to code this section in a few mins.

      Still a few things to iron out in the code, but all in all, for my first real attempt at a slightly longer Python script than Print("Hello World:), I am pretty pleased with myself.

      Connect4 coded in Pythonista and running (albeit with a few glitches) on my iPad. Who'd have thunk it!! haha

      posted in Pythonista
      themusicman
      themusicman
    • RE: How to get a SpriteNode to change image / colour on screen-touching another Sprite?

      I managed to write some alternate (but yes, very ugly) code to do this. Just not too sure where the best place is to locate it,.

      		for fill_board in range(COLUMN_COUNT):
      			for rows2 in range(ROW_COUNT):
      				if self.board[rows2][fill_board] != 0:
      
      					if self.board[rows2][fill_board] == 1:
      						self.fill_circle = SpriteNode('emj:Red_Circle')
      					else:
      						self.fill_circle = SpriteNode('emj:Blue_Circle')
      
      					#				self.fill_circle = SpriteNode(self.turn_colour)
      					self.fill_circle.scale = 1.8
      					self.fill_circle.position = (
      					(fill_board * (768 - 68) / COLUMN_COUNT) + 80, (rows2 * (768 - 68) / COLUMN_COUNT) + 68)
      					self.add_child(self.fill_circle)
      
      

      It works when this code is inserted in the

      def update(self): 
      

      function, though it is a very poor 'brute force' method of checking an array and filling a Sprite on the screen depending on the content of the item in the array.

      When I inserted this code into the

      def touch_began(self, touch):

      function, I have a few placement issues so need to do some further investigation as to the best location to place that code.

      I really do need to write a more efficient way of doing this... maybe by just inserting one piece on the board per turn instead of filling every space with its corresponding array item!

      That's noobies to coding for you, eh haha

      posted in Pythonista
      themusicman
      themusicman
    • RE: Can you develop apps for Pythonista iPad on a Mac then port across?

      Must admit @mikael - apologies but no, I have yet to try this. I just had a look at the GIT page, and I am not too sure of how to get this working and where exactly to place the files in the git repository!! Should they go on the iPad or in my Mac somewhere?

      Not sure I have figured out what this actually is yet.... haha! I did say I was a noobie.

      Any pointers?

      posted in Pythonista
      themusicman
      themusicman
    • RE: Can you develop apps for Pythonista iPad on a Mac then port across?

      Hi @hmartin

      I'd love to help, but alas my knowledge is a million miles away from yours, sir! This does indeed sound like a great project though, and I'd be very interested to see how it progresses.

      My temporary solution to developing Pythonista code on my Mac is to simply use iCloud. I generate the main script on the iPad in the cloud, then open that file in PyCharm on the Mac, edit it using that, then when ready to test, I save it and after a few seconds the iPad version automatically updates and I use Pythonista breakpoints on the iPad to test and debug.

      Yep, it sure is a cumbersome method for writing, scripting and debugging et al, but as I said... despite being in my mid 50's, I'm a total noobie to all this, but am totally loving the learning process.

      posted in Pythonista
      themusicman
      themusicman
    • How to get a SpriteNode to change image / colour on screen-touching another Sprite?

      So, as the title states, I would like to find out how I am able to amend an existing sprite to a new colour/image, when I touch another Sprite on the iPad screen.

      Specifically - this is part of the Connect-4 script I am trying to create. The way I have chosen to do the 'how to choose ones move' is comprised of an area with left and right arrows, and in between these arrows is the button that says 'make move'. So, as one presses the left or right arrows, another sprite moves one column at a time to the respective column in the space above the board where the player wishes to make the move. Once the player is happy with the column to move, they press the separate 'make move' sprite.

      This then calls the code that fills the next empty space on the board for that column, and also calls a 'check if winning line' function.

      However. what I also wish to do is once the 'make move' sprite has been pressed, the colour of the sprite in the space above the board changes to match the colour of the next player to go. I believe I have the logic sorted for this, but I can't for the life of me figure out how to change the sprites colour.

      In the def setup(self) function I have defined the sprite as this;

      		# this will show current player above row selected
      		self.player = SpriteNode(self.turn_colour)
      		self.player.position = (player_x, player_y)
      		self.player.scale = 1.8
      		self.add_child(self.player)
      

      and then in the def touch_began(self, touch) function, I have this;

      		if self.turn == 0:
      			self.turn_colour = ('emj:Red_Circle')
      		else:
      			self.turn_colour = ('emj:Blue_Circle')
      
      		self.player = SpriteNode(self.turn_colour)
      
      		# left button pressed, so insert code to move disc to left here
      		
      		# right button pressed so insert code to move disc to right here
      		
      

      But unfortunately, this does not seem to amend the self.player sprite at all. Could someone advise please;

      1 - if this is possible, and if so
      2 - what is the correct syntax I should use, and
      3 - which Pythonista game function I should place the code to do that

      Any help greatly appreciated. More than happy to elaborate if needed. Many thanks.

      posted in Pythonista
      themusicman
      themusicman
    • RE: Getting the pixel dimensions of a sprite? How?

      Thanks @jonB - great explanation.

      However, I think it is not knowing the width of the sprite that appears to be causing me some layout issues, and it is that width which I am trying to figure out. I have seen in Swift there is a command that allows one to ascertain the width of the bounding box of a sprite, just wondering if there is a similar command for Pythonista.

      posted in Pythonista
      themusicman
      themusicman
    • Getting the pixel dimensions of a sprite? How?

      Hi All

      So, is there a way of obtaining the physical pixel dimensions (x and y) of a sprite please?

      I am trying to generate a grid of circles of ROW_COUNT and COLUMN_COUNT using the self.size function to utilise the full width of the iPad screen, such that the grid is centred correctly and not closer to one side of the screen than the other - but just can't get my head around the correct formulae.

      Here's the code I am using...

      		# draw board (white circles) - eventually replace with image
      		for circles in range(COLUMN_COUNT):
      			for rows in range(ROW_COUNT):
      				new_circle = SpriteNode('shp:Circle')
      				new_circle.scale = 3
      				new_circle.position = ((circles * (x - 68) / COLUMN_COUNT) + 68, (rows * (x - 68) / ROW_COUNT) + 68)
      				self.add_child(new_circle)
      
      

      Can any experts please shed some light and help a learner in distress please, haha... thanks.

      John

      posted in Pythonista
      themusicman
      themusicman
    • Does the order of def statements matter?

      Hi all

      I am writing a script using the animation/game template in Pythonista, and have written many functions that are called within the programme. Does the order the functions appear in the script matter?

      I am getting a name create_board' not defined error when running the script.

      The thing is, the function is actually there in the script. It is currently the first one listed under the MyScene class as here...

      class MyScene (Scene):
      	def create_board(self):
      		self.board = np.zeros((ROW_COUNT, COLUMN_COUNT))
      		return self.board
      

      And this function is called from within the def setup function further on down the script.

      Any pointers please? Sorry if this is a little vague, shout and I'll be happy to provide more detail if needed.

      Thanks
      John

      posted in Pythonista
      themusicman
      themusicman
    • How to add image(s) from iPad camera roll to Pythonista image library

      Hi All

      So, how do I do this please? I simply wish to import an image to use as the background layer to a game I am attempting to code. Specifically, it is the background to a Connect4 type game which essentially shows an empty Connect4 board. I want to use that as the background, and then overlay sprites as each player makes their turn. I have done the code for the Connect4 game, now figuring out the correct way to present this on the screen.

      So, to simply import an image from camera roll to use within a pythonista script.

      Ta

      posted in Pythonista
      themusicman
      themusicman
    • RE: Using numpy getting error: module numpy has no attribute 'flip' - yet it does!!!

      Thanks @cvp, I simply used this instead:

      import numpy as np
      
           reverse_board = board[::-1]
           print(reverse_board)
      
      

      which reversed the individual items in the board array such that as there are 7 items in the array, board[0] becomes board[6], board[1] becomes board[5] etc...

      Now to work on SpriteNodes - something I have never ever used. Need to figure out how to draw shapes et al.

      posted in Pythonista
      themusicman
      themusicman
    • RE: Using numpy getting error: module numpy has no attribute 'flip' - yet it does!!!

      Many thanks both! Still learning, so very grateful for your expertise.

      So @cvp - may I ask how I would install that source code into Pythonista please?

      posted in Pythonista
      themusicman
      themusicman