Code Block |
---|
intconst gridWidth = 20; intconst gridHeight = 20; const float shapeWidth = 30; const float shapeHeight = 30; var float reactorScaler = 0.06; intvar xOffset; intvar yOffset; PVectorvar reactorPosition; void function setup() { reactorPosition = new PVectorcreateVector(0, 0); sizecreateCanvas(700, 700); // offset used to center the graphics on the screen xOffset = floor(width/2-(shapeWidth*gridWidth/2)); yOffset = floor(height/2-(gridHeight*shapeHeight/2)); background(255); smooth(); }; voidfunction draw() { background(255); fill(0); noStroke(); pushMatrixpush(); translate(xOffset, yOffset);//translate matrix to center for (intvar i = 0; i<gridWidth; i++ ) { for (intvar j = 0; j<gridHeight; j++ ) { PVector myPos = new PVectorcreateVector(i*shapeWidth, j*shapeHeight); floatvar reactorDistance = dist(reactorPosition.x, reactorPosition.y, myPos.x, myPos.y); floatvar scaler = reactorDistance*reactorScaler; ellipse(myPos.x, myPos.y, 1*scaler, 1*scaler); }; }; popMatrixpop(); }; intfunction mouse_XmouseMoved() { let returnvecX = (mouseX - xOffset); //correct positions afterlet matrix translations } int mouse_Y() { return (vecY = mouseY - xOffset); //correct positions after matrix translations } void mouseMoved() {yOffset; reactorPosition.x = mouse_X(); reactorPosition.y = mouse_Y(set(vecX, vecY); }; |
...