So i have a simple block of code here where i am placing a bunch of triangles on the screen and rotating them randomly in multiples of 90 degrees at every draw. It starts off all right but tends to get a gradual rotation on its own which is not in multiples of 90.
PShape triangle;
void setup(){
size(500,500);
triangle = createShape(TRIANGLE, 0, 0, 50, 50, 50, 0);
}
void draw(){
background(0);
for (int i = 0; i < 500; i+=50){
for (int j = 0; j < 500; j+=50){
fill(#567354);
triangle.rotate(radians((int)random(3)*90));
shape(triangle, i, j);
}
}
}
starts off all right
but then after 5 odd minutes of running it goes crazy wrong
i not watch that 5 minutes, get headache after 5 sec.
but actually what you are doing might be that you rotate
the triangle shape ( not the view or drawing )
15.000.000 times per second, // ( sorry, not see the j+=50 )
so 5min would mean 4.500.000.000 rotations.
can’t you make ONE,
copy rotate to 4 different triangles
and randomly choose one of these for draw?
Actually not so many. The step is 50 in the for loops, so it’s just 100 rotations per frame, 100*60 rotations per second, 100*60*60*5 = 1_800_000 rotations in 5 minutes. Not much.
Hey you guys, Thanks a lot for those insightful replies. As for the design… just add frameRate(1); to the code there and it becomes a nice infinite ‘seconds’ clock…
But here is the code I am goingn for… I am using Joshua Davis’s hype to import an svg and place it in grid etc…
import hype.*;
import hype.extended.colorist.HColorPool;
import hype.extended.layout.HGridLayout;
import hype.extended.behavior.HRotate;
HDrawablePool pool;
HColorPool colors;
HCanvas canvas;
void setup(){
size(640,384);
H.init(this).background(#000000).autoClear(false).use3D(true);
smooth();
frameRate(1);
canvas = new HCanvas().autoClear(true).fade(5);
H.add(canvas);
colors = new HColorPool(#ffffff, #000000);
pool = new HDrawablePool(400);
pool.autoParent(canvas)
.add(new HShape("svg3.svg"))
.layout(
new HGridLayout()
.startX(40 )
.startY(70)
.spacing(80, 80)
.cols(25)
)
.onCreate(
new HCallback() {
public void run(Object obj) {
int i = pool.currentIndex();
HShape d = (HShape) obj;
d.enableStyle(false)
.stroke(#000000)
.strokeWeight(0.5)
.anchorAt(H.TOP | H.LEFT)
.size( 80)
.rotate( (int)random(4) * 90 )
;
d.randomColors(colors.fillOnly());
}
}
)
.requestAll()
;
}
void draw() {
H.drawStage();
for (HDrawable d : pool) {
d.rotate( (int)random(4) * 90 );
}
}
translate and rotate solves the problem yes! But I am using H.drawStage… so… it’s .drawing them all at once
I still want to use rotate on the shape… is there a way around to refresh the overflowing float value or something… also which float value are you exactly reffering to…? Sorry I am bit of an amateur coder…