Advertisement
dannylol

p5lua Reference

Jul 13th, 2020
798
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.55 KB | None | 0 0
  1. --[[
  2.        _____ _            
  3.       | ____| |            
  4.   _ __| |__ | |_   _  __ _
  5.  | '_ \___ \| | | | |/ _` |
  6.  | |_) |__) | | |_| | (_| |
  7.  | .__/____/|_|\__,_|\__,_|
  8.  | |                      
  9.  |_|                      
  10.  
  11.     Hello!
  12.     p5lua is a lua version of the popular javascript library p5js.
  13.     This is the full reference of the p5lua library.
  14.  
  15.     (Note: p5lua is still being worked on and I will add more methods and functions later.)
  16. ]]
  17.  
  18. -- First, you must load the library.
  19. local p5 = loadstring(game:HttpGet('https://pastebin.com/raw/8BKNLVeC'))()
  20. --[[You can replace p5 with any variable name,
  21. but remember to use it as your calling variable later. ]]
  22.  
  23. -- Here are the constants:
  24. p5.HALF_PI -- pi / 2.
  25. p5.PI -- pi.
  26. p5.QUARTER_PI -- pi / 4.
  27. p5.TAU -- 2 * pi.
  28. p5.TWO_PI -- 2 * pi.
  29.  
  30. p5.width -- Width of screen.
  31. p5.height -- Height of screen.
  32.  
  33.  
  34. -- Here are the basic methods:
  35. p5:createCanvas(sizeX, sizeY, canvasColor, cursor, pos, cursorColor)
  36. --[[ Creates a canvas of specified size.
  37.      - 'sizeX': int(mandatory)
  38.      - 'sizeY': int(mandatory)
  39.      - 'canvasColor': Color3(optional)
  40.      - 'cursor': boolean(optional) -- Gives mouse a cursor when hovering over canvas.
  41.      - 'pos': Vector2(optional)
  42.      - 'cursorColor': Color3(optional)]]
  43.      
  44. p5:translate(x, y) -- Translates 0, 0 to x, y.
  45. p5:pVector2(x, y)   --[[ Returns a Vector2 value affected by p5:translate()
  46.                         Note: regular Vector2 values are not affected by p5:translate(). ]]
  47.  
  48. p5:mouseX() -- Returns the mouse's X position.
  49. p5:mouseY() -- Returns the mouse's Y position.
  50.  
  51. p5:dist(x1, y1, x2, y2) -- Returns the distance of x2, y2 from x1, y1.
  52.  
  53. p5:round(num, DecimalPlaces) -- Rounds num to DecimalPlaces.
  54.  
  55. p5:map(value, fromLow, fromHigh, toLow, toHigh) --[[ Re-maps a number
  56.                                                 from one range to another.]]
  57.  
  58. p5:point(x, y, size, color) -- Draws a point at x, y.
  59.  
  60.  
  61. -- Here are the advanced methods:
  62. p5:beginShape(key)
  63. p5:vertex(key, x, y)
  64. p5:endShape(key)
  65. --[[ Using the beginShape() and endShape() functions allow creating more
  66.     complex forms. beginShape() begins recording vertices for a shape and
  67.     endShape() stops recording. ]]
  68.  
  69. --[[ You will see the use of 'key' in most p5lua advanced methods.
  70.     It is used for p5lua to interpret what object you are trying to access.
  71.     (The key must always be a string.) For example, if I want to create a
  72.     new shape, I must create my key in the beginShape() method.
  73.     Then use that same key to add vertices with vertex(), or
  74.     end the shape with endShape(). ]]
  75.  
  76. -- Here is an example of the usage of 'key':
  77.  
  78. p5:beginShape('Shape1') --[[ This creates a new shape
  79.                             with the unique key 'Shape1'. ]]
  80.  
  81. p5:vertex('Shape1', 100, 500) -- Adding vertices to 'Shape1'.
  82. p5:vertex('Shape1', 200, 550)
  83.  
  84. p5:endShape('Shape1') --[[ This will connect all the vertices.
  85.                             (Therefore drawing the shape.) ]]
  86.  
  87. p5:createSlider(key, min, max, start, pos, w, color, textcolor, decimalPlaces)
  88. --[[ The p5lua createSlider method can appear a bit confusing with all
  89.     the parameters, but it is actually very simple.
  90.    
  91.     (some parameters are optional such as:
  92.         color, textcolor and decimalPlaces)
  93.    
  94.     - 'key' is used to store and grab the value from your slider.
  95.    
  96.     - 'min' and 'max'  are self explanatory, they are the
  97.     minimum and maximum values your slider should go to.
  98.  
  99.     - 'start' dictates what value the slider starts at.
  100.  
  101.     - 'pos' dictates what position the slider is on the screen.
  102.  
  103.     - 'w' (short for width) is how wide/long the slider should be.
  104.  
  105.     - 'color' the color of the slider button.
  106.     (by default set to Color3.fromRGB(71, 161, 202))
  107.  
  108.     - 'textcolor' the color of the slider value text.
  109.     (by default set to Color3.fromRGB(255, 255, 255))
  110.  
  111.     - 'decimalPlaces' if you would like the slider value to be rounded.
  112.         (by default set to 1)
  113.     ]]
  114.  
  115.     -- Here is an example using the createSlider method:
  116. p5:createSlider('Red', 0, 255, 0, Vector2.new(200, 400), 100, Color3.fromRGB(255, 0, 0), Color3.fromRGB(0, 0, 0), 0)
  117.  
  118. -- Use your key to index the correct value in the p5.Values table.
  119. p5.Values['Red']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement