Skip to content

Commit aca31d1

Browse files
added dist() and updated docs
1 parent 0788cbd commit aca31d1

File tree

4 files changed

+52
-12
lines changed

4 files changed

+52
-12
lines changed

README.md

+40-10
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,26 @@ def draw():
268268

269269
# Docs
270270

271+
### constants
272+
273+
- mouseX
274+
275+
position of x-coord of mouse
276+
277+
- mouseY
278+
279+
position of y-coord of mouse
280+
281+
- width
282+
283+
width of the canvas
284+
285+
- height
286+
287+
height of the canvas
288+
289+
### main functions
290+
271291
- setup()
272292

273293
Used to initialise what will be used only once
@@ -276,6 +296,8 @@ Used to initialise what will be used only once
276296

277297
code to be looped is placed in it
278298

299+
### graphics
300+
279301
- line()
280302

281303
```python
@@ -294,6 +316,18 @@ rect(x, y, width, height)
294316
ellipse(x, y, width, height)
295317
```
296318

319+
- beginShape()
320+
321+
```python
322+
beginShape()
323+
vertex(x1, y1)
324+
vertex(x2, y2)
325+
vertex(x3, y3)
326+
endShape()
327+
```
328+
329+
### fill control
330+
297331
- background()
298332

299333
```python
@@ -346,6 +380,8 @@ noStroke()
346380

347381
Removes strokes
348382

383+
### utility
384+
349385
- random()
350386

351387
```python
@@ -356,19 +392,13 @@ random() # returns arbitrary value from 0 to 1
356392

357393
Returns integer inclusive of start, exclusive of end
358394

359-
- beginShape()
395+
- dist
360396

361397
```python
362-
beginShape()
363-
vertex(x1, y1)
364-
vertex(x2, y2)
365-
vertex(x3, y3)
366-
endShape()
398+
dist(x1, x2, y1, y2)
367399
```
368-
- mouseX
369400

370-
position of x-coord of mouse
401+
Returns 2D distance between 2 coordinates.
402+
371403

372-
- mouseY
373404

374-
position of y-coord of mouse

ppython/dump/dump.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ def vertex(x, y):
149149
def endShape(*args):
150150
_p.polygon()
151151

152+
def dist(x1, y1, x2, y2):
153+
squared_delta_x = (x2 - x1) ** 2
154+
squared_delta_y = (y2 - y1) ** 2
155+
return sqrt(squared_delta_x + squared_delta_y)
156+
152157

153158

154159
from tkinter import *
@@ -162,7 +167,7 @@ def endShape(*args):
162167

163168
def setup():
164169
global width, height, mouseX, mouseY
165-
print(random())
170+
print(dist(0, 0, 0, 100))
166171

167172
def draw():
168173
global root, width, height, mouseX, mouseY

ppython/lab.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
def setup():
2-
print(random())
2+
print(dist(0, 0, 0, 100))
33

44
def draw():
55
#background(100)

ppython/template.py

+5
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ def vertex(x, y):
149149
def endShape(*args):
150150
_p.polygon()
151151

152+
def dist(x1, y1, x2, y2):
153+
squared_delta_x = (x2 - x1) ** 2
154+
squared_delta_y = (y2 - y1) ** 2
155+
return sqrt(squared_delta_x + squared_delta_y)
156+
152157

153158

154159
from tkinter import *

0 commit comments

Comments
 (0)