void addMap(Dictionary <object, object> map) { foreach (object key in map.Keys) { if (map[key] is bool) { CreatedNeuron neuron = mapNeurons[(Neuron)key]; neurons.Add(neuron); neuron.create(); if (count < neuron.Frame) { neuron.Frame = count; } } else if (key is Neuron) { CreatedNeuron neuron = (CreatedNeuron)(map[key]); mapNeurons.Add((Neuron)key, neuron); neurons.Add(neuron); neuron.create(); neuron.Frame = count; } else { CreatedSynapse synapse = (CreatedSynapse)(map[key]); mapSynapses.Add((Synapse)key, synapse); synapses.Add(synapse); } } }
public Dictionary <object, object> loadFrame(CreationFrame frame, int index) { Dictionary <object, object> result = new Dictionary <object, object>(); Random random = new Random(); bool added = false; Neuron neuron = frame.Neuron.Neuron; if (neurons.Find(k => k.Neuron == neuron) == null) { PointF position = randomPoint(random); AnimatedNeuron an = new AnimatedNeuron(neuron, position); CreatedNeuron cn = new CreatedNeuron(an); neurons.Add(an); result.Add(neuron, cn); added = true; } else { result.Add(neuron, true); } foreach (CreationData data in frame.Data) { if (data.Synapse.Changes.First <CreationData>() == data) { AnimatedNeuron pre = neurons.Find(k => data.Synapse.Pre == k.Neuron); AnimatedNeuron post = neurons.Find(k => data.Synapse.Post == k.Neuron); AnimatedSynapse synapse = synapses.Find(k => pre == k.Pre && post == k.Post); if (synapse == null) { AnimatedSynapse syn = new AnimatedSynapse(pre, post, data.Synapse); CreatedSynapse cs = new CreatedSynapse(syn); synapses.Add(syn); result.Add(syn.Synapse, cs); if (syn.isDuplex()) { result.Add(syn.Duplex, cs); } } else { synapse.setDuplex(data.Synapse); } } } if (added) { balance(); } return(result); }
public void create(List <CreatedNeuron> lcn, List <CreatedSynapse> lcs) { CreatedNeuron cn = neurons[neuron.Neuron]; if (!cn.Created) { cn.Frame = frame; cn.create(); lcn.Add(cn); } foreach (Synapse synapse in created) { lcs.Add(synapses[synapse]); } }
public void load(List <AnimatedNeuron> neurons, List <AnimatedSynapse> synapses) { animated = neurons; foreach (AnimatedNeuron an in neurons) { mapNeurons.Add(an.Neuron, new CreatedNeuron(an)); } foreach (AnimatedSynapse s in synapses) { if (s.Pre is AnimatedReceptor) { continue; } CreatedSynapse cs = new CreatedSynapse(s); mapSynapses.Add(s.Synapse, cs); if (s.isDuplex()) { mapSynapses.Add(s.Duplex, cs); } } framesChanged(length, null); frameChanged(count, null); int index = 1; foreach (CreationSequence cs in sequences) { foreach (CreationFrame cf in cs.Frames) { cf.finish += new EventHandler(finish); CreatedNeuron neuron = mapNeurons[cf.Neuron.Neuron]; if (neuron.Frame == 0) { neuron.Frame = index; } index++; } } }
public void undo(List <CreatedNeuron> lcn, List <CreatedSynapse> lcs) { CreatedNeuron cn = neurons[neuron.Neuron]; if (neurons[neuron.Neuron].Frame == frame) { cn.delete(); lcn.Remove(cn); } foreach (Synapse s in created) { lcs.Remove(synapses[s]); } foreach (CreationData cd in data) { synapses[cd.Synapse].Synapse.undo(cd); } }
public void tick() { float factor = (float)count / interval; switch (phase) { case 1: if (neurons[neuron.Neuron].Created) { phase = 2; } else { neurons[neuron.Neuron].draw(factor); } break; case 2: if (created.Count == 0) { phase = 3; } foreach (Synapse s in created) { synapses[s].draw(factor); } break; case 3: foreach (CreationData cd in data) { CreatedSynapse cs = synapses[cd.Synapse]; cs.tick(cd); } break; } if (++count == interval) { switch (phase++) { case 1: if (synapses.Count == 0) { phase++; } CreatedNeuron cn = neurons[neuron.Neuron]; cn.create(); cn.Frame = frame; finish(cn, null); break; case 2: finish(created, null); break; case 3: create(); finish(this, null); break; } count = 0; } }