<commit_before># -*- coding: utf-8 -*-
"""
Created on Fri May  2 01:17:09 2014

@author: jrcapriles
"""

import pygame, Buttons
from pygame.locals import *
import ode
from math import atan2, acos, asin
from numpy import *
from Point import *
import matplotlib.pyplot as plt

from sympy import solve,symbols, Eq
from sympy import sin as nsin
from sympy import cos as ncos


class armSimulator( object ):
    def __init__( self, width, lenght, links):
        self.width, self.lenght, self.links = width, lenght, links
        self.L = ones(self.links)
        self.desired = None
        # Initialize pygame
        pygame.init()
        
        # Open a display
        self.srf = pygame.display.set_mode((self.width,self.lenght))
        pygame.display.set_caption(str(links) + "-Link Arm")
        self.fps = 50
        self.dt = 1.0/self.fps
        self.loopFlag = True
        #Parameters
        self.g= -9.81
        self.maxF = 20*ones((1,links))
        self.thetad = zeros((1,links)) 
        self.switch_counter = 0
        self.goal_button = Buttons.Button(self.srf, color = (200,0,0), x = 10, y = 10, length =  50, height = 25, width = 0, text = "Goal", text_color = (255,255,255), font_size = 20, fade_on = False)
        self.switch_button = Buttons.Button(self.srf, color = (200,0,0), x = 60, y = 10, length =  50, height = 25, width = 0, text = "Switch", text_color = (255,255,255), font_size = 20, fade_on = False)
        self.follow_button = Buttons.Button(self.srf, color = (200,0,0), x = 110, y = 10, length =  50, height = 25, width = 0, text = "Follow", text_color = (255,255,255), font_size = 20, fade_on = False)

    def createIC(self):
        rest = [] 
        left = []
        right = []
        up =[]
        #First loop to create all different combinations of IC
        for i in range(0,self.links+1):
            rest.append(Point(0,-i,0))
            left.append(Point(i,0,0))
            right.append(Point(-i,0,0))
            up.append(Point(0,i,0))
           
        #Create the dicionary
        self.ICList = {"Rest":rest,
                       "Left":left,
                       "Right":right,
                       "Up":up}
        
    def setTarget(self,target):
        self.thetad = target
        self.newGoal = target
    
    def getTarget(self, i):
        return self.thetad[i]
        
    def getTargetRange(self, i,j):
        return self.thetad[i:j]
        
    def setIC(self, case):
        self.IC = self.ICList[case]
        
    def getIC(self,i):
        return self.IC[i].getPoint()
    
    def setMaxF(self, F):
        if F is None:
            self.maxF = [10 for i in range(self.links)]
        else:
            self.maxF = F
    
    def getMaxF(self,i):
        return self.maxF[i]
        
    def getWidth(self):
        return self.width

    def getLenght(self):
            return self.leght
    
    def world2screen(self,x,y):
        return int(self.width/2 + 128*x), int(self.lenght/2 - 128*y)
    
    def world2screenX(self,x):
        return int(self.width/2 + 128*x)
    
    def world2screenY(self,y):
        return int(self.lenght/2 - 128*y)
        
    def screen2worldX(self,x):
        return (float(x - self.width/2)/128)
        
    def screen2worldY(self,y):
        return (float(-y + self.lenght/2)/128)
    
    def screen2world(self,x,y):
        return (float(x - self.width/2)/128), (float(-y + self.lenght/2)/128)
    
    
    def surf(self, x,y):
        return (pow(x-pi/2,2) + pow(0.9*pi*y,2) - pow(pi/2,2))

    def phi(self, y):
        return -y -(2*self.a/sqrt(pow(self.a,2)-1))*arctan(sqrt((self.a-1)/(self.a+1))*tan(y/2)) 

    def runSimulation(self, case, targets):
        
        self.createIC() 
        self.createArm(case)
        self.setTarget(targets)
        
        # Simulation loop.
        self.clk = pygame.time.Clock()
        self.follow = False

        while self.loopFlag:
            
            events = pygame.event.get()
            for e in events:
                
                if e.type==QUIT:
                    self.loopFlag=False

                if e.type==KEYDOWN:
                    if e.key == K_g:
                        print "New Goals: please click the new goal over the red circle"
                        self.setNewGoal()

                    elif e.key == K_f:
                        self.follow = not self.follow
                        if self.follow:
                            self.follow_button.color = (100,0,0)
                        else:
                            self.follow_button.color = (200,0,0)

                    else:
                        self.loopFlag=False

                elif e.type == MOUSEBUTTONDOWN:
                    if self.goal_button.pressed(pygame.mouse.get_pos()):
                        print "New Goals: please click the new goal over the red circle"
                        self.setNewGoal()

                    elif self.switch_button.pressed(pygame.mouse.get_pos()):
                        print "Switching side"
                        self.switchSide()

                    elif self.follow_button.pressed(pygame.mouse.get_pos()):<commit_msg>Added hot key to switch side function<commit_after># -*- coding: utf-8 -*-
"""
Created on Fri May  2 01:17:09 2014

@author: jrcapriles
"""

import pygame, Buttons
from pygame.locals import *
import ode
from math import atan2, acos, asin
from numpy import *
from Point import *
import matplotlib.pyplot as plt

from sympy import solve,symbols, Eq
from sympy import sin as nsin
from sympy import cos as ncos


class armSimulator( object ):
    def __init__( self, width, lenght, links):
        self.width, self.lenght, self.links = width, lenght, links
        self.L = ones(self.links)
        self.desired = None
        # Initialize pygame
        pygame.init()
        
        # Open a display
        self.srf = pygame.display.set_mode((self.width,self.lenght))
        pygame.display.set_caption(str(links) + "-Link Arm")
        self.fps = 50
        self.dt = 1.0/self.fps
        self.loopFlag = True
        #Parameters
        self.g= -9.81
        self.maxF = 20*ones((1,links))
        self.thetad = zeros((1,links)) 
        self.switch_counter = 0
        self.goal_button = Buttons.Button(self.srf, color = (200,0,0), x = 10, y = 10, length =  50, height = 25, width = 0, text = "Goal", text_color = (255,255,255), font_size = 20, fade_on = False)
        self.switch_button = Buttons.Button(self.srf, color = (200,0,0), x = 60, y = 10, length =  50, height = 25, width = 0, text = "Switch", text_color = (255,255,255), font_size = 20, fade_on = False)
        self.follow_button = Buttons.Button(self.srf, color = (200,0,0), x = 110, y = 10, length =  50, height = 25, width = 0, text = "Follow", text_color = (255,255,255), font_size = 20, fade_on = False)

    def createIC(self):
        rest = [] 
        left = []
        right = []
        up =[]
        #First loop to create all different combinations of IC
        for i in range(0,self.links+1):
            rest.append(Point(0,-i,0))
            left.append(Point(i,0,0))
            right.append(Point(-i,0,0))
            up.append(Point(0,i,0))
           
        #Create the dicionary
        self.ICList = {"Rest":rest,
                       "Left":left,
                       "Right":right,
                       "Up":up}
        
    def setTarget(self,target):
        self.thetad = target
        self.newGoal = target
    
    def getTarget(self, i):
        return self.thetad[i]
        
    def getTargetRange(self, i,j):
        return self.thetad[i:j]
        
    def setIC(self, case):
        self.IC = self.ICList[case]
        
    def getIC(self,i):
        return self.IC[i].getPoint()
    
    def setMaxF(self, F):
        if F is None:
            self.maxF = [10 for i in range(self.links)]
        else:
            self.maxF = F
    
    def getMaxF(self,i):
        return self.maxF[i]
        
    def getWidth(self):
        return self.width

    def getLenght(self):
            return self.leght
    
    def world2screen(self,x,y):
        return int(self.width/2 + 128*x), int(self.lenght/2 - 128*y)
    
    def world2screenX(self,x):
        return int(self.width/2 + 128*x)
    
    def world2screenY(self,y):
        return int(self.lenght/2 - 128*y)
        
    def screen2worldX(self,x):
        return (float(x - self.width/2)/128)
        
    def screen2worldY(self,y):
        return (float(-y + self.lenght/2)/128)
    
    def screen2world(self,x,y):
        return (float(x - self.width/2)/128), (float(-y + self.lenght/2)/128)
    
    
    def surf(self, x,y):
        return (pow(x-pi/2,2) + pow(0.9*pi*y,2) - pow(pi/2,2))

    def phi(self, y):
        return -y -(2*self.a/sqrt(pow(self.a,2)-1))*arctan(sqrt((self.a-1)/(self.a+1))*tan(y/2)) 

    def runSimulation(self, case, targets):
        
        self.createIC() 
        self.createArm(case)
        self.setTarget(targets)
        
        # Simulation loop.
        self.clk = pygame.time.Clock()
        self.follow = False

        while self.loopFlag:
            
            events = pygame.event.get()
            for e in events:
                
                if e.type==QUIT:
                    self.loopFlag=False

                if e.type==KEYDOWN:
                    if e.key == K_g:
                        print "New Goals: please click the new goal over the red circle"
                        self.setNewGoal()

                    elif e.key == K_f:
                        self.follow = not self.follow
                        if self.follow:
                            self.follow_button.color = (100,0,0)
                        else:
                            self.follow_button.color = (200,0,0)
                    elif e.key == K_s:
                        print "Switching side"
                        self.switchSide()
                    else:
                        self.loopFlag=False

                elif e.type == MOUSEBUTTONDOWN:
                    if self.goal_button.pressed(pygame.mouse.get_pos()):
                        print "New Goals: please click the new goal over the red circle"
                        self.setNewGoal()

                    elif self.switch_button.pressed(pygame.mouse.get_pos()):
                        print "Switching side"
                        self.switchSide()

                    elif self.follow_button.pressed(pygame.mouse.get_pos()):
{'fraction_non_alphanumeric': 0.12155591572123177, 'fraction_numerical': 0.03317761464391267, 'mean_word_length': 1.6081551466931874, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2829505', 'n_tokens_mistral': 3613, 'n_tokens_neox': 3326, 'n_words': 768}