コード例 #1
0
def cube_array(origin, v1, v2, v3, v4, color, canvas, array):

    block_array = np.empty([index_width, index_height], dtype=object)

    # Put Tetris block in the block array.
    if (origin[1] + v1[1, 0]
        ) < index_height and (origin[1] + v2[1, 0]) < index_height and (
            origin[1] + v3[1, 0]) < index_height and (origin[1] +
                                                      v4[1, 0]) < index_height:
        block_array[origin[0] + v1[0, 0], origin[1] + v1[1, 0]] = color
        block_array[origin[0] + v2[0, 0], origin[1] + v2[1, 0]] = color
        block_array[origin[0] + v3[0, 0], origin[1] + v3[1, 0]] = color
        block_array[origin[0] + v4[0, 0], origin[1] + v4[1, 0]] = color

    # Draw all the cubes in the cube array on the canvas.
    for i in range(index_width):
        for j in range(index_height):
            if array[i, j] != None:
                color = array[i, j]
                sh.square(i * xstep, j * ystep, color, canvas)

    # If the Tetris block collides with other cubes, then add the block array to the cube array.
    collision = get_collision(array, block_array)
    if collision:
        array = append_array(array, block_array)

    return array, collision
コード例 #2
0
ファイル: packing.py プロジェクト: alanbernstein/geometry
    def __init__(self, dim=None, base_shapes=None):
        if dim is None:
            dim = np.array([6, 4])
        self.dim = dim

        if base_shapes is None:
            base_shapes = [arc()]
        self.base_shapes = base_shapes

        border_int = square() * dim
        border_ext = square() * (dim + 1) - [0.5, 0.5]
        self.border_poly = Polygon(border_ext, [border_int])
コード例 #3
0
def test(size, color, fill='Default'):  # runs all shapes
    sh.triangle(size, color)
    #forward(300)
    sh.square(size, color)
    #forward(300)
    sh.pentagon(size, color)
    #forward(300)
    sh.hexagon(size, color)
    #forward(300)
    sh.octagon(size, color)
    #forward(300)
    sh.star(size, color)
    #forward(300)
    sh.circler(size, color)
コード例 #4
0
ファイル: robot.py プロジェクト: damimarty/GOR
	def __init__(self,env,x,y,size,orientation,life=200.0):
		object.__init__(self)
		self.environnement = env
		self.size = size
		self.x = x
		self.y = y
		self.lifeValue = life
		self.orientation = orientation
		self.bboxSize = int((sqrt(2)*self.size)/2)
		self.eyeAOW = 45.0
		self.eyeRes = 0.5

		# Create sensors with dummy position (center of robot)
		self.eyeR = eye(self.environnement,self.eyeAOW,self.orientation,self.x,self.y,self.eyeRes)
		self.eyeL = eye(self.environnement,self.eyeAOW,self.orientation,self.x,self.y,self.eyeRes)
		self.mouth = mouth(self.environnement,45.0,self.orientation,self.x,self.y)
		self.earR = ear(self.environnement,45.0,self.orientation,self.x,self.y)
		self.earL = ear(self.environnement,45.0,self.orientation,self.x,self.y)

		self.mySensors = []
		self.mySensors.append(self.eyeR)
		self.mySensors.append(self.eyeL)
		self.mySensors.append(self.mouth)
		self.mySensors.append(self.earR)
		self.mySensors.append(self.earL)

		# Keep sensors relative position
		self.eyeAngle = 20.0
		self.posEyeR = (self.eyeAngle,sqrt((self.size/2)**2+(tan((self.eyeAngle)*(pi/180.0))*(self.size/2))**2),0.0)
		self.posEyeL = (-self.eyeAngle,sqrt((self.size/2)**2+(tan((-self.eyeAngle)*(pi/180.0))*(self.size/2))**2),0.0)
		self.posMouth = (0.0,self.size/2,0)
		self.posEarR = (90.0,self.size/2,90.0)
		self.posEarL = (-90.0,self.size/2,-90.0)

		self.body = square(self.x,self.y,size,self.orientation,RED)
コード例 #5
0
ファイル: robot.py プロジェクト: damimarty/GOR
    def __init__(self, env, x, y, size, orientation, life=200.0):
        object.__init__(self)
        self.environnement = env
        self.size = size
        self.x = x
        self.y = y
        self.lifeValue = life
        self.orientation = orientation
        self.bboxSize = int((sqrt(2) * self.size) / 2)
        self.eyeAOW = 45.0
        self.eyeRes = 0.5

        # Create sensors with dummy position (center of robot)
        self.eyeR = eye(self.environnement, self.eyeAOW, self.orientation,
                        self.x, self.y, self.eyeRes)
        self.eyeL = eye(self.environnement, self.eyeAOW, self.orientation,
                        self.x, self.y, self.eyeRes)
        self.mouth = mouth(self.environnement, 45.0, self.orientation, self.x,
                           self.y)
        self.earR = ear(self.environnement, 45.0, self.orientation, self.x,
                        self.y)
        self.earL = ear(self.environnement, 45.0, self.orientation, self.x,
                        self.y)

        self.mySensors = []
        self.mySensors.append(self.eyeR)
        self.mySensors.append(self.eyeL)
        self.mySensors.append(self.mouth)
        self.mySensors.append(self.earR)
        self.mySensors.append(self.earL)

        # Keep sensors relative position
        self.eyeAngle = 20.0
        self.posEyeR = (self.eyeAngle,
                        sqrt((self.size / 2)**2 + (tan((self.eyeAngle) *
                                                       (pi / 180.0)) *
                                                   (self.size / 2))**2), 0.0)
        self.posEyeL = (-self.eyeAngle,
                        sqrt((self.size / 2)**2 + (tan((-self.eyeAngle) *
                                                       (pi / 180.0)) *
                                                   (self.size / 2))**2), 0.0)
        self.posMouth = (0.0, self.size / 2, 0)
        self.posEarR = (90.0, self.size / 2, 90.0)
        self.posEarL = (-90.0, self.size / 2, -90.0)

        self.body = square(self.x, self.y, size, self.orientation, RED)
コード例 #6
0
 def run(self):
     global canvas, layer, shape, shape_choosen, shape_length, shape_orientation
     print("Rotate")
     print shape_choosen
     print shape_length
     print shape_orientation
     if shape.id == 0:
         # Rotating a dot does nothing
         pass
     elif shape.id == 1:
         # Line - default orientation = 0 (horizontal)
         # 0 _    1 /    2 |     3 \
         # rotation scheme:
         #   0 -> 1 -> 2 -> 3 -> 0 -> ...
         if shape.orientation == 0:
             shape.pix = shapes.line_d(shape.length, 1)
             shape_orientation = 1
             shape.orientation = 1
         elif shape.orientation == 1:
             shape.pix = shapes.line_v(shape.length)
             shape_orientation = 2
             shape.orientation = 2
         elif shape.orientation == 2:
             shape.pix = shapes.line_d(shape.length, 0)
             shape_orientation = 3
             shape.orientation = 3
         else:
             shape.pix = shapes.line_h(shape.length)
             shape_orientation = 0
             shape.orientation = 0
     elif shape.id == 2:
         # Square - default orientation = 0 (horizontal & vertical sides)
         # 0 |_|     1 v (diamond)
         if shape.orientation == 0:
             shape.pix = shapes.square_d(shape.length, shape.fill)
             shape_orientation = 1
             shape.orientation = 1
         else:
             shape.pix = shapes.square(shape.length, shape.fill)
             shape_orientation = 0
             shape.orientation = 0
     else:
         print "something went terribly wrong"
コード例 #7
0
ファイル: robot.py プロジェクト: benoitclem/GOR
	def __init__(self,env,x,y,size,orientation,life=200.0):
		object.__init__(self)
		self.environnement = env
		self.size = size
		self.x = x
		self.y = y
		self.defaultLife = life
		self.lifeValue = self.defaultLife
		self.orientation = orientation
		self.bboxSize = int((sqrt(2)*self.size)/2)
		self.eyeAOW = 45.0
		self.eyeRes = 1		# number of pixels per deg / you would like to change num_inputs in GorNnConfig

		# Create sensors with dummy position (center of robot)
		self.eyeR = eye(self.environnement,self.eyeAOW,self.orientation,self.x,self.y,self.eyeRes)
		self.eyeL = eye(self.environnement,self.eyeAOW,self.orientation,self.x,self.y,self.eyeRes)
		self.mouth = mouth(self.environnement,45.0,self.orientation,self.x,self.y)
		self.earR = ear(self.environnement,45.0,self.orientation,self.x,self.y)
		self.earL = ear(self.environnement,45.0,self.orientation,self.x,self.y)

		self.mySensors = []
		self.mySensors.append(self.eyeR)
		self.mySensors.append(self.eyeL)
		self.mySensors.append(self.mouth)
		self.mySensors.append(self.earR)
		self.mySensors.append(self.earL)

		# Keep sensors relative position
		self.eyeAngle = 20.0
		self.posEyeR = (self.eyeAngle,sqrt((self.size/2)**2+(tan((self.eyeAngle)*(pi/180.0))*(self.size/2))**2),0.0)
		self.posEyeL = (-self.eyeAngle,sqrt((self.size/2)**2+(tan((-self.eyeAngle)*(pi/180.0))*(self.size/2))**2),0.0)
		self.posMouth = (0.0,self.size/2,0)
		self.posEarR = (90.0,self.size/2,90.0)
		self.posEarL = (-90.0,self.size/2,-90.0)

		self.body = square(self.x,self.y,size,self.orientation,RED)

		self.diFactor = 3
		self.daFactor = 6
コード例 #8
0
import shapes

shapes.octagon()
shapes.circlery()
shapes.square()
shapes.hexagon()
shapes.star()
shapes.triangle()

mainloop()
コード例 #9
0
ファイル: Spirograph.py プロジェクト: ben-boy/spirograph
            t.hideturtle()
            t.speed(100)
            t.color(colours)
            t.forward(int(forward))
            t.left(int(rt))

if choice == "square":
    size = input("Give me a number ")
    rotate = input("Give another number ")
    colour = input("Give a colour ")

    while True:
        t.speed(100)
        t.hideturtle()
        t.color(str(colour))
        shapes.square(int(size))
        t.left(int(rotate))

if choice == "randomsquare":
    size = randint(50, 200)
    rotate = randint(10, 100)
    print(size, rotate)

    while True:
        for colours in [
                "red", "orange", "yellow", "green", "blue", "purple", "pink"
        ]:
            t.bgcolor("black")
            t.hideturtle()
            t.speed(100)
            t.color(colours)
コード例 #10
0
up()
left(90)
forward(225)
left(90)
forward(350)
right(180)
down()

shapes.eq_triangle(150)

up()
left(120)
forward(275)
down()

shapes.square(125)

up()
left(90)
forward(275)
down()

shapes.pentagon(95)

up()
right(18)
forward(150)
right(90)
down()

shapes.hexagon(80)
コード例 #11
0
#!usr/bin/env python3

import shapes as s

# use all of shapes' functions to print everything ontop of each other
s.equilateral_triangle()
s.square()
s.pentagon()
s.hexagon()
s.octagon()
s.star()
s.circle(wait=True)
コード例 #12
0
ファイル: turtle_shapes.py プロジェクト: jwmarion/DC_Turtles
import shapes
from turtle import mainloop

shapes.startPoint()

shapes.star(100, True, 'red')

shapes.square(100, False, 'blue')

shapes.hexagon(100, True, 'beige')

shapes.circle(100, True, 'purple')

shapes.pentagon(100, False, 'white')

shapes.octagon(100, True, 'Green')

shapes.triangle(100, True, 'yellow')

mainloop()
コード例 #13
0
 def test_square(self):
     sq = shapes.square()
     sq.setLength(5)
     self.assertEquals(sq.getPerimeter(), 20)
     self.assertEquals(sq.getArea(), 25)
コード例 #14
0
from turtle import *
import shapes
import math
from random import randint

shapes.square(50, 'blue', True)

mainloop()
コード例 #15
0
    shapes.circle(image, (4, 5), 3, e, 0)
    shapes.circle(image, (5, 6), 3, w, .1)
    shapes.circle(image, (5, 6), 3, e, 0)
    shapes.circle(image, (6, 7), 3, w, .1)
    shapes.circle(image, (6, 7), 3, e, 0)
    shapes.circle(image, (7, 8), 3, w, .1)
    shapes.circle(image, (7, 8), 3, e, 0)
    shapes.circle(image, (8, 9), 3, w, .1)
    shapes.circle(image, (8, 9), 3, e, 0)
    shapes.circle(image, (1, 2), 2, w, .1)
    shapes.circle(image, (1, 2), 2, e, 0)

# colorful squares
for x in range(5):
    shapes.square(
        image, [0, 0], [7, 0], [7, 7], [0, 7],
        [randint(0, 255), randint(0, 255),
         randint(0, 255)], .01)
    shapes.square(
        image, [1, 1], [6, 1], [6, 6], [1, 6],
        [randint(0, 255), randint(0, 255),
         randint(0, 255)], .01)
    shapes.square(
        image, [2, 2], [5, 2], [5, 5], [2, 5],
        [randint(0, 255), randint(0, 255),
         randint(0, 255)], .01)

# clear screen with squares
shapes.square(image, [0, 0], [7, 0], [7, 7], [0, 7], e, .01)
shapes.square(image, [1, 1], [6, 1], [6, 6], [1, 6], e, .01)
shapes.square(image, [2, 2], [5, 2], [5, 5], [2, 5], e, .01)
コード例 #16
0
import shapes

room1 = shapes.square(4)
room2 = shapes.rectangle(4, 2)

コード例 #17
0
def windows():
    up()
    left(49)
    forward(100)
    left(90)
    forward(75)
    down()

    shapes.square(50)

    up()
    left(90)
    forward(100)
    down()

    shapes.square(50)

    up()
    left(90)
    forward(100)
    down()

    shapes.square(50)

    up()
    left(90)
    forward(100)
    down()

    shapes.square(50)

    up()
    forward(75)
    down()

    shapes.square(50)

    up()
    forward(50)
    down()

    shapes.square(50)

    up()
    left(90)
    forward(100)
    down()

    shapes.square(50)

    up()
    left(90)
    forward(100)
    down()

    shapes.square(50)
コード例 #18
0
def squaretest():
    sh.square(100, 'blue', fill=True)
コード例 #19
0
ファイル: tests.py プロジェクト: kirbyfan64/mathworks
 def test_square(self):
     sq = shapes.square()
     sq.setLength(5)
     self.assertEquals(sq.getPerimeter(), 20)
     self.assertEquals(sq.getArea(), 25)
コード例 #20
0
#!usr/bin/env python3

import shapes as s

# use all of shapes' functions to print everything ontop of each other
# all parameters have defaults
# paramater order size, "color", fill, wait
s.equilateral_triangle(200, "red", True)
s.square(200, "black")
s.pentagon(120, "purple", True)
s.hexagon(120)
s.octagon(color="blue")
s.star(300, "yellow")
s.circle(wait=True)
コード例 #21
0
import shapes

#main program begins
print("drawing!")
shapes.square(0,0,200,'magenta',True)
shapes.triangle(0,200,200,'red',True)
shapes.mycircle(-100,200,50,'yellow',True,360)
print("finished!")
コード例 #22
0
ファイル: wall.py プロジェクト: StevenLOL/AStar-Pathfinder
 def __init__(self, lx, ly, rx, ry, colour):
     self.square = shapes.square(
             vertices=('v2i', (lx, ly, rx, ly, rx, ry, lx, ry)),
             colour=colour)