Ejemplo n.º 1
0
		def __new__(self, operator, context, pipe, thickness):

			split = random_integer(1, 100) < operator.split
			rail = random_integer(1, 100) < operator.split if not split else False

			pipe_profile = create.curve(operator, context, pipe.name+'-profile')

			self.pipe(operator, context, pipe_profile, split, rail)
			self.set_dimensions(operator, pipe_profile, thickness)

			return pipe_profile
 def rand_cells(self, x, y, l):
     for a in range(x):
         for b in range(y):
             r = random_integer(0, 100)
             s = random_integer(0, 100)
             if r > s:
                 v = 1
             else:
                 v = 0
             l[str((a, b))] = cell(self.world, (a, b), v).channel
     return l
Ejemplo n.º 3
0
    def send(self, recipient, message):
        # Send to IRC first
        recipient.receive(self.mind, recipient, message)

        message = message.get('text', '')
        if message.startswith('\x01ACTION '):
            message = message.replace('ACTION ', '', 1).replace('\x01', '_')

        channel_id = None
        if isinstance(recipient, Group):
            server = self.mind.get_guild(self.server_id)
            for chan in server.channels:
                irc_chan_name = chan.name.replace(' ', '_')
                if irc_chan_name == recipient.name:
                    channel_id = chan.id

        url = 'https://discordapp.com/api/channels/{0}/messages'.format(channel_id)
        nonce = random_integer(-2**63, 2**63 - 1)
        payload = {
            'content': unicode(message),
            'nonce': nonce
        }
        self._sent_nonces.append(unicode(nonce))

        return chord.http_post(url, self.credentials.token, payload)
def random_element(l):
    """
    returns random element in list l
    """
    if l:
        index = random_integer(0, len(l) - 1)
        return l[index]
    return 'empty list'
Ejemplo n.º 5
0
def random_element(l):
    """
    returns random element in list l
    """
    print('in random_element', combined)
    if l:
        index = random_integer(0, len(l) - 1)
        return l[index]
    return 'empty list'
Ejemplo n.º 6
0
        def __new__(self, ot, context, pipe, thickness):
            split = random_integer(1, 100) <= ot.split

            pipe_profile = create.curve(ot, context, pipe.name + '-profile')

            self.pipe(ot, context, pipe_profile, split, thickness)
            self.set_dimensions(ot, pipe_profile, thickness)

            return pipe_profile
Ejemplo n.º 7
0
                    def __init__(self, pipe_profile):
                        spline1 = pipe_profile.data.splines.new('BEZIER')
                        spline1.use_cyclic_u = True

                        spline2 = pipe_profile.data.splines.new('BEZIER')
                        spline2.use_cyclic_u = True

                        type = ['type1', 'type2', 'type3']
                        getattr(self,
                                type[random_integer(0, 2)])(pipe_profile,
                                                            spline1, spline2)
Ejemplo n.º 8
0
    def send_message(self, channel_id, content, *, guild_id=None, tts=False):
        url = '{0.CHANNELS}/{1}/messages'.format(self, channel_id)
        payload = {
            'content': str(content),
            'nonce': random_integer(-2**63, 2**63 - 1)
        }

        if tts:
            payload['tts'] = True

        return self.post(url, json=payload, bucket='messages:' + str(guild_id))
Ejemplo n.º 9
0
    def send_message(self, channel_id, content, *, guild_id=None, tts=False):
        url = '{0.CHANNELS}/{1}/messages'.format(self, channel_id)
        payload = {
            'content': str(content),
            'nonce': random_integer(-2**63, 2**63 - 1)
        }

        if tts:
            payload['tts'] = True

        return self.post(url, json=payload, bucket='messages:' + str(guild_id))
Ejemplo n.º 10
0
        def __init__(self, ot, context, pipe, index, thickness):
            spline = pipe.data.splines.new('POLY')

            is_straight_pipe = random_integer(1, 100) <= ot.straight

            self.depth(ot, context, pipe, ot.depth * 0.5, index, thickness)

            if is_straight_pipe:

                self.straight(ot, pipe, spline, thickness)

            else:

                self.bent(ot, context, pipe, spline, thickness)

            self.align_profile(ot, context, pipe)
Ejemplo n.º 11
0
		def __init__(self, operator, context, pipe, index, thickness):

			spline = pipe.data.splines.new('POLY')

			is_straight_pipe = random_integer(1, 100) < operator.straight

			self.depth(operator, context, pipe, operator.depth * 0.5, index, thickness)

			if is_straight_pipe:

				self.straight(operator, pipe, spline, thickness)

			else:

				self.bent(operator, context, pipe, spline, thickness)

			self.align_profile(context, pipe)
Ejemplo n.º 12
0
 def send_message(self, user=None, message=None, channel=None):
     """ Todo """
     self.logger.info("sending message to %s: %s", user, message)
     cid = channel
     if not cid:
         for cid in self.channels:
             if str(self.channels[cid]) == str(user):
                 channel = cid
                 self.logger.debug(cid)
     if (channel):
         self.post(
             'channels/' + cid + '/messages',
             json.dumps({
                 'content': message,
                 'nonce': random_integer(-2**63, 2**63 - 1)
             }))
     else:
         logger.error("Unknown user %s", user)
Ejemplo n.º 13
0
    def send_message(self,
                     channel_id,
                     content,
                     *,
                     guild_id=None,
                     tts=False,
                     embed=None):
        r = Route('POST',
                  '/channels/{channel_id}/messages',
                  channel_id=channel_id)
        payload = {'nonce': random_integer(-2**63, 2**63 - 1)}

        if content:
            payload['content'] = content

        if tts:
            payload['tts'] = True

        if embed:
            payload['embed'] = embed

        return self.request(r, json=payload)
Ejemplo n.º 14
0
# modules =============================

print(__name__)

import math
print(math.sqrt(4))

import random
print(random.randint(1, 10))

from random import randint
print(randint(1, 10))

from random import randint as random_integer
print(random_integer(1, 10))

import lab03_grading
print(lab03_grading.number_grade_to_letter_grade(87))

from lab03_grading import number_grade_to_letter_grade
print(number_grade_to_letter_grade(87))

# __name__ is a special variable you can access inside a module
# if the user ran the module, the value of __name__ will be __main__
# if the user imported the module, the value of __name__ will be the name of the module
# this allows you to only run certain code when the module itself is being run and not when it's imported

# comparisons =============================

x = 1
Ejemplo n.º 15
0
            def __init__(self, operator, context, pipe, spline, thickness):

                pipe_corners = self.get_corners(operator, context, pipe,
                                                spline, thickness)

                is_beveled = random_integer(
                    1, 100) <= operator.bevel and operator.bevel_size > 0

                if is_beveled:

                    for index, point in enumerate(pipe_corners):

                        if index == 0:

                            create.point(spline, point)

                        elif index != len(pipe_corners) - 1:

                            if point[2]:

                                length_x = abs(point[0] -
                                               pipe_corners[index + 1][0])
                                length_y = abs(pipe_corners[index - 1][1] -
                                               point[1])

                                if min((length_x,
                                        length_y)) * (operator.bevel_size *
                                                      0.01) > thickness * 0.5:

                                    offset_y = -min((length_x, length_y)) * (
                                        operator.bevel_size * 0.01)
                                    offset_x = offset_y if point[
                                        3] else -offset_y

                                    create.point(spline,
                                                 point,
                                                 offset_y=offset_y)
                                    create.point(spline,
                                                 point,
                                                 offset_x=offset_x)

                                    point[0] += offset_x

                                else:

                                    create.point(spline, point)

                            else:

                                length_x = abs(pipe_corners[index - 1][0] -
                                               point[0])
                                length_y = abs(point[1] -
                                               pipe_corners[index + 1][1])

                                if min((length_x,
                                        length_y)) * (operator.bevel_size *
                                                      0.01) > thickness * 0.5:

                                    offset_y = min((length_x, length_y)) * (
                                        operator.bevel_size * 0.01)
                                    offset_x = offset_y if point[
                                        3] else -offset_y

                                    create.point(spline,
                                                 point,
                                                 offset_x=offset_x)
                                    create.point(spline,
                                                 point,
                                                 offset_y=offset_y)

                                    point[1] += offset_y

                                else:

                                    create.point(spline, point)

                        else:

                            create.point(spline, point)

                else:

                    for point in pipe_corners:

                        create.point(spline, point)
Ejemplo n.º 16
0
			def __init__(self, operator, context, pipe, spline, thickness):

				pipe_corners = self.get_corners(operator, context, pipe, spline, thickness)

				is_beveled = random_integer(1, 100) < operator.bevel

				if is_beveled:

					for index, point in enumerate(pipe_corners):

						if index == 0:

							create.point(spline, point)

						elif index != len(pipe_corners) - 1:

							if point[2]:

								length_x = abs(point[0] - pipe_corners[index + 1][0])
								length_y = abs(pipe_corners[index - 1][1] - point[1])

								if min((length_x, length_y)) * 0.25 > thickness:

									offset_y = -min((length_x, length_y)) * 0.25
									offset_x = offset_y if point[3] else -offset_y

									create.point(spline, point, offset_y=offset_y)
									create.point(spline, point, offset_x=offset_x)

									point[0] += offset_x

								else:

									create.point(spline, point)

							else:

								length_x = abs(pipe_corners[index - 1][0] - point[0])
								length_y = abs(point[1] - pipe_corners[index + 1][1])

								if min((length_x, length_y)) * 0.25 > thickness:

									offset_y = min((length_x, length_y)) * 0.25
									offset_x = offset_y if point[3] else -offset_y

									create.point(spline, point, offset_x=offset_x)
									create.point(spline, point, offset_y=offset_y)

									point[1] += offset_y

								else:

									create.point(spline, point)

						else:

							create.point(spline, point)

				else:

					for point in pipe_corners:

						create.point(spline, point)
Ejemplo n.º 17
0
                def __init__(self, pipe_profile, type=None):

                    type = ['single', 'double'][random_integer(
                        0, 1)] if not type else type
                    getattr(self, type)(pipe_profile)
Ejemplo n.º 18
0
from random import randint as random_integer
# random.randint(A, B) generates a random integer number N, A ? N ? B.

ny = int(input('Please, enter number of rows: '))
nx = int(input('Please, enter number of columns: '))

rand_min = int(input('Let us define the range of your random numbers. '
                     'Enter minimual possible number: '))
rand_max = int(input('Enter maximual possible number: '))

# Generation of random matrix
a = []
for i in range(0,ny):
    row = []
    for j in range(0,nx):
        element_ij = random_integer(rand_min, rand_max)
        row.append(element_ij)
    a.append(row)

if nx and ny < 7:
    print(str(a))  # Print matrix.

fate = int(input('Enter the specific integer number '
                 'and I delete all rows that contain it. Your choice: '))

# Identification 'fatal' rows which contain the specific number.
fatal_columns_indices = []
for i in range(0,ny):
    row_susp = a[i]
    print(str(row_susp))
    for j in range(0,nx):
Ejemplo n.º 19
0
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

# Start Manager (shares plane between processes)
from multiprocessing import Process, Manager, Pipe, Array
recv, send = Pipe(False)

# Make up some things to simulate
from Physics import Particle
from random import randint as random_integer
# Some config width height settings
width = 1000
height = 1000
particle_amount = 5
random_plane = [Particle(X_position=random_integer(0, width), Y_position=random_integer(0, height), X_velocity=random_integer(-500, 500), Y_velocity=random_integer(-500, 500)) for count in range(particle_amount)]
logger.info('Created plane with %s particles', particle_amount)

# Start the display
import pygame
from pygame.locals import *
pygame.init()
clock = pygame.time.Clock()
screen = pygame.display.set_mode((width, height))

# Initialise the physics stuff
from Physics import World
Jacks_sweet_thread = World(random_plane, send)

from timeit import default_timer as current_time
from multiprocessing import Process, Pool
Ejemplo n.º 20
0
def random_number():
    """ Generates a random number between 2 and 12 """
    return random_integer(1, 6) + random_integer(1, 6)
Ejemplo n.º 21
0
print('Creating shared memory')

# Create particles in shared memory
from multiprocessing import RawArray
from numpy import frombuffer
particle_list_flat = RawArray('d', number_of_particles * number_of_axes * number_of_properties)
particle_list = frombuffer(particle_list_flat, dtype='d').reshape((number_of_particles, number_of_axes, number_of_properties))

print('Setting initial values')

# Set initial property values
from random import randint as random_integer

if placement is 'vortex':
    for particle in particle_list:
        poop = random_integer(0,height - 1)
        for axis_index, axis in enumerate(axes):
            # Randomise position
            particle[axis_index][i['position']] = poop

        particle[i['y']][i['velocity']] = -2 * (particle[i['y']][i['position']] - width/2)
        particle[i['x']][i['velocity']] = 2* (particle[i['x']][i['position']] - height/2)
elif placement is 'normal':
    for particle in particle_list:
        # Set acceleration
        particle[i['y']][i['acceleration']] = 100
        for axis_index, axis in enumerate(axes):
            # Randomise position
            particle[axis_index][i['position']] = random_integer(0,axes_size[axis_index] - 1)
            # Randomise velocity
            particle[axis_index][i['velocity']] = random_integer(-1000000,1000000)/10000
Ejemplo n.º 22
0
        print(f'- {toping}')


make_pizza(30, 'cheese')
make_pizza(40, 'cheese', 'ham', 'mushrooms')


#passing key-value arguments - ** double stars (kwargs)
def build_profile(first, last, **user_info):
    user_info['first_name'] = first
    user_info['last_name'] = last
    return user_info


user_profile = build_profile('paul', 'pelar', location='cieszyn', age='22')
print(user_profile)


#empty
def build_profile(**user_info):
    return user_info


user_profile = build_profile(location='cieszyn', age='22', first_name='paul')
print(user_profile)

#modules
from random import randint as random_integer  #can change names of functions

print(random_integer(69, 70))