“Markov” by David Smith
https://openprocessing.org/sketch/49398
License CreativeCommons Attribution ShareAlike
https://creativecommons.org/licenses/by-sa/3.0
{{filePath}}
{{width}} x {{height}}
Report Sketch
Oh, that naughty sketch! Please let us know what the issue is below.
Apply Template
Applying this template will reset your sketch and remove all your changes. Are you sure you would like to continue?
Report Sketch
Report Comment
Please confirm that you would like to report the comment below.
We will review your submission and take any actions necessary per our Community Guidelines. In addition to reporting this comment, you can also block the user to prevent any future interactions.
Please report comments only when necessary. Unnecessary or abusive use of this tool may result in your own account being suspended.
Are you sure you want to delete your sketch?
Any files uploaded will be deleted as well.
Delete Comment?
This will also delete all the replies to this comment.
Delete this tab? Any code in it will be deleted as well.
Select a collection to submit your sketch
We Need Your Support
Since 2008, OpenProcessing has provided tools for creative coders to learn, create, and share over a million open source projects in a friendly environment.
Niche websites like ours need your continued support for future development and maintenance, while keeping it an ad-free platform that respects your data and privacy!
Please consider subscribing below to show your support with a "Plus" badge on your profile and get access to many other features!
CC Attribution ShareAlike
Markov
Smith
xxxxxxxxxx
ArrayList plots;
int timesteps = 100;
float probA = 0.1;
float probB = 0.05;
float probC = 0.025;
int state = 0;
int lastDrawnAt = 0;
int totalTransition1 = 0;
int totalTransition2 = 0;
int totalTransition3 = 0;
int countTransition1 = 0;
int countTransition2 = 0;
int countTransition3 = 0;
float meanTransition1 = 0;
float meanTransition2 = 0;
float meanTransition3 = 0;
void setup() {
background(255);
size(640, 400);
plots = new ArrayList();
}
void draw() {
background(255);
int Transition1 = -1;
int Transition2 = -1;
int Transition3 = -1;
if (millis() - lastDrawnAt > map(mouseY, 0, height, 1, 1000)) {
state = 0;
for (int i=0; i<= timesteps * 10; i++) { //Loop through timesteps
switch(state) {
case 0:
if (random(0, 1) <= probA) {
Transition1 = i;
state = 1;
totalTransition1 = totalTransition1 + Transition1;
countTransition1 ++;
meanTransition1 = totalTransition1/countTransition1;
}
break;
case 1:
if (random(0, 1) <= probB) {
Transition2 = i;
state = 2;
totalTransition2 = totalTransition2 + Transition2;
countTransition2 ++;
meanTransition2 = totalTransition2/countTransition2;
}
break;
case 2:
if (random(0, 1) <= probC) {
Transition3 = i;
state = 3;
totalTransition3 = totalTransition3 + Transition3;
countTransition3 ++;
meanTransition3 = totalTransition3/countTransition3;
}
break;
case 3:
state = 3;
break;
}
}
plots.add(new Plot(Transition1, Transition2, Transition3));
lastDrawnAt = millis()+1;
}
for (int i=plots.size()-1; i >= 0; i--) {
Plot thisPlot = (Plot) plots.get(i);
thisPlot.updateMe();
if (thisPlot.a == 0) {
plots.remove(i);
}
}
plotMean(meanTransition1, meanTransition2, meanTransition3);
//println(plots.size()); // Debug successful removal of old plots from arraylist
}
void plotMean(float meanT1, float meanT2, float meanT3) {
int vertX = 0;
float vertY = height;
float finalY = 0;
smooth();
noFill();
strokeWeight(width/timesteps);
stroke(#080101, 255);
beginShape();
vertex(vertX, vertY);
if (meanT1 >= 0) {
vertex((width/timesteps)*(meanT1 - 1), height);
vertex((width/timesteps)*(meanT1), height*0.75);
finalY = height*0.75;
}
if (meanT2 >= 0) {
vertex((width/timesteps)*(meanT2 - 1), height*0.75);
vertex((width/timesteps)*(meanT2), height*0.5);
finalY = height*0.5;
}
if (meanT3 >= 0) {
vertex((width/timesteps)*(meanT3 - 1), height*0.5);
vertex((width/timesteps)*(meanT3), height*0.25);
finalY = height*0.25;
}
vertex(width, finalY);
endShape();
}
class Plot {
int Transition1;
int Transition2;
int Transition3;
float vertX;
float vertY;
float a = 255; //Transparency
float finalY = height;
Plot (int T1, int T2, int T3) {
Transition1 = T1;
Transition2 = T2;
Transition3 = T3;
}
void drawMe() {
vertX = 0;
vertY = height;
smooth();
noFill();
strokeWeight(max(1, width/timesteps));
stroke(#5CD6E3, a);
beginShape();
vertex(vertX, vertY);
if (Transition1 >= 0) {
vertex((width/timesteps)*(Transition1 - 1), height);
vertex((width/timesteps)*(Transition1), height*0.75);
finalY = height*0.75;
}
if (Transition2 >= 0) {
vertex((width/timesteps)*(Transition2 - 1), height*0.75);
vertex((width/timesteps)*(Transition2), height*0.5);
finalY = height*0.5;
}
if (Transition3 >= 0) {
vertex((width/timesteps)*(Transition3 - 1), height*0.5);
vertex((width/timesteps)*(Transition3), height*0.25);
finalY = height*0.25;
}
vertex(width, finalY);
endShape();
}
void updateMe() {
if (a - map(mouseX, 0, width, 0.5, 10) < 0) {
a = 0;
}
else {
a = a-map(mouseX, 0, width, 0.5, 10);
}
drawMe();
}
}
See More Shortcuts