goleft | bioinformatics tools distributed under MIT license | Genomics library

 by   brentp Go Version: v0.2.4 License: MIT

kandi X-RAY | goleft Summary

goleft is a Go library typically used in Artificial Intelligence, Genomics, Docker applications. goleft has no bugs, it has no vulnerabilities, it has a Permissive License and it has low support. You can download it from GitHub.
goleft is a collection of bioinformatics tools written in go distributed together as a single binary under a liberal (MIT) license. Running the binary goleft will give a list of subcommands with a short description. Running any subcommand without arguments will give a full help for that command.
    Support
      Quality
        Security
          License
            Reuse
            Support
              Quality
                Security
                  License
                    Reuse

                      kandi-support Support

                        summary
                        goleft has a low active ecosystem.
                        summary
                        It has 180 star(s) with 22 fork(s). There are 15 watchers for this library.
                        summary
                        It had no major release in the last 12 months.
                        summary
                        There are 13 open issues and 46 have been closed. On average issues are closed in 38 days. There are no pull requests.
                        summary
                        It has a neutral sentiment in the developer community.
                        summary
                        The latest version of goleft is v0.2.4
                        goleft Support
                          Best in #Genomics
                            Average in #Genomics
                            goleft Support
                              Best in #Genomics
                                Average in #Genomics

                                  kandi-Quality Quality

                                    summary
                                    goleft has no bugs reported.
                                    goleft Quality
                                      Best in #Genomics
                                        Average in #Genomics
                                        goleft Quality
                                          Best in #Genomics
                                            Average in #Genomics

                                              kandi-Security Security

                                                summary
                                                goleft has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
                                                goleft Security
                                                  Best in #Genomics
                                                    Average in #Genomics
                                                    goleft Security
                                                      Best in #Genomics
                                                        Average in #Genomics

                                                          kandi-License License

                                                            summary
                                                            goleft is licensed under the MIT License. This license is Permissive.
                                                            summary
                                                            Permissive licenses have the least restrictions, and you can use them in most projects.
                                                            goleft License
                                                              Best in #Genomics
                                                                Average in #Genomics
                                                                goleft License
                                                                  Best in #Genomics
                                                                    Average in #Genomics

                                                                      kandi-Reuse Reuse

                                                                        summary
                                                                        goleft releases are available to install and integrate.
                                                                        summary
                                                                        Installation instructions, examples and code snippets are available.
                                                                        goleft Reuse
                                                                          Best in #Genomics
                                                                            Average in #Genomics
                                                                            goleft Reuse
                                                                              Best in #Genomics
                                                                                Average in #Genomics
                                                                                  Top functions reviewed by kandi - BETA
                                                                                  kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
                                                                                  Currently covering the most popular Java, JavaScript and Python libraries. See a Sample Here
                                                                                  Get all kandi verified functions for this library.
                                                                                  Get all kandi verified functions for this library.

                                                                                  goleft Key Features

                                                                                  goleft is a collection of bioinformatics tools distributed under MIT license in a single static binary

                                                                                  goleft Examples and Code Snippets

                                                                                  No Code Snippets are available at this moment for goleft.
                                                                                  Community Discussions

                                                                                  Trending Discussions on goleft

                                                                                  using serial monitor as a button input for LibGDX game
                                                                                  chevron right
                                                                                  Python Turtle has Stopped Listening
                                                                                  chevron right
                                                                                  Loop Function on Mouseover in Vanilla Javascript
                                                                                  chevron right
                                                                                  WebForms RichTextBox Editing Approch?
                                                                                  chevron right
                                                                                  Display styling if a image id is display block instead of none
                                                                                  chevron right
                                                                                  Why doesn't my flex work in my css? I've tried to use grid but it still doesn't work
                                                                                  chevron right
                                                                                  Handle input events in stateless manner
                                                                                  chevron right
                                                                                  JavaFX - move projectiles
                                                                                  chevron right
                                                                                  Why is the “root.after ()” method not stoppable?
                                                                                  chevron right
                                                                                  Pac Man cross obstacles
                                                                                  chevron right

                                                                                  QUESTION

                                                                                  using serial monitor as a button input for LibGDX game
                                                                                  Asked 2021-Apr-21 at 17:40

                                                                                  I'm currently working on a project that includes a short demo game, we've decided to use LibGDX as the java library and we're required to use an arduino and/or raspberry pi as a controller input. My assumption was to make an inputprocessor that uses the serial monitor input sent by the arduino. We're currently stumped on how to accomplish this and aren't even sure if you can use the inputprocessor in this way.

                                                                                  #define left 2
                                                                                  #define right 3
                                                                                  void setup() {
                                                                                    // put your setup code here, to run once:
                                                                                    Serial.begin(9600);
                                                                                  }
                                                                                  
                                                                                  void loop() {
                                                                                    // put your main code here, to run repeatedly:
                                                                                    if(digitalRead(left))
                                                                                    {
                                                                                     
                                                                                  
                                                                                   goLeft();
                                                                                    }
                                                                                    if(digitalRead(right))
                                                                                    {
                                                                                      goRight();
                                                                                    }
                                                                                    delay(100);
                                                                                  }
                                                                                  void goLeft()
                                                                                  {
                                                                                    Serial.println(1000);
                                                                                  }
                                                                                  void goRight()
                                                                                  {
                                                                                    Serial.println(500);
                                                                                  }
                                                                                  

                                                                                  This is the code running on the Arduino it's a simple setup that just serial prints 2 different numbers depending on what button is pressed to be later used as a left or right direction in the game.

                                                                                  port = SerialPort.getCommPort("COM4");
                                                                                          if(port.openPort()) {
                                                                                              System.out.println("Successfully opened the port.");
                                                                                          } else {
                                                                                              System.out.println("Unable to open the port.");
                                                                                              return;
                                                                                          }
                                                                                          port.setComPortTimeouts(SerialPort.TIMEOUT_READ_SEMI_BLOCKING, 0, 0);
                                                                                          data = new Scanner(port.getInputStream());
                                                                                          if(data.hasNextLine())
                                                                                          {
                                                                                              int number = 0;
                                                                                              try{number = Integer.parseInt(data.nextLine());}catch(Exception e){}
                                                                                              if(number == 500)
                                                                                              {
                                                                                                  bucket.x += 200 * Gdx.graphics.getDeltaTime();
                                                                                              }
                                                                                              if(number == 1000)
                                                                                              {
                                                                                                  bucket.x -= 200 * Gdx.graphics.getDeltaTime();
                                                                                              }
                                                                                          }
                                                                                  

                                                                                  This is the code currently used during the render() function in our game. However what happens is that the game will only continue to render when there is a nextLine in the serial monitor and will not render at any other times. We're currently using the java library jserial comm in order to facilitate the connection between the ardiono and java application. For this reason we believed we would require an inputprocessor however as we're currently student developers we're unable to figure out if this is the case and how we could accomplish it.

                                                                                  ANSWER

                                                                                  Answered 2021-Apr-21 at 17:40

                                                                                  I would suggest moving your serial listener to a separate dedicated thread, which calls back to your game when it reads something.

                                                                                  This way your GDX Game thread can continue to run as you expect, with a parallel thread listening for inputs, only notifying the game when it receives them.

                                                                                  To achieve this, package your listener into a Runnable interface:

                                                                                      // Runnable class, listens for serial input
                                                                                      public class serialListener implements Runnable {
                                                                                          
                                                                                          @Override
                                                                                          public void run() {
                                                                                              // Listen for input, and calls corresponding methods in your game
                                                                                          }
                                                                                      }
                                                                                  

                                                                                  Then dispatch it in a new thread from your game upon creation :

                                                                                      public class myGame extends GameAdapter {
                                                                                          
                                                                                          private serialListener listener = new serialListener();
                                                                                          private Thread ListenerThread;
                                                                                          
                                                                                          @Override
                                                                                          public void Create(){
                                                                                              ListenerThread = new Thread(listener);
                                                                                              ListenerThread.setDaemon(true);
                                                                                              ListenerThread.start();
                                                                                          }
                                                                                      }
                                                                                  

                                                                                  Source https://stackoverflow.com/questions/67198183

                                                                                  QUESTION

                                                                                  Python Turtle has Stopped Listening
                                                                                  Asked 2021-Feb-23 at 18:21

                                                                                  I want to make a drawing app that uses the WSAD keys to move the turtle, Q and E to raise and lower the pen, and I tried to add a dialog box so you can choose the color of the turtle, but after I change the color, the turtle won't respond to the WSAD keybindings. Can someone explain what is going on and how to fix this problem?

                                                                                  Here is the code:

                                                                                  import turtle
                                                                                  
                                                                                  #WSAD to move
                                                                                  def up():
                                                                                      char.setheading(90)
                                                                                      char.forward(10)
                                                                                  
                                                                                  def down():
                                                                                      char.setheading(270)
                                                                                      char.forward(10)
                                                                                  
                                                                                  def goLeft():
                                                                                      char.setheading(180)
                                                                                      char.forward(10)
                                                                                  
                                                                                  def goRight():
                                                                                      char.setheading(0)
                                                                                      char.forward(10)
                                                                                  
                                                                                  
                                                                                  #Raises and Lowers the pen
                                                                                  def lowerPen():
                                                                                      char.pendown()
                                                                                  def raisePen():
                                                                                      char.penup()
                                                                                  
                                                                                  #change colors
                                                                                  def color():
                                                                                      data = turtle.simpledialog.askstring("Change Color", "Change Color to:")
                                                                                      char.color(data)
                                                                                  
                                                                                  #Char info
                                                                                  char = turtle.Turtle()
                                                                                  char.speed(0)
                                                                                  
                                                                                  screen = turtle.Screen()
                                                                                  screen.title("Arrow Paint")
                                                                                  
                                                                                  #Make Turtle Listen to Keystrokes.
                                                                                  turtle.listen()
                                                                                  
                                                                                  #Keybindings
                                                                                  turtle.onkey(color, "c")
                                                                                  turtle.onkey(up, "w")
                                                                                  turtle.onkey(down, "s")
                                                                                  turtle.onkey(goLeft, "a")
                                                                                  turtle.onkey(goRight, "d")
                                                                                  turtle.onkey(raisePen, "q")
                                                                                  turtle.onkey(lowerPen, "e")
                                                                                  
                                                                                  
                                                                                  turtle.done()
                                                                                  

                                                                                  Thank you in advance

                                                                                  Edit: I have also tried substituting the turtle.simpledialog.askstring() function with the textinput() function I found, and it still won't respond to the keybindings

                                                                                  ANSWER

                                                                                  Answered 2021-Feb-23 at 18:21

                                                                                  When you do:

                                                                                  turtle.listen()
                                                                                  

                                                                                  you make your turtle window the listener for keyboard events. But when you invoke:

                                                                                   data = turtle.simpledialog.askstring("Change Color", "Change Color to:")
                                                                                  

                                                                                  or textinput(), the window that pops up becomes the listener for keyboard events. So when you're done with your user dialog window, call:

                                                                                  turtle.listen()
                                                                                  

                                                                                  again afterward. This should allow your turtle keyboard events to operate as before. The revised code:

                                                                                  from turtle import Screen, Turtle
                                                                                  
                                                                                  # WSAD to move
                                                                                  def goUp():
                                                                                      char.setheading(90)
                                                                                      char.forward(10)
                                                                                  
                                                                                  def goDown():
                                                                                      char.setheading(270)
                                                                                      char.forward(10)
                                                                                  
                                                                                  def goLeft():
                                                                                      char.setheading(180)
                                                                                      char.forward(10)
                                                                                  
                                                                                  def goRight():
                                                                                      char.setheading(0)
                                                                                      char.forward(10)
                                                                                  
                                                                                  # Raise and Lowers the pen
                                                                                  def lowerPen():
                                                                                      char.pendown()
                                                                                  
                                                                                  def raisePen():
                                                                                      char.penup()
                                                                                  
                                                                                  # Change colors
                                                                                  def color():
                                                                                      data = screen.textinput("Change Color", "Change Color to:")
                                                                                      char.color(data)
                                                                                      screen.listen()
                                                                                  
                                                                                  screen = Screen()
                                                                                  screen.title("Arrow Paint")
                                                                                  
                                                                                  # Char info
                                                                                  char = Turtle()
                                                                                  char.speed('fastest')
                                                                                  
                                                                                  # Keybindings
                                                                                  screen.onkey(color, "c")
                                                                                  
                                                                                  screen.onkey(goUp, "w")
                                                                                  screen.onkey(goDown, "s")
                                                                                  screen.onkey(goLeft, "a")
                                                                                  screen.onkey(goRight, "d")
                                                                                  
                                                                                  screen.onkey(raisePen, "q")
                                                                                  screen.onkey(lowerPen, "e")
                                                                                  
                                                                                  # Make Turtle Listen to Keystrokes.
                                                                                  screen.listen()
                                                                                  
                                                                                  screen.mainloop()
                                                                                  

                                                                                  Source https://stackoverflow.com/questions/66327950

                                                                                  QUESTION

                                                                                  Loop Function on Mouseover in Vanilla Javascript
                                                                                  Asked 2020-Dec-08 at 21:43

                                                                                  I am trying to create a carousel of images and wanted to horizontal scroll when the user hovers over the left and right side of the div. I have two "invisible" divs for the left and right controls and gave them eventListeners:

                                                                                  right.addEventListener("mouseover", goRight)

                                                                                  function goRight() {
                                                                                      document.getElementById('images').scrollLeft += 20;
                                                                                  }
                                                                                  

                                                                                  left.addEventListener("mouseover", goLeft)

                                                                                  function goLeft() {
                                                                                  
                                                                                      document.getElementById('images').scrollLeft -= 20;
                                                                                  }
                                                                                  

                                                                                  When I hover over them, it will scroll once, but I would like it to continuously scroll until I mouseout. How I can I make goRight()/goLeft() loop while I am hovering on the controls?

                                                                                  ANSWER

                                                                                  Answered 2020-Dec-08 at 21:39

                                                                                  One solution is to use the setInterval() method which should be cancelled on mouseout. You can store the interval id and use clearInterval() on mouseout:

                                                                                  const delay = 100;
                                                                                  let intervalId;
                                                                                  
                                                                                  function goLeft() {
                                                                                    intervalId = setInterval(
                                                                                      () => (document.getElementById('images').scrollLeft -= 20),
                                                                                      delay,
                                                                                    );
                                                                                  }
                                                                                  
                                                                                  function goRight() {
                                                                                    intervalId = setInterval(
                                                                                      () => (document.getElementById('images').scrollLeft += 20),
                                                                                      delay,
                                                                                    );
                                                                                  }
                                                                                  
                                                                                  function stopScrolling() {
                                                                                    clearInterval(intervalId);
                                                                                  }
                                                                                  
                                                                                  left.addEventListener('mouseover', goLeft);
                                                                                  left.addEventListener('mouseout', stopScrolling);
                                                                                  right.addEventListener('mouseover', goRight);
                                                                                  right.addEventListener('mouseout', stopScrolling);
                                                                                  

                                                                                  Source https://stackoverflow.com/questions/65207071

                                                                                  QUESTION

                                                                                  WebForms RichTextBox Editing Approch?
                                                                                  Asked 2020-Sep-07 at 15:15

                                                                                  I am using C# WinForm, and I have a RichTextBox that I am trying to make look like a C# script.

                                                                                  Means when using specific words, I want them to be colored. When they edit the word by changing it, I want it to go back to be black.

                                                                                  My approach works, but it really messy and cause bugs when the a scroll option is created and needed to be used to see the code below. (When typing, pretty much the richtextbox jumps up and down without stop)

                                                                                  private void ScriptRichTextBox_TextChanged(object sender, EventArgs e)
                                                                                      {
                                                                                          ScriptTextChange = ScriptRichTextBox.Text;
                                                                                          ScriptColorChange();
                                                                                      }
                                                                                  
                                                                                      private void ScriptColorChange()
                                                                                      {
                                                                                          int index = ScriptRichTextBox.SelectionStart;
                                                                                          ScriptRichTextBox.Text = ScriptTextChange; //Only way I found to make the all current text black again, SelectAll() didn't work well.
                                                                                          ScriptRichTextBox.SelectionStart = index;
                                                                                          String[] coloredNames = {"Main", "ClickMouseDown", "ClickMouseUp", "PressKey", "StopMoving", "Delay", "GoRight", "GoLeft", "GoUp", "GoDown", "MousePosition", "LastHorizontalDirection", "LastVerticalDirections", "CurrentDirection", "Directions" };
                                                                                          String[] coloredNames2 = { "cm.", "if", "else", "while", "switch", "case", "break", "return", "new" };
                                                                                          String[] coloredNames3 = { "MyPosition", "MyHp", "MyMp", "OtherPeopleInMap", ".RIGHT", ".LEFT", ".UP", ".DOWN", ".STOP_MOVING" };
                                                                                          foreach (String s in coloredNames)
                                                                                              this.CheckKeyword(s, Color.LightSkyBlue, 0);
                                                                                          foreach (String s in coloredNames2)
                                                                                              this.CheckKeyword(s, Color.Blue, 0);
                                                                                          foreach (String s in coloredNames3)
                                                                                              this.CheckKeyword(s, Color.DarkGreen, 0);
                                                                                      }
                                                                                  
                                                                                      private void CheckKeyword(string word, Color color, int startIndex)
                                                                                      {
                                                                                          if (this.ScriptRichTextBox.Text.Contains(word))
                                                                                          {
                                                                                              int index = 0;
                                                                                              int selectStart = this.ScriptRichTextBox.SelectionStart;
                                                                                  
                                                                                              while ((index = this.ScriptRichTextBox.Text.IndexOf(word, (index + 1))) != -1)
                                                                                              {
                                                                                                  this.ScriptRichTextBox.Select((index + startIndex), word.Length);
                                                                                                  this.ScriptRichTextBox.SelectionColor = color;
                                                                                                  this.ScriptRichTextBox.Select(selectStart, 0);
                                                                                                  this.ScriptRichTextBox.SelectionColor = Color.Black;
                                                                                              }
                                                                                          }
                                                                                      }
                                                                                  

                                                                                  ANSWER

                                                                                  Answered 2020-Sep-07 at 15:15

                                                                                  I refactored your code a little to hopefully demonstrate a better approach to colouring the text. It is also not optimal to instantiate your string arrays every time you fire the TextChanged event.

                                                                                  Updated: The idea is to build up a word buffer that will be matched with your set of words when typing.

                                                                                  The buffer records each key and if it .IsLetterOrDigit it adds it to the StringBuilder buffer. The buffer has some additional bugs, with recording key press values and not removing recorded chars if you hit backspace etc..

                                                                                  Instead of the word buffer, use RegEx to match any of the words in your reserve word list. Build up the reserve word RegEx so you end up with something like \b(word|word2|word3....)\b This is done in the code in the BuildRegExPattern(..) method.

                                                                                  Once you hit any key other than a letter or number the buffer is checked for content and if the content matches a word then only the text right before the cursor in the ScriptRichTextBox.Text is checked and changed.

                                                                                  Remove the .(dots) from the reserve words as this just complicates the matching criteria. The RegEx in the built up patters will match the words exactly, so if you type something like FARRIGHT or cms the words will not partially change colour.

                                                                                  As an extra I also covered the paste process pressing Ctrl+V because it is a bit of a pain in WinForms and will probably happen quite often.

                                                                                  There are older questions eg. this one that cover the scrolling behaviour, where it shows how to interop by adding the [System.Runtime.InteropServices.DllImport("user32.dll")] attribute, but it can be done without it.

                                                                                  To prevent all the scroll jumping you can make use of the .DefWndProc(msg) method on the form. this question pointed me towards the WM_SETREDRAW property.

                                                                                  There is also this list of other properties that can be set.

                                                                                  The full implementation is this:

                                                                                  public partial class Form1 : Form
                                                                                  {
                                                                                      private readonly string[] _skyBlueStrings;
                                                                                      private readonly string[] _blueStrings;
                                                                                      private readonly string[] _greenStrings;
                                                                                  
                                                                                      //for pasting
                                                                                      bool _IsCtrl;
                                                                                      bool _IsV;
                                                                                  
                                                                                      //value to fix the colour not setting first character after return key pressed
                                                                                      int _returnIdxFix = 0;
                                                                                  
                                                                                      //regex patterns to use
                                                                                      string _LightBlueRegX = "";
                                                                                      string _BlueRegX = "";
                                                                                      string _GreenRegX = "";
                                                                                  
                                                                                      //match only words
                                                                                      Regex _rgxAnyWords = new Regex(@"(\w+)");
                                                                                  
                                                                                      //colour setup
                                                                                      Color _LightBlueColour = Color.LightSkyBlue;
                                                                                      Color _BlueColour = Color.Blue;
                                                                                      Color _GreenColour = Color.DarkGreen;
                                                                                      Color _DefaultColour = Color.Black;
                                                                                  
                                                                                  
                                                                                      public Form1()
                                                                                      {
                                                                                          InitializeComponent();
                                                                                  
                                                                                          _skyBlueStrings = new string[] { "Main", "ClickMouseDown", "ClickMouseUp", "PressKey", "StopMoving", "Delay", "GoRight", "GoLeft", "GoUp", "GoDown", "MousePosition", "LastHorizontalDirection", "LastVerticalDirections", "CurrentDirection", "Directions" };
                                                                                          _blueStrings = new string[] { "cm", "if", "else", "while", "switch", "case", "break", "return", "new" };
                                                                                          _greenStrings = new string[] { "MyPosition", "MyHp", "MyMp", "OtherPeopleInMap", "RIGHT", "LEFT", "UP", "DOWN", "STOP_MOVING" };
                                                                                  
                                                                                          _LightBlueRegX = BuildRegExPattern(_skyBlueStrings);
                                                                                          _BlueRegX = BuildRegExPattern(_blueStrings);
                                                                                          _GreenRegX = BuildRegExPattern(_greenStrings);
                                                                                      }
                                                                                  
                                                                                      string BuildRegExPattern(string[] keyworkArray)
                                                                                      {
                                                                                          StringBuilder _regExPatern = new StringBuilder();
                                                                                          _regExPatern.Append(@"\b(");//beginning of word
                                                                                          _regExPatern.Append(string.Join("|", keyworkArray));//all reserve words
                                                                                          _regExPatern.Append(@")\b");//end of word
                                                                                          return _regExPatern.ToString();
                                                                                      }
                                                                                  
                                                                                      private void ProcessAllText()
                                                                                      {
                                                                                          BeginRtbUpdate();
                                                                                          FormatKeywords(_LightBlueRegX, _LightBlueColour);
                                                                                          FormatKeywords(_BlueRegX, _BlueColour);
                                                                                          FormatKeywords(_GreenRegX, _GreenColour);
                                                                                  
                                                                                          //internal function to process words and set their colours
                                                                                          void FormatKeywords(string regExPattern, Color wordColour)
                                                                                          {
                                                                                              var matchStrings = Regex.Matches(ScriptRichTextBox.Text, regExPattern);
                                                                                              foreach (Match match in matchStrings)
                                                                                              {
                                                                                                  FormatKeyword(keyword: match.Value, wordIndex: match.Index, wordColour: wordColour);
                                                                                              }
                                                                                          }
                                                                                  
                                                                                          EndRtbUpdate();
                                                                                          ScriptRichTextBox.Select(ScriptRichTextBox.Text.Length, 0);
                                                                                          ScriptRichTextBox.Invalidate();
                                                                                      }
                                                                                  
                                                                                      void ProcessWordAtIndex(string fullText, int cursorIdx)
                                                                                      {
                                                                                          MatchCollection anyWordMatches = _rgxAnyWords.Matches(fullText);
                                                                                          if (anyWordMatches.Count == 0)
                                                                                          { return; } // no words found
                                                                                  
                                                                                          var allWords = anyWordMatches.OfType().ToList();
                                                                                  
                                                                                          //get the word just before cursor
                                                                                          var wordAtCursor = allWords.FirstOrDefault(w => (cursorIdx - _returnIdxFix) == (w.Index + w.Length));
                                                                                          if (wordAtCursor is null || string.IsNullOrWhiteSpace(wordAtCursor.Value))
                                                                                          { return; }//no word at cursor or the match was blank
                                                                                  
                                                                                          Color wordColour = CalculateWordColour(wordAtCursor.Value);
                                                                                          FormatKeyword(wordAtCursor.Value, wordAtCursor.Index, wordColour);
                                                                                  
                                                                                      }
                                                                                  
                                                                                      private Color CalculateWordColour(string word)
                                                                                      {
                                                                                          if (_skyBlueStrings.Contains(word))
                                                                                          { return _LightBlueColour; }
                                                                                          if (_blueStrings.Contains(word))
                                                                                          { return _BlueColour; }
                                                                                          if (_greenStrings.Contains(word))
                                                                                          { return _GreenColour; }
                                                                                          return _DefaultColour;
                                                                                      }
                                                                                  
                                                                                      private void FormatKeyword(string keyword, int wordIndex, Color wordColour)
                                                                                      {
                                                                                          ScriptRichTextBox.Select((wordIndex - _returnIdxFix), keyword.Length);
                                                                                          ScriptRichTextBox.SelectionColor = wordColour;
                                                                                          ScriptRichTextBox.Select(wordIndex + keyword.Length, 0);
                                                                                          ScriptRichTextBox.SelectionColor = _DefaultColour;
                                                                                      }
                                                                                  
                                                                                      #region RichTextBox BeginUpdate and EndUpdate Methods
                                                                                          protected override void WndProc(ref Message m)
                                                                                          {
                                                                                              base.WndProc(ref m);
                                                                                              //wait until the rtb is visible, otherwise you get some weird behaviour.
                                                                                              if (ScriptRichTextBox.Visible && ScriptRichTextBox.IsHandleCreated)
                                                                                              {
                                                                                                  if (m.LParam == ScriptRichTextBox.Handle)
                                                                                                  {
                                                                                                      rtBox_lParam = m.LParam;
                                                                                                      rtBox_wParam = m.WParam;
                                                                                                  }
                                                                                              }
                                                                                          }
                                                                                  
                                                                                          IntPtr rtBox_wParam = IntPtr.Zero;
                                                                                          IntPtr rtBox_lParam = IntPtr.Zero;
                                                                                          const int WM_SETREDRAW = 0x0b;
                                                                                          const int EM_HIDESELECTION = 0x43f;
                                                                                  
                                                                                          void BeginRtbUpdate()
                                                                                          {
                                                                                              Message msg_WM_SETREDRAW = Message.Create(ScriptRichTextBox.Handle, WM_SETREDRAW, (IntPtr)0, rtBox_lParam);
                                                                                              this.DefWndProc(ref msg_WM_SETREDRAW);
                                                                                          }
                                                                                  
                                                                                          public void EndRtbUpdate()
                                                                                          {
                                                                                              Message msg_WM_SETREDRAW = Message.Create(ScriptRichTextBox.Handle, WM_SETREDRAW, rtBox_wParam, rtBox_lParam);
                                                                                              this.DefWndProc(ref msg_WM_SETREDRAW);
                                                                                              //redraw the RichTextBox
                                                                                              ScriptRichTextBox.Invalidate();
                                                                                          }
                                                                                          #endregion
                                                                                  
                                                                                      private void ScriptRichTextBox_TextChanged(object sender, EventArgs e)
                                                                                      {
                                                                                          //only run all text if it was pasted NOT ON EVERY TEXT CHANGE!
                                                                                          if (_IsCtrl && _IsV)
                                                                                          {
                                                                                              _IsCtrl = false;
                                                                                              ProcessAllText();
                                                                                          }
                                                                                      }
                                                                                  
                                                                                      protected void ScriptRichTextBox_KeyPress(object sender, KeyPressEventArgs e)
                                                                                      {
                                                                                          if (!char.IsLetterOrDigit(e.KeyChar))
                                                                                          {
                                                                                              //if the key was enter the cursor position is 1 position off                
                                                                                              _returnIdxFix = (e.KeyChar == '\r') ? 1 : 0;
                                                                                              ProcessWordAtIndex(ScriptRichTextBox.Text, ScriptRichTextBox.SelectionStart);
                                                                                          }
                                                                                      }
                                                                                  
                                                                                      private void ScriptRichTextBox_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
                                                                                      {
                                                                                          if (e.KeyCode == Keys.ControlKey)
                                                                                          {
                                                                                              _IsCtrl = true;
                                                                                          }
                                                                                          if (e.KeyCode == Keys.V)
                                                                                          {
                                                                                              _IsV = true;
                                                                                          }
                                                                                      }
                                                                                  
                                                                                      private void ScriptRichTextBox_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
                                                                                      {
                                                                                          if (e.KeyCode == Keys.ControlKey)
                                                                                          {
                                                                                              _IsCtrl = false;
                                                                                          }
                                                                                          if (e.KeyCode == Keys.V)
                                                                                          {
                                                                                              _IsV = false;
                                                                                          }
                                                                                      }
                                                                                  }
                                                                                  

                                                                                  It looks like this when you paste some "code" with keywords:

                                                                                  and typing looks like this:

                                                                                  Source https://stackoverflow.com/questions/63722850

                                                                                  QUESTION

                                                                                  Display styling if a image id is display block instead of none
                                                                                  Asked 2020-Jun-29 at 19:31

                                                                                  I want to use java script instead of j query : Check, using jQuery, if an element is 'display:none' or block on click, but when you switch the display none into a display block using a button. Java

                                                                                                      var slideIndex = 0;
                                                                                                      showDivs(slideIndex);
                                                                                  
                                                                                                      function plusDivs(n) {
                                                                                                        showDivs(slideIndex += n);
                                                                                                      }
                                                                                  
                                                                                                      function showDivs(n) {//switching function
                                                                                                        var i;
                                                                                                        var x = document.getElementsByClassName("mySlides");
                                                                                                        if (n > x.length) {slideIndex = 1}
                                                                                                        if (n < 1) {slideIndex = x.length}
                                                                                                        for (i = 0; i < x.length; i++) {
                                                                                                          x[i].style.display = "none";  
                                                                                                        }
                                                                                                        x[slideIndex-1].style.display = "block";  
                                                                                                      }
                                                                                                      if(document.getElementsById("1").style.display = "block")//if style display is block
                                                                                                      {
                                                                                                          document.getElementsById("1I").style.width = "78px";
                                                                                                          document.getElementsById("1I").style.height = "48px";
                                                                                                          document.getElementsById("1I").style.border = "4px solid green";
                                                                                                          document.getElementsById("1I").style.boxShadow = "1px 4px 8px lightblue";
                                                                                                      }
                                                                                  

                                                                                  Html

                                                                                                  
                                                                                                      
                                                                                                      
                                                                                                      
                                                                                                      
                                                                                                      
                                                                                                      
                                                                                                      
                                                                                                      
                                                                                                      
                                                                                                      
                                                                                                      
                                                                                                      
                                                                                                      ❮
                                                                                                      ❯
                                                                                                  
                                                                                                  
                                                                                    

                                                                                  I done the switching part of this, but when i click the button it dont do any thing but switches Image the two buttons are for switching the image but when i click one of them the arrow button it will show a style at the bottom of the image that is the same image and the image will switch same as the image that is style

                                                                                  ANSWER

                                                                                  Answered 2020-Jun-27 at 02:16

                                                                                  You are assigning the value of "block" to the display property instead of checking for equality on this line:

                                                                                  if(document.getElementsById("1").style.display = "block")
                                                                                  

                                                                                  Try changing the = to ===:

                                                                                  if(document.getElementsById("1").style.display === "block")
                                                                                  

                                                                                  Source https://stackoverflow.com/questions/62605108

                                                                                  QUESTION

                                                                                  Why doesn't my flex work in my css? I've tried to use grid but it still doesn't work
                                                                                  Asked 2020-Jun-23 at 14:39
                                                                                  const PictureBox = () => {
                                                                                      **this is an array of pictures**
                                                                                      const allPictures = [
                                                                                          { before: Sofa1, after: Sofa2 },
                                                                                          { before: Sofa1, after: Sofa2 },
                                                                                          { before: Sofa1, after: Sofa2 },
                                                                                          { before: Sofa1, after: Sofa2 }
                                                                                      ];
                                                                                     
                                                                                      **setting the state**
                                                                                      const [x, setX] = useState(0)
                                                                                  
                                                                                      **functions that slide left and right based on the state**
                                                                                      const goLeft = () => {
                                                                                          x === 200 * (allPictures.length - 1) ? setX(0) : setX(x + 200)
                                                                                          x === 200 * (allPictures.length - 1) ? setX(0) : setX(x + 200)
                                                                                      }
                                                                                      const goRight = () => {
                                                                                          x === 0 ? setX(200 * (allPictures.length - 1)) : setX(x - 200)
                                                                                          x === 0 ? setX(200 * (allPictures.length - 1)) : setX(x - 200)
                                                                                      }
                                                                                  
                                                                                      return (
                                                                                          
                                                                                              
                                                                                                   {allPictures.map((img, index) => {
                                                                                                  return (
                                                                                                     
                                                                                                      
                                                                                                          
                                                                                                          
                                                                                                      
                                                                                                  )
                                                                                              })}
                                                                                              
                                                                                             
                                                                                              left
                                                                                              right
                                                                                          
                                                                                      )
                                                                                  }
                                                                                  
                                                                                  
                                                                                  export default PictureBox;
                                                                                  

                                                                                  Styling:

                                                                                  .slider {
                                                                                      height: 450px;
                                                                                      min-width: 100%;
                                                                                      box-sizing: border-box;
                                                                                      margin: 0;
                                                                                      padding: 0;
                                                                                      position: relative;
                                                                                      display: flex;
                                                                                      flex-direction: row;
                                                                                      flex: 1;
                                                                                      border-radius: 12px; 
                                                                                      /* overflow: hidden; */
                                                                                  }
                                                                                  
                                                                                  .slide {
                                                                                      min-width: 100%;
                                                                                      height: 100%; 
                                                                                      transition: 0.5s;
                                                                                      box-sizing: border-box; 
                                                                                      border: 1px double skyblue;
                                                                                      background: rgb(2, 67, 95);
                                                                                  }
                                                                                  

                                                                                  ANSWER

                                                                                  Answered 2020-Jun-23 at 12:14

                                                                                  Here are some things to explore

                                                                                  1. The flex:1 css should be on the child not the parent so write that on .slide
                                                                                  2. Images are notorious to adding problems you can check if maybe there's an issue with the images not respecting flex img{max-width:100%;max-height:100%}

                                                                                  Source https://stackoverflow.com/questions/62534097

                                                                                  QUESTION

                                                                                  Handle input events in stateless manner
                                                                                  Asked 2020-May-18 at 12:13

                                                                                  Yesterday I`ve asked how may I handle keyboard input (with ScalaFX) in a functional manner. Thanks to @alfilercio help I came up with something like this:

                                                                                  class InputHandler {
                                                                                    private val goUp: Int => State => State = step => state => State(state.x, state.y - step)
                                                                                    private val goDown: Int => State => State = step => state => State(state.x, state.y + step)
                                                                                    private val goLeft: Int => State => State = step => state => State(state.x - step, state.y)
                                                                                    private val goRight: Int => State => State = step => state => State(state.x + step, state.y)
                                                                                    private val doNothing: Int => State => State = step => state => state
                                                                                  
                                                                                    private var behaviour: Int => State => State = doNothing
                                                                                  
                                                                                    def keyPressedHandler(key: KeyEvent): Unit = {
                                                                                      behaviour = key.getCode match {
                                                                                        case KeyCode.Up.delegate => goUp
                                                                                        case KeyCode.Down.delegate => goDown
                                                                                        case KeyCode.Left.delegate => goLeft
                                                                                        case KeyCode.Right.delegate => goRight
                                                                                        case _ => doNothing
                                                                                      }
                                                                                    }
                                                                                  
                                                                                    def keyReleasedHandler(key: KeyEvent): Unit = behaviour = doNothing
                                                                                  
                                                                                    def update: Int => State => State = behaviour
                                                                                  }
                                                                                  

                                                                                  Then there is an Updater (working name) thats updates state based on time passed, some internal logic and/or user input:

                                                                                  def update(state: State)(implicit inputHandler: InputHandler): State = { ... }

                                                                                  With such approach the core classes may remain pure and no single variable is needed. But there is still problem with the InputHandler itself. I mean the behaviour variable makes it statefull. This InputHandler adds kind of abstraction to ScalaFX used to generate GUI. The metdods keyPressedHandler/keyRelasedHandler are set as ScalaFX Scene events handlers respectively. To conclude, I am looking way to remove state variable (behaviour) from this InputHandler. I try to grasp functional approach for educational reasons that`s why I keep bothering you with this case :)

                                                                                  ANSWER

                                                                                  Answered 2020-May-18 at 12:13

                                                                                  Personally I would assume that all Listeners and Handlers are by definition impure objects from outside of our pure world, so if I wanted to keep things pure, I would make them send commands as values through some IO.

                                                                                  class SthListener(keyPressed: KeyCode => Unit,
                                                                                                    keyReleased: KeyCode => Unit,
                                                                                                    updateState: (State => Unit) => Unit) externds XListener {
                                                                                  
                                                                                    def keyPressedHandler(key: KeyEvent): Unit = keyPressed(key.getCode)
                                                                                  
                                                                                    def keyReleasedHandler(key: KeyEvent): Unit = keyReleased()
                                                                                  
                                                                                    def update: Unit = updateState { state => // received from outside world
                                                                                      // how to update current component basing on received state
                                                                                    }
                                                                                  }
                                                                                  

                                                                                  and somewhere else

                                                                                  sealed trait Event
                                                                                  object Event {
                                                                                    case class KeyPressed(keyCode: Int) extends Event
                                                                                    case class KeyReleased(keyCode: Int) extends Event
                                                                                  }
                                                                                  
                                                                                  val eventBus = Queue[Task, Event]
                                                                                  
                                                                                  val stateRef = Ref[Task, State]
                                                                                  
                                                                                  // translate pure operations on boundary of dirtyness
                                                                                  new SthListener(
                                                                                    keyPressed = keyCode => eventBus.enqueue1(Event.KeyPressed(keyCode)).runSync, // or runAndForget, or what works for you,
                                                                                    keyReleased = keyCode => eventBus.enqueue1(Event.KeyReleased(keyCode)).runSync,
                                                                                    update => stateRef.get.runSync
                                                                                  )
                                                                                  
                                                                                  // handle state transitions
                                                                                  queue.dequeue
                                                                                    .evalMap {
                                                                                      case Event.KeyPressed(key)  => stateRef.update(...)
                                                                                      case Event.KeyReleased(key) => stateRef.update(...)
                                                                                    }
                                                                                    .compile
                                                                                    .drain
                                                                                  

                                                                                  Does it make sense doing it always? Personally I don't think so, but you/your team see much value in purity, RT, and you have a lot of use cases which would justify this overhead, then you could add this kind of wrappers to make sure that imperative API won't force you to change the style of coding in whole application, but just in the part that forces imperative style on you.

                                                                                  If this is way too much... well, you can just use mutability and imperative style for now and revisit that approach once you will feel more familiar. Don't force it, take your time and write the code that the current you can understand and maintain easily.

                                                                                  Source https://stackoverflow.com/questions/61866016

                                                                                  QUESTION

                                                                                  JavaFX - move projectiles
                                                                                  Asked 2020-Apr-21 at 13:08

                                                                                  first of all, this is my very first post here. Hello everyone!

                                                                                  I am a beginnner in Java/JavaFX. Currently I wrote some simple "game" to learn some basic stuff in game development, doing that just for fun right now. So far I get a player which moves to the left/right (movemt is unrestricted, but never mind that now) and fires projectiles. I got this done, code below:

                                                                                  package tester;
                                                                                  
                                                                                  import java.util.ArrayList;
                                                                                  import javafx.animation.AnimationTimer;
                                                                                  import javafx.application.Application;
                                                                                  import javafx.scene.Scene;
                                                                                  import javafx.scene.input.KeyCode;
                                                                                  import javafx.scene.layout.AnchorPane;
                                                                                  import javafx.scene.paint.Color;
                                                                                  import javafx.scene.shape.Circle;
                                                                                  import javafx.scene.shape.Rectangle;
                                                                                  import javafx.stage.Stage;
                                                                                  
                                                                                  
                                                                                  public class Tester extends Application {
                                                                                  
                                                                                      private int dx, x = 150, y = 470, projectileSpeed = 10;
                                                                                      private int counter = 0, spawnTime = 180, enemySpeed = 4;
                                                                                      private boolean goLeft, goRight, isShooting;
                                                                                  
                                                                                      public final static int APP_WIDTH = 300;
                                                                                      public final static int APP_HEIGHT = 500;
                                                                                  
                                                                                      private AnchorPane root;
                                                                                      private Scene scene;
                                                                                  
                                                                                      private Rectangle projectile;
                                                                                      private Circle player = new Circle(x, y, 10, Color.RED);
                                                                                      private Rectangle enemy;
                                                                                      private ArrayList projectiles = new ArrayList();
                                                                                      private ArrayList enemies = new ArrayList();
                                                                                  
                                                                                      @Override
                                                                                      public void start(Stage primaryStage) {
                                                                                  
                                                                                          root = new AnchorPane();
                                                                                          scene = new Scene(root, APP_WIDTH, APP_HEIGHT, Color.GHOSTWHITE);
                                                                                  
                                                                                          primaryStage.setTitle("Hello World!");
                                                                                          primaryStage.setScene(scene);
                                                                                          primaryStage.setResizable(false);
                                                                                          primaryStage.show();
                                                                                  
                                                                                          root.getChildren().addAll(player);
                                                                                  
                                                                                          loop();
                                                                                      }
                                                                                  
                                                                                      private void controls() {
                                                                                  
                                                                                          scene.setOnKeyPressed(event -> {
                                                                                              KeyCode key = event.getCode();
                                                                                  
                                                                                              switch (key) {
                                                                                                  case LEFT:
                                                                                                      goLeft = true;
                                                                                                      break;
                                                                                                  case RIGHT:
                                                                                                      goRight = true;
                                                                                                      break;
                                                                                                  case SPACE:
                                                                                                      projectiles.add(projectile = new Rectangle(3, 3, Color.BLUE));
                                                                                                      projectile.relocate(x + player.getRadius(), y);
                                                                                                      root.getChildren().add(projectile);
                                                                                                      break;
                                                                                              }
                                                                                  
                                                                                          });
                                                                                          scene.setOnKeyReleased(event -> {
                                                                                              KeyCode key = event.getCode();
                                                                                  
                                                                                              switch (key) {
                                                                                                  case LEFT:
                                                                                                      goLeft = false;
                                                                                                      break;
                                                                                                  case RIGHT:
                                                                                                      goRight = false;
                                                                                                      break;
                                                                                                  case SPACE:
                                                                                                      isShooting = false;
                                                                                                      break;
                                                                                              }
                                                                                  
                                                                                          });
                                                                                  
                                                                                      }
                                                                                  
                                                                                      private void shoot() {
                                                                                          for (int i = 0; i < projectiles.size(); ++i) {
                                                                                              if (projectiles.get(i).getLayoutY() > (root.getBoundsInParent().getMinY() - projectile.getHeight())) {
                                                                                                  projectiles.get(i).relocate(projectiles.get(i).getLayoutX(), (projectiles.get(i).getLayoutY() - projectileSpeed));
                                                                                              } else {
                                                                                                  projectiles.remove(i);
                                                                                                  root.getChildren().remove(i);
                                                                                              }
                                                                                          }
                                                                                  
                                                                                      }
                                                                                  
                                                                                      private void spawnEnemy() {
                                                                                  
                                                                                          double spawnPosition = Math.random();
                                                                                  
                                                                                          int eWidth = 20;
                                                                                          int eHeight = 40;
                                                                                          double ex = (APP_WIDTH - eWidth) * spawnPosition;
                                                                                          int ey = (int) (root.getBoundsInParent().getMinY());
                                                                                  
                                                                                          if (counter % spawnTime == 0) {
                                                                                              enemies.add(enemy = new Rectangle(ex, ey, eWidth, eHeight));
                                                                                              root.getChildren().add(enemy);
                                                                                          }
                                                                                      }
                                                                                  
                                                                                      public void moveEnemy() {
                                                                                          for (int i = 0; i < enemies.size(); ++i) {
                                                                                              if (enemies.get(i).getLayoutY() < (root.getBoundsInParent().getMaxY() + enemy.getHeight())) {
                                                                                                  enemies.get(i).relocate(enemies.get(i).getLayoutX(), (enemies.get(i).getLayoutY() + enemySpeed));
                                                                                              } else {
                                                                                                  enemies.remove(i);
                                                                                  
                                                                                              }
                                                                                          }
                                                                                      }
                                                                                  
                                                                                      private void loop() {
                                                                                  
                                                                                          AnimationTimer timer = new AnimationTimer() {
                                                                                  
                                                                                              @Override
                                                                                              public void handle(long now) {
                                                                                  
                                                                                                  controls();
                                                                                                  if (goLeft) {
                                                                                                      dx = -5;
                                                                                                  }
                                                                                                  if (goRight) {
                                                                                                      dx = 5;
                                                                                                  }
                                                                                                  if (!goLeft && !goRight) {
                                                                                                      dx = 0;
                                                                                                  }
                                                                                                  player.relocate(x += dx, y);
                                                                                                  shoot();
                                                                                  
                                                                                                  counter++;
                                                                                                  spawnEnemy();
                                                                                                  moveEnemy();
                                                                                              }
                                                                                          };
                                                                                          timer.start();
                                                                                      }
                                                                                  
                                                                                      public static void main(String[] args) {
                                                                                          launch(args);
                                                                                      }
                                                                                  
                                                                                  }
                                                                                  

                                                                                  Now the weird part. If I comment the moveEnemy() method out, everything seems OK - the "enemies" (black rectangles) appear in random places along the x axis on the top of the root.

                                                                                  I thought I'll move enemies by means of the same method which I used to move projectiles. However, if I actually use this, my enemies keep appearing at the left top corner and dissappear almost instantly. Why is that?

                                                                                  Many thanks!

                                                                                  Edit: maybe I wasn't clear. I don't expect a ready-made solution, but an explanation.

                                                                                  ANSWER

                                                                                  Answered 2020-Apr-21 at 13:08

                                                                                  Ok, I got it sorted out, thanks kleopatra for help! Probably there is still a room for improvement, but nonetheless its some progress:

                                                                                  package tester;
                                                                                  
                                                                                  import java.util.ArrayList;
                                                                                  import java.util.Iterator;
                                                                                  import javafx.animation.AnimationTimer;
                                                                                  import javafx.application.Application;
                                                                                  import javafx.scene.Scene;
                                                                                  import javafx.scene.input.KeyCode;
                                                                                  import javafx.scene.layout.AnchorPane;
                                                                                  import javafx.scene.paint.Color;
                                                                                  import javafx.scene.shape.Circle;
                                                                                  import javafx.scene.shape.Rectangle;
                                                                                  import javafx.stage.Stage;
                                                                                  
                                                                                  public class Tester extends Application {
                                                                                  
                                                                                      private int dx, x = 150, y = 470, projectileSpeed = 10;
                                                                                      private int counter = 0, spawnTime = 180, enemySpeed = 4;
                                                                                      private boolean goLeft, goRight, isShooting;
                                                                                  
                                                                                      public final static int APP_WIDTH = 300;
                                                                                      public final static int APP_HEIGHT = 500;
                                                                                  
                                                                                      private AnchorPane root;
                                                                                      private Scene scene;
                                                                                  
                                                                                      private Rectangle projectile;
                                                                                      private Circle player = new Circle(x, y, 10, Color.RED);
                                                                                      private Rectangle enemy;
                                                                                  
                                                                                      private ArrayList projectiles = new ArrayList();
                                                                                      private ArrayList enemies = new ArrayList();
                                                                                  
                                                                                      @Override
                                                                                      public void start(Stage primaryStage) {
                                                                                  
                                                                                          root = new AnchorPane();
                                                                                          scene = new Scene(root, APP_WIDTH, APP_HEIGHT, Color.GHOSTWHITE);
                                                                                  
                                                                                          primaryStage.setTitle("Hello World!");
                                                                                          primaryStage.setScene(scene);
                                                                                          primaryStage.setResizable(false);
                                                                                          primaryStage.show();
                                                                                  
                                                                                          root.getChildren().addAll(player);
                                                                                  
                                                                                          controls();
                                                                                          loop();
                                                                                      }
                                                                                  
                                                                                      private void controls() {
                                                                                  
                                                                                          scene.setOnKeyPressed(event -> {
                                                                                              KeyCode key = event.getCode();
                                                                                  
                                                                                              switch (key) {
                                                                                                  case LEFT:
                                                                                                      goLeft = true;
                                                                                                      break;
                                                                                                  case RIGHT:
                                                                                                      goRight = true;
                                                                                                      break;
                                                                                                  case SPACE:
                                                                                                      if (!isShooting) {
                                                                                                          projectiles.add(projectile = new Rectangle(2, 10, Color.ORANGERED));
                                                                                                          projectile.relocate(x + player.getRadius(), y);
                                                                                                          root.getChildren().add(projectile);
                                                                                                          isShooting = true;
                                                                                                          break;
                                                                                                      }
                                                                                              }
                                                                                  
                                                                                          });
                                                                                          scene.setOnKeyReleased(event -> {
                                                                                              KeyCode key = event.getCode();
                                                                                  
                                                                                              switch (key) {
                                                                                                  case LEFT:
                                                                                                      goLeft = false;
                                                                                                      break;
                                                                                                  case RIGHT:
                                                                                                      goRight = false;
                                                                                                      break;
                                                                                                  case SPACE:
                                                                                                      isShooting = false;
                                                                                                      break;
                                                                                              }
                                                                                  
                                                                                          });
                                                                                  
                                                                                      }
                                                                                  
                                                                                      private void shoot() {
                                                                                          for (int i = 0; i < projectiles.size(); ++i) {
                                                                                              projectiles.get(i).relocate(projectiles.get(i).getLayoutX(), (projectiles.get(i).getLayoutY() - projectileSpeed));
                                                                                          }
                                                                                  
                                                                                          Iterator iterator = projectiles.iterator();
                                                                                  
                                                                                          while (iterator.hasNext()) {
                                                                                              projectile = iterator.next();
                                                                                              if (projectile.getLayoutY() < root.getLayoutY()) {
                                                                                  
                                                                                                  iterator.remove();
                                                                                                  root.getChildren().remove(projectile);
                                                                                  
                                                                                              }
                                                                                          }
                                                                                  
                                                                                      }
                                                                                  
                                                                                      private void spawnEnemy() {
                                                                                  
                                                                                          double spawnPosition = Math.random();
                                                                                  
                                                                                          int eWidth = 20;
                                                                                          int eHeight = 40;
                                                                                          double ex = (int) ((APP_WIDTH - eWidth) * spawnPosition);
                                                                                          int ey = (int) (root.getLayoutY());
                                                                                  
                                                                                          if (counter % spawnTime == 0) {
                                                                                  
                                                                                              enemy = new Rectangle(eWidth, eHeight);
                                                                                              enemy.relocate(ex, ey);
                                                                                              enemies.add(enemy);
                                                                                              root.getChildren().add(enemy);
                                                                                          }
                                                                                  
                                                                                      }
                                                                                  
                                                                                      public void moveEnemy(int delta) {
                                                                                  
                                                                                          for (int i = 0; i < enemies.size(); ++i) {
                                                                                              enemies.get(i).setY(enemies.get(i).getY() + delta);
                                                                                          }
                                                                                  
                                                                                          Iterator iterator = enemies.iterator();
                                                                                  
                                                                                          while (iterator.hasNext()) {
                                                                                              enemy = iterator.next();
                                                                                              if (enemy.getLayoutY() < root.getLayoutY()) {
                                                                                  
                                                                                                  iterator.remove();
                                                                                                  root.getChildren().remove(enemy);
                                                                                  
                                                                                              }
                                                                                          }
                                                                                      }
                                                                                  
                                                                                      private void loop() {
                                                                                  
                                                                                          AnimationTimer timer = new AnimationTimer() {
                                                                                  
                                                                                              @Override
                                                                                              public void handle(long now) {
                                                                                  
                                                                                                  if (goLeft) {
                                                                                                      dx = -5;
                                                                                                  }
                                                                                                  if (goRight) {
                                                                                                      dx = 5;
                                                                                                  }
                                                                                                  if (!goLeft && !goRight) {
                                                                                                      dx = 0;
                                                                                                  }
                                                                                                  player.relocate(x += dx, y);
                                                                                                  shoot();
                                                                                  
                                                                                                  counter++;
                                                                                  
                                                                                                  spawnEnemy();
                                                                                                  moveEnemy(4);
                                                                                  
                                                                                              }
                                                                                          };
                                                                                          timer.start();
                                                                                      }
                                                                                  
                                                                                      public static void main(String[] args) {
                                                                                          launch(args);
                                                                                      }
                                                                                  
                                                                                  }
                                                                                  

                                                                                  Now I'll play with the code a bit, try detecting collisions, restricting movement, adding some more stuff etc.

                                                                                  Source https://stackoverflow.com/questions/61279926

                                                                                  QUESTION

                                                                                  Why is the “root.after ()” method not stoppable?
                                                                                  Asked 2020-Feb-15 at 22:25

                                                                                  I'm trying to make a simple tool-path program with directional buttons. It works, but sometimes releasing the button is ineffective and the turtle stops just clicking the "Home" button. Else it just runs continuously as if I did not release the button.

                                                                                  Here is the code:

                                                                                  from tkinter import *
                                                                                  from turtle import RawTurtle, TurtleScreen
                                                                                  
                                                                                  def showPos():
                                                                                      monitor.delete('1.0', END)
                                                                                      monitor.insert(END, "X: " + str(tool.ycor()) +" Z: " + str(tool.xcor()))
                                                                                  
                                                                                  def goHome():
                                                                                      tool.home()
                                                                                      showPos()
                                                                                      stop_move()
                                                                                  
                                                                                  def goUp():
                                                                                      tool.sety(tool.ycor() + 10)
                                                                                  
                                                                                  def goDown():
                                                                                      tool.sety(tool.ycor() - 10)
                                                                                  
                                                                                  def goRight():
                                                                                      tool.setx(tool.xcor() + 10)
                                                                                  
                                                                                  def goLeft():
                                                                                      tool.setx(tool.xcor() - 10)
                                                                                  
                                                                                  def stop_move():
                                                                                      global jobid
                                                                                      root.after_cancel(jobid)
                                                                                  
                                                                                  def move(direction):
                                                                                      global jobid
                                                                                  
                                                                                      if direction == "-X":
                                                                                          goDown()
                                                                                  
                                                                                      if direction == "+X":
                                                                                          goUp()    
                                                                                  
                                                                                      if direction == "-Z":
                                                                                          goLeft()
                                                                                  
                                                                                      if direction == "+Z":
                                                                                          goRight()    
                                                                                  
                                                                                      jobid = root.after(10, move, direction)
                                                                                      showPos()
                                                                                  
                                                                                  jobid = None
                                                                                  
                                                                                  root = Tk()
                                                                                  root.title("CNC Lathe")
                                                                                  
                                                                                  canvas = Canvas(root, width=800, height=600)
                                                                                  canvas.pack()
                                                                                  
                                                                                  screen = TurtleScreen(canvas)
                                                                                  screen.bgcolor("black")
                                                                                  screen.register_shape("wnmg.gif")
                                                                                  
                                                                                  tool = RawTurtle(screen, shape="wnmg.gif")
                                                                                  tool.pencolor("white")
                                                                                  
                                                                                  monitor = Text(root, height=1, width=16, font="Helvetica")
                                                                                  monitor.pack()
                                                                                  
                                                                                  topFrame = Frame(root)
                                                                                  topFrame.pack()
                                                                                  middleFrame = Frame(root)
                                                                                  middleFrame.pack()
                                                                                  bottomFrame = Frame(root)
                                                                                  bottomFrame.pack()
                                                                                  
                                                                                  for direction in ("-X", "+X", "-Z", "+Z"):
                                                                                      if direction == "+X":
                                                                                          button = Button(topFrame, text=direction)
                                                                                          button.pack()
                                                                                  
                                                                                      if direction == "-X":
                                                                                          button = Button(bottomFrame, text=direction)
                                                                                          button.pack()
                                                                                  
                                                                                      if direction == "-Z":
                                                                                          button = Button(middleFrame, text=direction)
                                                                                          button.pack(side=LEFT)
                                                                                  
                                                                                      if direction == "+Z":
                                                                                          button = Button(middleFrame, text=direction)
                                                                                          button.pack(side=RIGHT)   
                                                                                  
                                                                                      button.bind('', lambda event, direction=direction: move(direction))
                                                                                      button.bind('', lambda event: stop_move())
                                                                                  
                                                                                  Button(middleFrame, text="Home", command=goHome).pack()
                                                                                  
                                                                                  root.mainloop()
                                                                                  

                                                                                  I tried to set the variable "jobid" to "None" after the "root.after_cancel ()" method, but nothing changed. At times this does not seem to detect the release of the button. Does anyone know a solution?

                                                                                  ANSWER

                                                                                  Answered 2020-Feb-15 at 22:25

                                                                                  I tried to make your code work with your jobid model, and although I could improve it, the flaw eventually surfaced -- I can't say exactly why. You have to consider that, in your implementation, jobid doesn't always represent a pending job, it could be one that has fired successfuly.

                                                                                  Another issue to consider is the timing of:

                                                                                  jobid = root.after(10, move, direction)
                                                                                  

                                                                                  The 10ms time has to be greater than the time it takes to execute the move() method, plus time to react. That is, if you can't draw the minimal size box (10 x 10) without repitition getting in your way, you again need to incress this time.

                                                                                  Below is my rework of your code using a simple state variable instead of the job id (plus some other changes.) It seems to solve the problem:

                                                                                  from tkinter import *
                                                                                  from turtle import RawTurtle, TurtleScreen
                                                                                  
                                                                                  def showPos():
                                                                                      monitor.delete('1.0', END)
                                                                                      monitor.insert(END, "X: " + str(tool.ycor()) + " Z: " + str(tool.xcor()))
                                                                                  
                                                                                  def goHome():
                                                                                      tool.home()
                                                                                      showPos()
                                                                                  
                                                                                  def goUp():
                                                                                      tool.sety(tool.ycor() + 10)
                                                                                  
                                                                                  def goDown():
                                                                                      tool.sety(tool.ycor() - 10)
                                                                                  
                                                                                  def goRight():
                                                                                      tool.setx(tool.xcor() + 10)
                                                                                  
                                                                                  def goLeft():
                                                                                      tool.setx(tool.xcor() - 10)
                                                                                  
                                                                                  pressing = False
                                                                                  
                                                                                  def start_move(event):
                                                                                      global pressing
                                                                                  
                                                                                      event.widget.unbind('')  # unbind event handler inside handler(s)
                                                                                  
                                                                                      pressing = True
                                                                                  
                                                                                      move(event)
                                                                                  
                                                                                  def stop_move(event):
                                                                                      global pressing
                                                                                  
                                                                                      pressing = False
                                                                                  
                                                                                      event.widget.bind('', start_move)
                                                                                  
                                                                                  def move(event):
                                                                                      if not pressing:
                                                                                          return
                                                                                  
                                                                                      direction = event.widget['text']
                                                                                  
                                                                                      if direction == '-X':
                                                                                          goDown()
                                                                                      elif direction == '+X':
                                                                                          goUp()    
                                                                                      elif direction == '-Z':
                                                                                          goLeft()
                                                                                      elif direction == '+Z':
                                                                                          goRight()    
                                                                                  
                                                                                      showPos()
                                                                                  
                                                                                      root.after(75, move, event)
                                                                                  
                                                                                  root = Tk()
                                                                                  root.title("CNC Lathe")
                                                                                  
                                                                                  canvas = Canvas(root, width=800, height=600)
                                                                                  canvas.pack()
                                                                                  
                                                                                  screen = TurtleScreen(canvas)
                                                                                  screen.bgcolor('black')
                                                                                  # screen.register_shape("wnmg.gif")
                                                                                  
                                                                                  # tool = RawTurtle(screen, shape="wnmg.gif")
                                                                                  tool = RawTurtle(screen, shape='turtle')
                                                                                  tool.pencolor('white')
                                                                                  
                                                                                  monitor = Text(root, height=1, width=16, font='Helvetica')
                                                                                  monitor.pack()
                                                                                  
                                                                                  topFrame = Frame(root)
                                                                                  topFrame.pack()
                                                                                  middleFrame = Frame(root)
                                                                                  middleFrame.pack()
                                                                                  bottomFrame = Frame(root)
                                                                                  bottomFrame.pack()
                                                                                  
                                                                                  for direction in ('-X', '+X', '-Z', '+Z'):
                                                                                      if direction == '+X':
                                                                                          button = Button(topFrame, text=direction)
                                                                                          button.pack()
                                                                                  
                                                                                      if direction == '-X':
                                                                                          button = Button(bottomFrame, text=direction)
                                                                                          button.pack()
                                                                                  
                                                                                      if direction == '-Z':
                                                                                          button = Button(middleFrame, text=direction)
                                                                                          button.pack(side=LEFT)
                                                                                  
                                                                                      if direction == '+Z':
                                                                                          button = Button(middleFrame, text=direction)
                                                                                          button.pack(side=RIGHT)   
                                                                                  
                                                                                      button.bind('', start_move)
                                                                                      button.bind('', stop_move)
                                                                                  
                                                                                  Button(middleFrame, text="Home", command=goHome).pack()
                                                                                  
                                                                                  root.mainloop()
                                                                                  

                                                                                  I changed the cursor to a turtle as I didn't have your "wnmg.gif" image to work with.

                                                                                  Source https://stackoverflow.com/questions/60239463

                                                                                  QUESTION

                                                                                  Pac Man cross obstacles
                                                                                  Asked 2019-Dec-26 at 21:39

                                                                                  I'm doing a Pac-Man game on c# , and pac man cross every obstacles that I pass.

                                                                                  This is the entire code of my Pac-Man game:

                                                                                  using System; 
                                                                                  using System.Media; 
                                                                                  using System.Windows.Forms;
                                                                                  
                                                                                  namespace Pac_Man {
                                                                                      public partial class Form1 : Form
                                                                                      {
                                                                                  

                                                                                  Variables:

                                                                                  bool goLeft;
                                                                                          bool goRight;
                                                                                          bool goUp;
                                                                                          bool goDown;
                                                                                  
                                                                                          int score = 0;
                                                                                          int totalCoins = 160;
                                                                                          int playerSpeed = 4;
                                                                                  
                                                                                          int ghost1 = 4;
                                                                                          int ghost2 = 4;
                                                                                  

                                                                                  Initializing:

                                                                                          public Form1()
                                                                                          {
                                                                                              InitializeComponent();
                                                                                              lblGame.Visible = false;
                                                                                              playSound();
                                                                                          }
                                                                                  

                                                                                  Play sound:

                                                                                          private void playSound()
                                                                                          {
                                                                                              SoundPlayer simpleSound = new SoundPlayer(@"C:\Users\rsss-\OneDrive\Documentos\Visual Studio 2019\Projects\Pac_Man\Pac_Man\Sound\pacman_beginning.wav");
                                                                                              simpleSound.PlayLooping();
                                                                                          }
                                                                                  

                                                                                  Key is down:

                                                                                          private void keyisdown(object sender, KeyEventArgs e)
                                                                                          {
                                                                                              if (e.KeyCode == Keys.Up)
                                                                                              {
                                                                                                  goUp = true;
                                                                                              }
                                                                                              if (e.KeyCode == Keys.Down)
                                                                                              {
                                                                                                  goDown = true;
                                                                                              }
                                                                                              if (e.KeyCode == Keys.Left)
                                                                                              {
                                                                                                  goLeft = true;
                                                                                              }
                                                                                              if (e.KeyCode == Keys.Right)
                                                                                              {
                                                                                                  goRight = true;
                                                                                              }
                                                                                          }
                                                                                  

                                                                                  Key is up:

                                                                                          private void keyisup(object sender, KeyEventArgs e)
                                                                                          {
                                                                                              if (e.KeyCode == Keys.Up)
                                                                                              {
                                                                                                  goUp = false;
                                                                                              }
                                                                                              if (e.KeyCode == Keys.Down)
                                                                                              {
                                                                                                  goDown = false;
                                                                                              }
                                                                                              if (e.KeyCode == Keys.Left)
                                                                                              {
                                                                                                  goLeft = false;
                                                                                              }
                                                                                              if (e.KeyCode == Keys.Right)
                                                                                              {
                                                                                                  goRight = false;
                                                                                              }
                                                                                          }
                                                                                  

                                                                                  Timer:

                                                                                          private void timer1_Tick(object sender, EventArgs e)
                                                                                          {
                                                                                              int movement = playerSpeed;
                                                                                              if (goLeft)
                                                                                              {
                                                                                                  foreach (Control x in this.Controls)
                                                                                                  {
                                                                                                      if (x is PictureBox && x.Tag == "obstacle" && x.Left == player.Left - playerSpeed && x.Top == player.Top)
                                                                                                      {
                                                                                                          movement = 0;
                                                                                                          break;
                                                                                                      }
                                                                                                  }
                                                                                                  player.Left -= movement;
                                                                                                  movement = playerSpeed;
                                                                                              }
                                                                                              else if (goRight)
                                                                                              {
                                                                                                  foreach (Control x in this.Controls)
                                                                                                  {
                                                                                                      if (x is PictureBox && x.Tag == "obstacle" && x.Left == player.Left + playerSpeed && x.Top == player.Top)
                                                                                                      {
                                                                                                          movement = 0;
                                                                                                          break;
                                                                                                      }
                                                                                                  }
                                                                                                  player.Left += movement;
                                                                                                  movement = playerSpeed;
                                                                                              }
                                                                                              else if (goUp)
                                                                                              {
                                                                                                  foreach (Control x in this.Controls)
                                                                                                  {
                                                                                                      if (x is PictureBox && x.Tag == "obstacle" && x.Top == player.Top - playerSpeed && x.Left == player.Left)
                                                                                                      {
                                                                                                          movement = 0;
                                                                                                          break;
                                                                                                      }
                                                                                                  }
                                                                                                  player.Top -= movement;
                                                                                                  movement = playerSpeed;
                                                                                              }
                                                                                              else if (goDown)
                                                                                              {
                                                                                                  foreach (Control x in this.Controls)
                                                                                                  {
                                                                                                      if (x is PictureBox && x.Tag == "obstacle" && x.Top == player.Top + playerSpeed && x.Left== player.Left)
                                                                                                      {
                                                                                                          movement = 0;
                                                                                                          break;
                                                                                                      }
                                                                                                  }
                                                                                                  player.Top += movement;
                                                                                                  movement = playerSpeed;
                                                                                              }
                                                                                  
                                                                                              if (player.Left > 641)
                                                                                              {
                                                                                                  player.Left = 82;
                                                                                              }
                                                                                              else if (player.Left < 82)
                                                                                              {
                                                                                                  player.Left = 641;
                                                                                              }
                                                                                  
                                                                                              foreach (Control x in this.Controls)
                                                                                              {
                                                                                                  if (x is PictureBox && x.Tag == "ghost")
                                                                                                  {
                                                                                                      if (((PictureBox)x).Bounds.IntersectsWith(player.Bounds))
                                                                                                      {
                                                                                                          gameOver();
                                                                                                          MessageBox.Show("You Lost!" + "\n" + "Your score is " + score);
                                                                                                          this.Close();
                                                                                                      }
                                                                                                  }
                                                                                              }
                                                                                  

                                                                                  Ghosts Movement:

                                                                                              redGhost.Left += ghost1;
                                                                                              orangeGhost.Left += ghost2;
                                                                                              blueGhost.Left -= ghost1;
                                                                                              pinkGhost.Left -= ghost2;
                                                                                  
                                                                                              foreach (Control c in this.Controls)
                                                                                              {
                                                                                                  if (c is PictureBox && c.Tag == "coin")
                                                                                                  {
                                                                                                      if (player.Bounds.IntersectsWith(c.Bounds))
                                                                                                      {
                                                                                                          this.Controls.Remove(c);
                                                                                                          score++;
                                                                                                      }
                                                                                                  }
                                                                                              }
                                                                                  
                                                                                              lblScore.Text = "Score: " + score;
                                                                                              if (score == totalCoins)
                                                                                              {
                                                                                                  gameOver();
                                                                                                  MessageBox.Show("You Win!" + "\n" + "You reach the maximum score: " + score);
                                                                                                  this.Close();
                                                                                              }
                                                                                  
                                                                                          }
                                                                                  

                                                                                  Game Over:

                                                                                          private void gameOver()
                                                                                          {
                                                                                              timer1.Stop();
                                                                                              lblGame.Visible = true;
                                                                                              lblGame.Text = "Game Over!";
                                                                                          }
                                                                                      } }
                                                                                  

                                                                                  Basically, I want that the character don't move in that direction if he hits an obstacle. Anyone can help me? Thank you.

                                                                                  ANSWER

                                                                                  Answered 2019-Dec-26 at 21:39

                                                                                  This is a different and hopefully simpler way to test for obstacle hit, I dont know if it can compile but i hope you get the general idea

                                                                                  First calculate x and y movement, then apply that movement to a copy of the players bounds and check if it intersects with any obstacle, if it does break out of the loop, if not test next obstacle If no intersections found then move the player

                                                                                  Need to ensure that System.Drawing.Rectangle originalBounds = player.Bounds actually creates a copy of the players bounds, otherwise the player will move back and forward while the loop is running

                                                                                   private void timer1_Tick(object sender, EventArgs e)
                                                                                   {
                                                                                       int moveX = 0;
                                                                                       int moveY = 0;
                                                                                       bool hitObstacle = false;
                                                                                       System.Drawing.Rectangle originalBounds = player.Bounds; // make sure this is a copy of players bounds rectangle. 
                                                                                  
                                                                                  
                                                                                       if(goLeft)     
                                                                                          moveX = -playerSpeed;
                                                                                       else if(goRight)     
                                                                                          moveX = playerSpeed;
                                                                                       else if (goUp)
                                                                                          moveY = -playerSpeed;
                                                                                       else if (goDown)
                                                                                           moveY = playerSpeed;
                                                                                  
                                                                                       originalBounds.Offset(moveX,moveY);
                                                                                  
                                                                                       foreach (Control x in this.Controls)
                                                                                       {
                                                                                          if (x is PictureBox && x.Tag == "obstacle") {
                                                                                  
                                                                                              if (originalBounds.IntersectsWith(x.Bounds)) {
                                                                                                  hitObstacle = true;
                                                                                                  break;
                                                                                              }
                                                                                           }     
                                                                                           if(hitObstacle==false) {
                                                                                              player.Bounds=originalBounds;
                                                                                            }
                                                                                  
                                                                                           if (player.Left > 641)
                                                                                           ..... 
                                                                                  

                                                                                  Source https://stackoverflow.com/questions/59490558

                                                                                  Community Discussions, Code Snippets contain sources that include Stack Exchange Network

                                                                                  Vulnerabilities

                                                                                  No vulnerabilities reported

                                                                                  Install goleft

                                                                                  The easiest way to install goleft is to download the latest binary from the releases and make sure to chmod +x the resulting binary.

                                                                                  Support

                                                                                  For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
                                                                                  Find more information at:
                                                                                  Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
                                                                                  Find more libraries
                                                                                  Explore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits​
                                                                                  Save this library and start creating your kit

                                                                                  Share this Page

                                                                                  share link

                                                                                  Reuse Pre-built Kits with goleft

                                                                                  Consider Popular Genomics Libraries

                                                                                  Try Top Libraries by brentp

                                                                                  cyvcf2

                                                                                  by brentpPython

                                                                                  vcfanno

                                                                                  by brentpGo

                                                                                  bio-playground

                                                                                  by brentpC

                                                                                  smoove

                                                                                  by brentpGo

                                                                                  cruzdb

                                                                                  by brentpPython

                                                                                  Compare Genomics Libraries with Highest Support

                                                                                  picard

                                                                                  by broadinstitute

                                                                                  galaxy

                                                                                  by galaxyproject

                                                                                  gatk

                                                                                  by broadinstitute

                                                                                  cbioportal

                                                                                  by cBioPortal

                                                                                  intermine

                                                                                  by intermine

                                                                                  Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
                                                                                  Find more libraries
                                                                                  Explore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits​
                                                                                  Save this library and start creating your kit