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.
trying to make parallelograms for Side wall
-
im tryng to make a 3d looking room and want the side walls to be parallelograms that connect to the back rectangle
from scene import * import sound import random import math A = Action import ui from scene import * def wall_maker(x_start=None, y_start=None, to_right_tc=None, to_right_bc=None, to_left_bc=None, x_pos=None, y_pos=None, color=None): path = ui.Path() path.move_to(x_start, y_start) # Move to the top-left corner path.line_to(to_right_tc, y_start) # Draw a line to the top-right corner path.line_to(to_right_bc, to_left_bc) # Draw a line to the bottom-right corner path.line_to(to_right_bc, to_right_tc) # Draw a line to the bottom-left corner path.line_to(to_right_bc, to_right_tc) # Draw a line to the top-left corner path.close() # Close the path to form a trapezoid # Create a shape node with the trapezoid path wall = ShapeNode(path=path) wall.fill_color = color wall.stroke_color = 'black' wall.position = (x_pos, y_pos) return wall class MyScene(Scene): def setup(self): self.main_node = Node(parent=self) self.background_color = 'gray' # Create the back wall self.back_wall = ShapeNode(ui.Path.rect(self.size.w * 0.1, self.size.h * 0.1, self.size.w * 0.60, self.size.h * 0.75)) self.back_wall.position = (self.size.w / 2, self.size.h / 1.8) self.back_wall.line_width = 4 self.back_wall.fill_color = 'orange' self.back_wall.stroke_color = 'black' self.main_node.add_child(self.back_wall) # Create the left wall using the wall_maker function self.left_wall = wall_maker(x_start=self.size.w * 0.1, y_start=self.size.h * 0, to_right_tc=375, to_right_bc=800, to_left_bc=-20, x_pos=self.size.w * 0.10, y_pos=self.size.h * 0.55, color='orange') self.add_child(self.left_wall) # Create the right wall using the wall_maker function self.right_wall = wall_maker(x_start=50, y_start=50, to_right_tc=400, to_right_bc=900, to_left_bc=-20, x_pos=self.size.w * 0.90, y_pos=self.size.h * 0.50, color='orange') self.add_child(self.right_wall) # Create the floor line self.floor_line = ShapeNode() self.floor_line.path = ui.Path() self.floor_line.path.line_width = 4 self.floor_line.path.move_to(self.size.w * 0.75, self.size.h * 0.1) # Move to the top-right corner self.floor_line.path.line_to(self.size.w * 0.1, self.size.h * 0.1) # Draw a line to the top-left corner self.floor_line.fill_color = 'blue' self.floor_line.stroke_color = 'black' self.floor_line.position = (self.size.w * 0.50, self.size.h * 0.08) self.add_child(self.floor_line) 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) ![like this](https://www.google.com/imgres?imgurl=https%3A%2F%2Fwww.retrogames.cz%2Fgames%2F248%2FNES_01.gif&tbnid=3xiW2_4RJBWSxM&vet=12ahUKEwjn8KnugKP_AhX6O0QIHUnsDAsQMygFegUIARC3Ag..i&imgrefurl=https%3A%2F%2Fwww.retrogames.cz%2Fplay_248-NES.php&docid=9ydgQwkmSe7WrM&w=256&h=224&q=spy%20v%20spy%20nes&client=safari&ved=2ahUKEwjn8KnugKP_AhX6O0QIHUnsDAsQMygFegUIARC3Ag)
-
@resserone13v2-0 im not sure how to do this with self.size for all the parameters
-
this gets me close to the shape im looking for but its not using self .size and I don't think I will adjust to the screen size
import ui from scene import * def create_wall( x_start=None, y_start=None, x_right_tc=None, y_right_tc=None, x_right_bc=None, y_right_bc=None, x_left_bc=None, y_left_bc=None, x_left_tc=None, y_left_tc=None, x_pos=None, y_pos=None, color=None): path = ui.Path() path.move_to(x_start, y_start) # Move to the top-left corner path.line_to(x_right_tc, y_right_tc) # Draw a line to the top-right corner path.line_to(x_right_bc, y_right_bc) # Draw a line to the bottom-right corner path.line_to(x_left_bc, y_left_bc) # Draw a line to the bottom-left corner path.line_to(x_left_tc, y_left_tc) # Draw a line to the top-left corner path.close() # Close the path to form a trapezoid # Create a shape node with the trapezoid path wall = ShapeNode(path=path) wall.fill_color = color wall.stroke_color = 'black' wall.position = (x_pos, y_pos) return wall class MyScene(Scene): def setup(self): # Create the left wall using the wall_maker function self.left_wall = create_wall( x_start=50, y_start=100, x_right_tc=50, y_right_tc=100, x_right_bc=200, y_right_bc=100, x_left_bc=300, y_left_bc=300, x_left_tc=250, y_left_tc=400, x_pos=self.size.w / 2, y_pos=self.size.h /2, color='orange' ) self.add_child(self.left_wall) 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)
-
I found this
In parallelogram ABCDABCD {AB} = 10AB=10 and measured angle A = 60. Find {CD}CD
and ask chatgpt to use it to make a parallelogram then mix that with what I had before
it makes a parallelogram and now have to work on the size and placement
import ui from scene import * def parallelogram(a, angle_of_a, color, x_pos, y_pos): b = a # Calculate the coordinates of points B and C angle_A_rad = math.radians(angle_of_a) bx = a by = 0 cx = bx + b * math.cos(angle_A_rad) cy = b * math.sin(angle_A_rad) # Create a path to draw the parallelogram path = ui.Path() path.move_to(bx, by) # Point B path.line_to(cx, cy) # Point C path.line_to(cx - a,cy + a) # Point D path.line_to(bx - a, by + a) # Point A path.close() # Create a shape node with the path parallelogram = ShapeNode(path=path) parallelogram.fill_color = color parallelogram.stroke_color = 'black' parallelogram.position = (x_pos, y_pos) return parallelogram class MyScene(Scene): def setup(self): self.background_color = 'white' self.left_wall = parallelogram(400, 100, 'orange', self.size.w / 2, self.size.h / 2) self.add_child(self.left_wall) if __name__ == '__main__': run(MyScene(), show_fps=False)
-
I ended up with this. Not everything is lined up completely but you can see the idea of a 3-D room.
from scene import * import sound import random import math A = Action def parallelogram(x_start = None, y_start = None, x_1 = None, y_1 = None, x_2 = None, y_2 = None, x_3 = None, y_3 = None, fill_color = None, stroke_color = None, x_pos = None, y_pos =None): # Create line path = ui.Path() path.line_width = 4 path.move_to(x_start, y_start) # Move to start point path.line_to(x_1, y_1) # Point A path.line_to(x_2, y_2) # Point B path.line_to(x_3, y_3) # Point C path.close() # Point d line = ShapeNode(path=path) line.fill_color = fill_color line.stroke_color = stroke_color line.position = (x_pos, y_pos) line.anchor_point = (5, 5) return line class MyScene(Scene): def setup(self): ssw = self.size.w ssh = self.size.h self.background_color = 'red' # Back wall. self.back_wall = ShapeNode(ui.Path.rect(self.size.w * 0.1, self.size.h * 0.1, self.size.w * 0.54, self.size.h * 0.5)) self.back_wall.position = (self.size.w / 2, self.size.h / 1.5) self.back_wall.line_width = 4 self.back_wall.fill_color = 'orange' self.back_wall.stroke_color = 'black' self.add_child(self.back_wall) # Right wall. self.right_wall = parallelogram(x_start=self.size.w* 0.1, y_start=self.size.h * 0.6, x_1=self.size.w * 0.1, y_1=self.size.h * 0.1, x_2=self.size.w * 0.3, y_2=self.size.h * 0.2, x_3=self.size.w * 0.3, y_3=self.size.h * 0.92, fill_color='orange', stroke_color='black', x_pos=self.size.w * .976, y_pos=self.size.h * .92) self.add_child(self.right_wall) # Left wall. self.left_wall = parallelogram(x_start=self.size.w * 0.9, y_start=self.size.h * 0.6, x_1=self.size.w * 0.9, y_1=self.size.h * 0.1, x_2=self.size.w * 0.7, y_2=self.size.h * 0.2, x_3=self.size.w * 0.7, y_3=self.size.h * 0.92, fill_color='orange', stroke_color='black', x_pos=self.size.w * 0.225, y_pos=self.size.h * 0.921) self.add_child(self.left_wall) self.add_child(self.left_wall) # Create the floor line. self.floor_line = ShapeNode() self.floor_line.path = ui.Path() self.floor_line.path.line_width = 4 self.floor_line.path.move_to(self.size.w * 1, self.size.h * 0.1) # Move to the top-right corner self.floor_line.path.line_to(self.size.w * 0.08, self.size.h * 0.08) # Draw a line to the top-left corner self.floor_line.fill_color = 'blue' self.floor_line.stroke_color = 'black' self.floor_line.position = (self.size.w * 0.50, self.size.h * 0.08) self.add_child(self.floor_line) 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(), LANDSCAPE, show_fps=False)No
-
@resserone13v2-0 I thought you left the forum because you never replied to my last post in this topic
-
@cvp no. Never that. Lol. I just pop in and out. I was able to use anchor point. I didn’t use transform yet. I’ll probably finish up getting the room to lineed up correctly and then see if I can figure out how to get a sprite the walk thru it and scale depending on where it is on the screen
-
-
Here are a few more updates. I got the room pretty much lined up. Nothing major but you can see what’s going on. I set up some controls and I got the guy moving up and down and once those are fine tuned I’m going to copy and paste everything to the left and right buttons. I have a sprite sheet but I barely learned about sprite sheet animation earlier this morning. I’m not even sure how I thought of the word sprite sheet but I must’ve heard it somewhere before or something and then I started seeing how I don’t need to chop it into 1 million pieces I just need to locate each image on the sheet I checked and search for spreadsheet on here but I only seen I think three post. Anyways, I just wanted to get a post. I seen a bunch of spams post going on and I’ve been working on some Here and there. Working on some webs scraping.
from scene import * import sound import random import math A = Action def parallelogram(x_start=None, y_start=None, x_1=None, y_1=None, x_2=None, y_2=None, x_3=None, y_3=None, fill_color=None, stroke_color=None, x_pos=None, y_pos=None): # Create line path = ui.Path() path.line_width = 4 path.move_to(x_start, y_start) # Move to start point path.line_to(x_1, y_1) # Point A path.line_to(x_2, y_2) # Point B path.line_to(x_3, y_3) # Point C path.close() # Point d line = ShapeNode(path=path) line.fill_color = fill_color line.stroke_color = stroke_color line.position = (x_pos, y_pos) line.anchor_point = (5, 5) return line def create_button(img, x, y, alpha, color): btn = SpriteNode(img, position=(x, y), alpha=alpha, color=color) return btn class MyScene(Scene): def setup(self): self.background_color = 'red' self.up_pressed = False self.down_pressed = False self.right_pressed = False self.left_pressed = False self.a_btn_pressed = False self.b_btn__pressed = False # Back wall. self.back_wall = ShapeNode( ui.Path.rect(self.size.w * 1, self.size.h * 0.1, self.size.w * 0.54, self.size.h * 0.5)) self.back_wall.position = (self.size.w / 2, self.size.h / 1.5) self.back_wall.line_width = 4 self.back_wall.fill_color = 'white' self.back_wall.stroke_color = 'black' self.add_child(self.back_wall) # Right wall. self.right_wall = parallelogram(x_start=self.size.w * 0.1, y_start=self.size.h * 0.6, x_1=self.size.w * 0.1, y_1=self.size.h * 0.1, x_2=self.size.w * 0.3, y_2=self.size.h * 0.2, x_3=self.size.w * 0.3, y_3=self.size.h * 0.92, fill_color='white', stroke_color='black', x_pos=self.size.w * .976, y_pos=self.size.h * .92) self.add_child(self.right_wall) # Left wall. self.left_wall = parallelogram(x_start=self.size.w * 0.9, y_start=self.size.h * 0.6, x_1=self.size.w * 0.9, y_1=self.size.h * 0.1, x_2=self.size.w * 0.7, y_2=self.size.h * 0.2, x_3=self.size.w * 0.7, y_3=self.size.h * 0.92, fill_color='white', stroke_color='black', x_pos=self.size.w * 0.23, y_pos=self.size.h * 0.921) self.add_child(self.left_wall) # Create the floor line. self.floor_line = ShapeNode() self.floor_line.path = ui.Path() self.floor_line.path.line_width = 4 self.floor_line.path.move_to( self.size.w * 1.04, self.size.h * 0.1) # Move to the top-right corner self.floor_line.path.line_to( self.size.w * 0.09, self.size.h * 0.09) # Draw a line to the top-left corner self.floor_line.fill_color = 'blue' self.floor_line.stroke_color = 'black' self.floor_line.position = ( self.size.w * 0.50, self.size.h * 0.08) self.add_child(self.floor_line) # Spy sprite self.spy = SpriteNode('emj:Guardsman') self.spy.position = ( self.size.w / 2, self.size.h / 3) self.add_child(self.spy) # Controller Layout self.up = create_button('iow:arrow_up_b_32', self.size.w / 7, self.size.h / 3, .5, 'gray') self.add_child(self.up) self.down = create_button('iow:arrow_down_b_32', self.size.w / 7, self.size.h / 5.1, .5, 'gray') self.add_child(self.down) self.right = create_button('iow:arrow_right_b_32', self.size.w / 5.6, self.size.h / 3.8, .5, 'gray') self.add_child(self.right) self.left = create_button('iow:arrow_left_b_32', self.size.w / 9.2, self.size.h / 3.8, .5, 'gray') self.add_child(self.left) self.a_btn = create_button('A_button.PNG', self.size.w * 0.8, self.size.h / 7, .5, 'white') self.a_btn.scale = .04 self.add_child(self.a_btn) self.b_btn = create_button('B_button.PNG', self.size.w * .9, self.size.h / 7, .5, 'white') self.b_btn.scale = .045 self.add_child(self.b_btn) def did_change_size(self): pass def update(self): if self.up_pressed: if self.spy.position.y <= self.size.h * 0.45: self.spy.position += (0, 1.5) self.spy.scale -= 0.001 if self.down_pressed: if self.spy.position.y >= self.size.h * 0.134: self.spy.position += (0, -1.5) self.spy.scale += 0.001 def touch_began(self, touch): if touch.location in self.up.frame: self.up_pressed = True if touch.location in self.down.frame: self.down_pressed = True if touch in self.right.frame: pass if touch in self.left.frame: pass if touch in self.a_btn.frame: pass if touch in self.b_btn.frame: pass def touch_moved(self, touch): if touch.location in self.up.frame: self.up_pressed = False if touch.location in self.down.frame: self.down_pressed = False def touch_ended(self, touch): if touch.location in self.up.frame: self.up_pressed = False if touch.location in self.down.frame: self.down_pressed = False if __name__ == '__main__': run(MyScene(), LANDSCAPE, show_fps=False)
-
@resserone13v2-0 not able to run it because A_button.PNG and B_button.PNG are missing
-
@cvp you can switch them with any of the images in pythonista. they are just random images from google. They don't work yet. Just up and down work. I wanted to get most of the code to work then update left and right.
ill try to add the images here
-
@cvp
2nd try -
@resserone13v2-0 said
you can switch them with any of the images in pythonista.
Ok, done, but I don't see them on the scene, assumed you said "they don't work yet"
-
This post is deleted! -
@cvp it should just be a basic room with an emoji that you can move back and forth in the room.
i need to figure out how to use a sprite sheeti wanna use this code to create rooms
def creat_rooms(self, level): amount_of_rooms = game_levels[level] for room in amount_of_rooms: self.rooms.append(room)
class Room(): def __init__(self, furniture_list, items_list): self.exit_to_plane = False self.rooms_furniture = self.decorate_room(furniture_list, items_list) def decorate_room(self, furniture_list, items_list): # Still need to position funiture on the wall in the rooms '''returns a list with 2 list [objects, object names]''' decorated_room = [] random.shuffle(furniture_list) furniture_set = random.sample(furniture_list, 3) furniture_set_names = [] for f in furniture_set: random.shuffle(items_list) random_item = random.choice(items_list) pof = Furniture(f) pof.hide_item(random_item) print(pof.name, pof.has_item) decorated_room.append(pof) furniture_set_names.append(pof.name) return [decorated_room, furniture_set_names] def __str__(self): furniture_str = "\n".join(str(furniture) for furniture in self.rooms_furniture) return f"Room:\n{furniture_str}"
-
@resserone13v2-0 said
i need to figure out how to use a sprite sheet
No idea, I can't help you, good luck, seems funny
-
@resserone13v2-0 In Pythonista Examples/Game Tutorial folder, you can find a full example of how to animate your spritenode...with an array of walk textures, what you call a sprite sheet
Edit: with even an explanation here