Skip to content

Commit

Permalink
add/remove scenes, added log file
Browse files Browse the repository at this point in the history
  • Loading branch information
MrNothing committed Dec 12, 2017
1 parent 4933c2c commit 959c100
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 41 deletions.
44 changes: 41 additions & 3 deletions Sources/build_scripts/global_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def SendPieData(id, name, color='#3e95cd', flush=True):
Log("pie:"+str(id)+":"+str(name)+":"+str(color), flush)

#data contains an array or normalized inputs (from 0 to 1)
def SendImageData(id, data, width=32, height=32, name="", rgba=False, flush=True, invert=False, offset=0):
def SendImageData(id, data, width=32, height=32, name="", rgba=False, flush=True, invert=False, offset=0, resize=[]):
if EDITOR_MODE:
img = Image.new( 'RGBA', (width,height), "white")
pixels = img.load()
Expand All @@ -57,6 +57,8 @@ def SendImageData(id, data, width=32, height=32, name="", rgba=False, flush=True
else:
pixels[x,y] = (int(pixel[0]*255), int(pixel[1]*255), int(pixel[2]*255), 255) # set the colour accordingly

if len(resize)>0:
img = img.resize((resize[0], resize[1]), Image.NEAREST)

tmpDir = tempfile.gettempdir()
imgPath = str(tmpDir)+"/"+name+"_out_"+str(id)+"_"+str(offset)+".png"
Expand Down Expand Up @@ -178,6 +180,27 @@ def CarveNumber(pixels, number, x, y, bg = (255, 255, 255, 255), color=(0, 0, 0,
IOHelpers.CarveDigit(pixels, str_num[i], x+loc_x, y, bg, color)
loc_x+=4

def CreateImage(data, width=32, height=32, rgba=False, invert=False, resize=[]):
img = Image.new( 'RGBA', (width,height), "white")
pixels = img.load()

for i in range(len(data)): # for every pixel:
y = int(np.floor(i/width))
x = i-y*width
#print("coord: "+str(x)+"_"+str(y)+":"+str(data[i]))
if rgba:
pixel = max(0, data[i])
else:
pixel = [max(0, data[i]), max(0, data[i]), max(0, data[i]), 1]
if invert:
pixels[x,height-y-1] = (int(pixel[0]*255), int(pixel[1]*255), int(pixel[2]*255), 255) # set the colour accordingly
else:
pixels[x,y] = (int(pixel[0]*255), int(pixel[1]*255), int(pixel[2]*255), 255) # set the colour accordingly

if len(resize)>0:
img = img.resize((resize[0], resize[1]), Image.NEAREST)

return img

def CarveDigit(pixels, digit, x, y, bg = (255, 255, 255, 255), color=(0, 0, 0, 255)):
#3x5 = 15pixels
Expand Down Expand Up @@ -732,7 +755,7 @@ def avg(data=[], steps=-1):

return _sum/divider

def entropy(data=[], ground=0.5, multiplier = 3):
def entropy(data=[], ground=0, multiplier = 3):
_sum = 0
_len = max(1, len(data))
for v in data:
Expand Down Expand Up @@ -775,7 +798,22 @@ def normalize(sample):
sample[i] = sample[i]/_max
return sample

def normalize2D(sample):
_max = 0
for m in sample:
for n in m:
if abs(n)>_max:
_max = abs(n)

for i in range(len(sample)):
for j in range(len(sample[i])):
sample[i][j] = sample[i][j]/_max
return sample

def Spectrogram(samples, samplerate):
from scipy import signal
frequencies, times, spectogram = signal.spectrogram(samples, len(samples))
return spectogram
return spectogram

def Sigmoid(data):
pass
60 changes: 41 additions & 19 deletions Sources/scripts/convolutions.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,54 @@
#description An onvolutional layer
#description An 2D convolutional layer
#icon fa fa-sitemap
#param list:conv,deconv,
type = "conv"
#param list:conv2d,deconv2d,maxpool2d
type = "conv2d"
#zone type==conv2d
#param array|int
shape = [5, 5, 1, 32]
#param int
out_channels = 32
#zone type==conv
strides = 1
#endzone

#zone type==maxpool2d
#param int
stride = 2
k = 2
#endzone

def Run(batch_input):
out_channels = self.out_channels
stride = self.stride
self.variables = []

if self.type=="conv":
with tf.variable_scope(self.name):
in_channels = batch_input.get_shape()[3]
filter = tf.get_variable("filter", [4, 4, in_channels, out_channels], dtype=tf.float32, initializer=tf.random_normal_initializer(0, 0.02))
# [batch, in_height, in_width, in_channels], [filter_width, filter_height, in_channels, out_channels]
# => [batch, out_height, out_width, out_channels]
padded_input = tf.pad(batch_input, [[0, 0], [1, 1], [1, 1], [0, 0]], mode="CONSTANT")
conv = tf.nn.conv2d(padded_input, filter, [1, stride, stride, 1], padding="VALID")
return conv
def Run(self, batch_input, reuse=False):

if self.type=="conv2d":
W = tf.Variable(tf.random_normal(self.shape))
b = tf.Variable(tf.random_normal([self.shape[3]]))

self.variables.append(W)
self.variables.append(b)

x = self.conv2d(batch_input, W, b, strides=self.strides, name=self.name)
Log(self.name+" "+str(x.get_shape()))
return x
elif self.type=="maxpool2d":
x = self.maxpool2d(batch_input, k=self.k, name=self.name)
Log(self.name+" "+str(x.get_shape()))
return x
else:
stride = self.strides
out_channels = self.out_channels
with tf.variable_scope(self.name):
batch, in_height, in_width, in_channels = [int(d) for d in batch_input.get_shape()]
filter = tf.get_variable("filter", [4, 4, out_channels, in_channels], dtype=tf.float32, initializer=tf.random_normal_initializer(0, 0.02))
# [batch, in_height, in_width, in_channels], [filter_width, filter_height, out_channels, in_channels]
# => [batch, out_height, out_width, out_channels]
conv = tf.nn.conv2d_transpose(batch_input, filter, [batch, in_height * 2, in_width * 2, out_channels], [1, 2, 2, 1], padding="SAME")
return conv
return conv

def conv2d(self, x, W, b, strides=1, name=""):
# Conv2D wrapper, with bias and relu activation
x = tf.nn.conv2d(x, W, strides=[1, strides, strides, 1], padding='SAME', name=name)
x = tf.nn.bias_add(x, b)
return tf.nn.relu(x)

def maxpool2d(self, x, k=2, name=""):
# MaxPool2D wrapper
return tf.nn.max_pool(x, ksize=[1, k, k, 1], strides=[1, k, k, 1], padding='SAME', name=name)
10 changes: 9 additions & 1 deletion Sources/scripts/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
#description Activation functions: softmax, relu, tanh, sigmoid etc...
#icon fa fa-flask

#param list: sigmoid, tanh, softmax, relu, batchnorm, lrelu
#param list: sigmoid, tanh, softmax, relu, batchnorm, lrelu, reshape
function = "sigmoid"
#zone function==lrelu
#param float
a = 1
#endzone

#zone function==reshape
#param array|eval
shape = [-1, 100]
#endzone


def Run(self, x, reuse=False):
Log(self.function)

Expand All @@ -23,6 +29,8 @@ def Run(self, x, reuse=False):
return self.batchnorm(x)
elif self.function=="lrelu":
return self.lrelu(x)
elif self.function=="reshape":
return tf.reshape(x, self.shape)
else:
return tf.nn.relu(x)

Expand Down
2 changes: 2 additions & 0 deletions Sources/src/Model/Controllers/GlobalService.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default class GlobalService
this.sceneReady = false;
this.hierarchyReady = false;
this.running = false;
this.running_scene = 0;

this.propertiesUI = null;
this.projectPropertiesUI = null;
Expand Down Expand Up @@ -217,6 +218,7 @@ export default class GlobalService
this.runningUI.forceUpdate();
this.sceneUI.forceUpdate();
window.service.builder = null;
document.getElementById("activeTab_"+window.service.running_scene).className = "glyphicon glyphicon-picture";
}

copySelection()
Expand Down
4 changes: 3 additions & 1 deletion Sources/src/Model/Managers/ProjectRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ const { spawn } = require('child_process');
export default class ProjectRunner{
constructor(folder) {
this.folder = folder;
window.service.log("Running scene: "+window.service.currentScene, "", 0);
window.service.running_scene = window.service.currentScene;
window.service.log("Running scene: "+window.service.project.sceneNames[window.service.currentScene], "", 0);
window.service.consoleWindow.selectTab(1)
window.service.updatedDynamicVars = true;

const exec = spawn('python', [folder+'/main.py']);
window.service.runningProcess = exec;
Expand Down
13 changes: 13 additions & 0 deletions Sources/src/Model/UI/Properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,18 @@ export default class Properties extends React.Component {
filePicker(script, paramID, listIndex, isFile)
{
let selected_dir;

/*let defaultpath;
if(listIndex!=null)
{
let splitlist = script.params[paramID].value.split(";")
defaultpath = splitlist[listIndex];
}
else
{
defaultpath = script.params[paramID].value;
}*/

if(isFile)
selected_dir = require('electron').remote.dialog.showOpenDialog({title:"Select a file...", properties: ['openFile']});
else
Expand Down Expand Up @@ -248,6 +260,7 @@ export default class Properties extends React.Component {
else if(script.params[p].type.trim()=="folder" || script.params[p].type.trim()=="file")
{
let domID = "script_input_"+p;

params.push(
<div key={script.params[p].name+"_"+script.id+"_"+p} className="input-group">
<span className="input-group-addon input-group-small input-group-addon-small">{script.params[p].name}:</span>
Expand Down
72 changes: 56 additions & 16 deletions Sources/src/Model/UI/Window.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class Window extends React.Component {

editSceneName(sceneID)
{
this.setState({editing:true, sceneEdit:sceneID, newSceneName:window.service.project.sceneNames[sceneID-1]});
this.setState({editing:true, sceneEdit:sceneID, newSceneName:window.service.project.sceneNames[sceneID]});
}

updateNewSceneName(evt)
Expand All @@ -24,35 +24,70 @@ export default class Window extends React.Component {

saveNewName()
{
window.service.project.sceneNames[this.state.sceneEdit-1] = this.state.newSceneName;
window.service.project.sceneNames[this.state.sceneEdit] = this.state.newSceneName;
this.setState({editing:false, newSceneName:""});
}

addScene()
{
window.service.project.sceneNames.push("New Scene");
this.forceUpdate();
}

removeScene()
{
window.service.project.sceneNames.splice(this.state.activeTab, 1);
this.setState({editing:false, newSceneName:""});
}

renderTabs() {
let first = true;
let counter = 0;
const listItems = this.props.tabs.map((element) => {
counter++;

let name = element;
let edit = "";
if(this.props.scene_selector && window.service.project.sceneNames)
if(this.props.scene_selector)
{
let listItems = [];

for (let i in window.service.project.sceneNames) {
let name = window.service.project.sceneNames[i];
let edit = (<span onClick={this.editSceneName.bind(this, counter)} className="glyphicon glyphicon-edit" style={{cursor:'pointer'}}></span>);

if (counter==this.state.activeTab)
{
listItems.push(<li key={counter} className="active"><a style={{"user-select":"none", background:this.props.color}}><span id={"activeTab_"+counter} className={"glyphicon glyphicon-"+this.props.icons[0]}></span> {name} {edit}</a></li>);
}
else
{
name = window.service.project.sceneNames[counter-1];
edit = (<span onClick={this.editSceneName.bind(this, counter)} className="glyphicon glyphicon-edit" style={{cursor:'pointer'}}></span>);
listItems.push(<li key={counter} className="inactivetab"><a className="inactivetabLink" style={{"user-select":"none"}} href="#" onClick={this.selectTab.bind(this, counter)}><span id={"activeTab_"+counter} className={"glyphicon glyphicon-"+this.props.icons[0]}></span> {name}</a></li>);
}
counter++;
}

listItems.push(<li key={counter} className="inactivetab"><a className="inactivetabLink" style={{"user-select":"none"}} href="#" onClick={this.addScene.bind(this)}><span class="glyphicon glyphicon-plus"></span> Add Scene</a></li>)
return listItems;
}
else
{

const listItems = this.props.tabs.map((element) => {
counter++;

let name = element;

if (counter-1==this.state.activeTab)
{
return <li key={counter} className="active"><a style={{"user-select":"none", background:this.props.color}}><span className={"glyphicon glyphicon-"+this.props.icons[counter-1]}></span> {name} {edit}</a></li> ;
return <li key={counter} className="active"><a style={{"user-select":"none", background:this.props.color}}><span className={"glyphicon glyphicon-"+this.props.icons[counter-1]}></span> {name}</a></li> ;
}
else
{
return <li key={counter} className="inactivetab"><a className="inactivetabLink" style={{"user-select":"none"}} href="#" onClick={this.selectTab.bind(this, counter-1)}><span className={"glyphicon glyphicon-"+this.props.icons[counter-1]}></span> {name}</a></li>;
}
});
});

return listItems;
}

return listItems;

}

getActiveChild() {
Expand All @@ -75,6 +110,7 @@ export default class Window extends React.Component {
window.service.sceneUI.update();
window.service.sceneUI.clearSelection();
window.service.hierarchyUI.forceUpdate();
this.setState({editing:false, newSceneName:""});
}

this.setState({
Expand Down Expand Up @@ -135,14 +171,18 @@ export default class Window extends React.Component {
}

let edit = "";

if(this.state.editing)
if(this.state.editing)
{
let left = document.getElementById("activeTab_"+window.service.currentScene).getBoundingClientRect().left-17;
edit = (
<div className="input-group editSceneName">
<div className="input-group editSceneName" style={{left:left+"px"}}>
<input type="text" className="form-control" value={this.state.newSceneName} placeholder="Scene Name" onChange={this.updateNewSceneName.bind(this)}/>
<div className="input-group-btn">
<button className="btn btn-default" type="submit" onClick={this.saveNewName.bind(this)} style={{height: "31px"}}>
<button className="btn btn-default" type="submit" onClick={this.removeScene.bind(this)} style={{height: "31px"}}>
<i className="fa fa-trash"></i>
</button>
<button className="btn btn-default" type="submit" onClick={this.saveNewName.bind(this)} style={{height: "31px"}}>
<i className="fa fa-check"></i>
</button>
</div>
Expand Down
Loading

0 comments on commit 959c100

Please sign in to comment.