-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathroundedSquare.py
More file actions
146 lines (100 loc) · 6.26 KB
/
roundedSquare.py
File metadata and controls
146 lines (100 loc) · 6.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#This Source Code Form is subject to the terms of the Mozilla Public
#License, v. 2.0. If a copy of the MPL was not distributed with this
#file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#Created by Fabrice Fernandez on 22/07/2019.
import string
import NatronEngine
from NatronGui import *
from PySide.QtGui import *
# CREATE A FULL FRAME ROUNDED SQUARE #
def roundedSquare():
# get current Natron instance running in memory
app = natron.getGuiInstance(0)
dialog = app.createModalDialog()
# set dialog title #
dialog.setWindowTitle("Rounded square")
# set dialog margins #
dialog.setContentsMargins(0, 0, 10, 10)
# set window size #
dialog.resize( 400, 100 )
# UI creation #
line01 = dialog.createStringParam("line01","")
line01.setType(NatronEngine.StringParam.TypeEnum.eStringTypeLabel)
line02 = dialog.createStringParam("line02","")
line02.setType(NatronEngine.StringParam.TypeEnum.eStringTypeLabel)
hardnessParameter = dialog.createDoubleParam("userHardness","Hardness : ")
hardnessParameter.setDefaultValue(10)
hardnessParameter.restoreDefaultValue()
hardnessParameter.setMinimum(3)
hardnessParameter.setDisplayMinimum(3)
hardnessParameter.setDisplayMaximum(20)
#################################################
# Refresh UI #
dialog.refreshUserParamsGUI()
# if user press 'OK' #
if dialog.exec_():
# create a 'Roto' node
myRoto = app.createNode("fr.inria.built-in.Roto")
# set 'Roto' label
myRoto.setLabel('rounded_Square1')
# get input image size
imageWidth = myRoto.getOutputFormat().width()
imageHeight = myRoto.getOutputFormat().height()
roundness = imageHeight / hardnessParameter.get()
tangentRoundness = roundness / 2
# get roto context
rotoContext = myRoto.getRotoContext()
# get 'Base Layer'
rootLayer = rotoContext.getBaseLayer()
# create one point bezier curve at frame 1
# point 0
newSquare = rotoContext.createBezier( (imageWidth / 2) - (imageHeight/2) + roundness , 0 , 1 )
currentPoint = newSquare.getControlPointPosition( 0 , 1 )
newSquare.setPointAtIndex( 0 , 1 , currentPoint[0] , currentPoint[1] , currentPoint[0] - tangentRoundness , 0 , currentPoint[0] + tangentRoundness , 0 )
newSquare.setFeatherPointAtIndex( 0 , 1 , currentPoint[0] , currentPoint[1] , currentPoint[0] - tangentRoundness , 0 , currentPoint[0] + tangentRoundness , 0 )
newSquare.setScriptName("rounded_Square1")
newSquare.setLabel("rounded_Square1")
newSquare.setLocked(False)
newSquare.setVisible(True)
# point 1
newSquare.addControlPoint( (imageWidth / 2) + (imageHeight/2) - roundness , 0 )
currentPoint = newSquare.getControlPointPosition( 1 , 1 )
newSquare.setPointAtIndex( 1 , 1 , currentPoint[0] , currentPoint[1] , currentPoint[0] - tangentRoundness , 0 , currentPoint[0] + tangentRoundness , 0 )
newSquare.setFeatherPointAtIndex( 1 , 1 , currentPoint[0] , currentPoint[1] , currentPoint[0] - tangentRoundness , 0 , currentPoint[0] + tangentRoundness , 0 )
# point 2
newSquare.addControlPoint( (imageWidth / 2) + (imageHeight/2) , roundness )
currentPoint = newSquare.getControlPointPosition( 2 , 1 )
newSquare.setPointAtIndex( 2 , 1 , currentPoint[0] , currentPoint[1] , currentPoint[0] , currentPoint[1] - tangentRoundness , currentPoint[0] , currentPoint[1] + tangentRoundness )
newSquare.setFeatherPointAtIndex( 2 , 1 , currentPoint[0] , currentPoint[1] , currentPoint[0] , currentPoint[1] - tangentRoundness , currentPoint[0] , currentPoint[1] + tangentRoundness )
# point 3
newSquare.addControlPoint( (imageWidth / 2) + (imageHeight/2) , imageHeight - roundness )
currentPoint = newSquare.getControlPointPosition( 3 , 1 )
newSquare.setPointAtIndex( 3 , 1 , currentPoint[0] , currentPoint[1] , currentPoint[0] , currentPoint[1] - tangentRoundness , currentPoint[0] , currentPoint[1] + tangentRoundness )
newSquare.setFeatherPointAtIndex( 3 , 1 , currentPoint[0] , currentPoint[1] , currentPoint[0] , currentPoint[1] - tangentRoundness , currentPoint[0] , currentPoint[1] + tangentRoundness )
# point 4
newSquare.addControlPoint( (imageWidth / 2) + (imageHeight/2) - roundness , imageHeight )
currentPoint = newSquare.getControlPointPosition( 4 , 1 )
newSquare.setPointAtIndex( 4 , 1 , currentPoint[0] , currentPoint[1] , currentPoint[0] + tangentRoundness , imageHeight , currentPoint[0] - tangentRoundness , imageHeight )
newSquare.setFeatherPointAtIndex( 4 , 1 , currentPoint[0] , currentPoint[1] , currentPoint[0] + tangentRoundness , imageHeight , currentPoint[0] - tangentRoundness , imageHeight )
# point 5
newSquare.addControlPoint( (imageWidth / 2) - (imageHeight/2) + roundness , imageHeight )
currentPoint = newSquare.getControlPointPosition( 5 , 1 )
newSquare.setPointAtIndex( 5 , 1 , currentPoint[0] , currentPoint[1] , currentPoint[0] + tangentRoundness , imageHeight , currentPoint[0] - tangentRoundness , imageHeight )
newSquare.setFeatherPointAtIndex( 5 , 1 , currentPoint[0] , currentPoint[1] , currentPoint[0] + tangentRoundness , imageHeight , currentPoint[0] - tangentRoundness , imageHeight )
# point 6
newSquare.addControlPoint( (imageWidth / 2) - (imageHeight/2) , imageHeight - roundness )
currentPoint = newSquare.getControlPointPosition( 6 , 1 )
newSquare.setPointAtIndex( 6 , 1 , currentPoint[0] , currentPoint[1] , currentPoint[0] , currentPoint[1] + tangentRoundness , currentPoint[0] , currentPoint[1] - tangentRoundness )
newSquare.setFeatherPointAtIndex( 6 , 1 , currentPoint[0] , currentPoint[1] , currentPoint[0] , currentPoint[1] + tangentRoundness , currentPoint[0] , currentPoint[1] - tangentRoundness )
# point 7
newSquare.addControlPoint( (imageWidth / 2) - (imageHeight/2) , roundness )
currentPoint = newSquare.getControlPointPosition( 7 , 1 )
newSquare.setPointAtIndex( 7 , 1 , currentPoint[0] , currentPoint[1] , currentPoint[0] , currentPoint[1] + tangentRoundness , currentPoint[0] , currentPoint[1] - tangentRoundness )
newSquare.setFeatherPointAtIndex( 7 , 1 , currentPoint[0] , currentPoint[1] , currentPoint[0] , currentPoint[1] + tangentRoundness , currentPoint[0] , currentPoint[1] - tangentRoundness )
# close the curve
newSquare.setCurveFinished(1)
# add created bezier to 'Base Layer'
rootLayer.addItem(newSquare)
# set center position
myRoto.getParam('center').setValue(imageWidth/2,0)
myRoto.getParam('center').setValue(imageHeight/2,1)