We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am working on creating a mitosis cell that can split using a function rather than having to click on it. I want to try and create a ball that is in the centre of the screen and will split out in a radial fashion.
This is my Cell function
function Cell(pos, r, c){
if (pos) {
this.pos = pos.copy();
} else {
this.pos = createVector(700, 360, 700, 160);
}
this.r = r || 60;
this.c = c || color(random(100, 200), 0, random(100, 200), 100);
this.clicked = function(x, y) {
var d = dist(this.pos.x, this.pos.y, x, y);
if (d < this.r) {
return true;
} else {
return false;
}
}
this.mitosis = function() {
this.pos.x += random(-10, 10);
var cell = new Cell(this.pos, this.r*0.8, this.c);
return cell;
}
this.move = function () {
var vel = p5.Vector.random2D();
this.pos.add(vel);
}
this.show = function () {
noStroke();
fill(this.c);
ellipse(this.pos.x, this.pos.y, this.r, this.r)
}
}
Any help would be really appreciated. Thank you
Answers
maybe as a start use probability to cause the cells to split? You can pick a random number and determine if it is less that
0.01
for a 1% chance for example:Perhaps if you could find some animation that shows what you're trying to achieve, it would be easier to advise you.
I couldn't find any example of what I wanted so I quickly storyboarded my idea. Thank you any help is very useful! So I want the ball to start as 1 and then explode sort of randomly and then cluster back into colour coded sections as shown below.
Thank you
I don't think actual mitosis acts as such, but this might be doable. I could do this in Processing (Java), but I haven't much knowledge of p5.js, sorry.
If you could help me in processing that would be a lot better as I have been focusing more on processing than p5.js. I only used mitosis as an example as I followed Shiffmans tutorials on youtube. If you have any ideas of how to do it in processing it would be really helpful.
Thank you
First, a Cell class, as you already have. Now, this should have a "color" property.
Second, create an AraryList of arrays of Cells.
Here, things get complex. It depends on how nice you want your entire sketch to be. If a single "mitosis" is all you want, the solution is simple. If so -
Do this much and come back here. I'm trying to think about exactly what sort of explosion to cause, as you have given no details to the specific amounts of the different colored cells.
Im only a beginner and its getting confusing. Here is what I have got in processing so far. I don't understand how to make it explode on its own rather than having to click it all the time. Thank you helping me.
The method to post code on this forum is to copy and paste it. But don't forget to format the code by pressing ctrl + o and leaving a line above and below it.
Thank you
I need to think about this.
The problem lies in the sizes of the new cells. I'll think and tell you once I find a solution to create cells with a size distribution similar to your picture.
By this time tomorrow, probably.
Thank you so much! this is going to be so helpful for my project. I really appreciate it!
I figured out an algorithm for producing random numbers in a particular distribution.
Where should it go? Im trying to post it here but nothing is happening. Its started getting really confusing, I'm still very new to processing.
This should get you started:
Tab Cell:
Thank you, thats so helpful!
If you make any progress, be sure to post it here.
I will do thank you for all the help so far.
Even better random number generator -
Replace
randomReducing()
(line 34) withrandomBeta()
, and add the new code to a new tab.Thank you, starting to look more like what i needed
In this random generator, most of the new circles will be 0.2-0.3 times the original circle's radius, but some will be medium or very small in size, with very few being very large.
But a question is - is it okay for the cells to overlap with each other? If so, the rest is possibly easy, otherwise, it is certainly difficult.
Have you made any progress?
yes I was working on the idea of them slightly having an opacity sort of 80% maybe and yes they can overlap it gives a cool effect. I haven't made any major progress, just with the sizes. Im trying to find tutorials that I can follow to learn.
Okay, then each time the mitosis function is called, you need to check out every single new Cell and add it to some corresponding
ArrayList<Cell>
. If you don't know about arraylists I recommend reading about them - ArrayList referenceThank you, I will have a look into it