skip to Main Content
import numpy as np
import matplotlib.pyplot as plt

# INITIAL CONDITIONS
m = 550E03 # kg
r = 3.7 / 2 # m
l = 70 # m

I = m * ( (r ** 2) / 4 + (l ** 2) / 12 ) # kg * m^2

position = [0, 0] # m
velocity = [0, 0] # m/s
acceleration = [0, 0] # m/s^2
theta = np.pi / 2 # rad

F_g = [0, -53.935E06] # N
F_R = [80.905E06 * np.cos(theta), 80.905E06 * np.sin(theta)] # N

With this code, VS Code seems to change the color of the variable F_R arbitrarily. I’ve noticed it does the same for any variable named with the format [Capital Letter]_[Capital Letter]. Any particular idea why this might be the case, and/or how to change this? It is not dependent on VS Code’s Color Theme.

enter image description here

2

Answers


  1. As per PEP-8:

    Constants

    Constants are usually defined on a module level and written in all
    capital letters with underscores separating words. Examples include
    MAX_OVERFLOW and TOTAL.

    VSCode considers F_R constant and that’s why the color is different. You can confirm if hoover with mouse over it.

    As a side note, with my setup of VSCode, all other variables/names are light-blue and pylint complains they don’t conform to naming convention for constants.

    Login or Signup to reply.
  2. The answer by buran already explains why the colors are different. Here’s a way to modify the color.

    vscode syntax highlighting is related to the theme.

    enter image description here
    Theme: [Abyss]

    enter image description here
    Theme: [Dark High Contrast]

    You can customize syntax highlighting in settings.json with the following configuration

    "editor.tokenColorCustomizations": {
            "[Default Dark+]": {
                "textMateRules": [
                    {
                        "scope": "variable.other.constant",
                        "settings": {
                            "foreground": "#FF0000"
                        }
                    }
                ]
            }
        }
    

    enter image description here
    Theme: [Default Dark+]

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search