d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > For Loop Help..
Add Reply New Topic New Poll
Member
Posts: 16,399
Joined: Mar 28 2009
Gold: 22.69
Oct 25 2016 08:18pm
I am trying to get the program to draw a random number of these 2 concentric ellipses all over the canvas, while keeping its concentric detail and it must stay within the nested for loop. I've tried so many things but each time the concentric detail turns into a scattered mess. Any advice?

I don't believe the "total * 10" "total * 20" etc do not need to be changed... the only part of the ellipses that need to be randomized are the 200 values right? That's my idea on that anyways

Code
noStroke();


var flower = function(x,y) {
for(var total = 5; total > 0; total--){

fill(random(0,255),random(0,255), random(0,255));


for(var i = 0; i < random(1,20); i++) {


ellipse(200, 200, total * 10, total * 20);

ellipse(200, 200, total * 20, total * 10);
}
}
};
flower();





I did a similar assignment with a while loop and I've been kind of trying to base this for loop assignment off this since they're pretty similar.

Code
var i = 0;

var circle = function(x,y) {
while (i< random (1, 20)){
stroke(random(0,255),random(0,255), random(0,255));
strokeWeight(random(0,50));
point(random(x,y), random(x,y));
i++;
}


};
draw = function() {
circle(0,400);
};


This post was edited by Shakti on Oct 25 2016 08:25pm
Member
Posts: 1,039
Joined: Jul 8 2008
Gold: 1,939.50
Oct 26 2016 04:04pm
You should state what language/library you're using.

Assuming you're using processJs here is the code:
Code

noStroke();

var r = random(1,20);
for(var i = 0; i < r; i++) {
var randomx = random(40, width-40);
var randomy = random(40, height-40);
fill(119, 230, 64);
ellipse(randomx, randomy, 80, 80);
}

You need to look at the doc here: http://processingjs.org/reference/ellipse_/
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll