About ads on Siafoo
Hide Siafoo is here to make coding less frustrating and to save you time. Learn More Join Siafoo

Utility Geometry Code

In Brief: A few simple geometric functions for Nodebox projects. The angle, distance, and coordinates functions originally derived from the Math Tutorial at the Nodebox website. All others added by members of the Siafoo community.... more
Language Nodebox Python
# 's
 1def angle(x0, y0, x1, y1):
2 from math import degrees, atan2
3 a = degrees( atan2(y1-y0, x1-x0) )
4 return a
5
6def distance(x0, y0, x1, y1):
7 from math import sqrt, pow
8 return sqrt(pow(x1-x0, 2) + pow(y1-y0, 2))
9
10def coordinates(x0, y0, distance, angle):
11 from math import radians, sin, cos
12 x1 = x0 + cos(radians(angle)) * distance
13 y1 = y0 + sin(radians(angle)) * distance
14 return x1, y1
15
16def relative_coordinates(x0,y0,distance,angle):
17 from math import radians, sin, cos
18 x1 = cos(radians(angle)) * distance
19 y1 = sin(radians(angle)) * distance
20 return x1, y1
21
22def centered_text_path(text_string,container_path,scaling=True):
23 ''' Accepts a string and a bezier path (Nodebox-style implementation)
24
25 Returns a Bezier path of the string text, located at the center of the target path'''
26
27 cont_bounds = container_path.bounds
28 cont_origin = cont_bounds.origin
29 cont_size = cont_bounds.size
30
31 c_x = cont_origin.x
32 c_y = cont_origin.y
33
34 c_width = cont_size.width
35 c_height = cont_size.height
36 tp_h = textheight(text_string)
37
38 x_offset = c_x + 0.1*c_width
39 y_offset = c_y + 0.5*c_height + 0.25*tp_h
40 push()
41 align(CENTER)
42
43 tp = textpath(text_string,x_offset,y_offset,width=c_width*0.8,height=c_height)
44 pop()
45 return tp

A few simple geometric functions for Nodebox projects. The angle, distance, and coordinates functions originally derived from the Math Tutorial at the Nodebox website. All others added by members of the Siafoo community.

Note that many of these functions depend on the inherited functionality of the Nodebox environment.

Keywords nodebox (7) geometry (1) utility (1)
Included in this Library
Average
n/a
Rated
0
Times
5
4
3
2
1
0
License Public Domain
Lines 37
Owner: Theodore Test
Group Owner: Nodebox Community
Viewable by Everyone
Editable by All Siafoo Users
Sponsored Links
About ads on Siafoo