intersection question
in
Programming Questions
•
1 year ago
I'm trying to change the color of a box on screen when a circle at mousex and mousey passes over it. my code runs but doesn't work. can anyone see where I'm going wrong?
- boolean isTouching = false;
- int blobRad = 80;
- color col;
- sonicBlock[] sonicBlocks = new sonicBlock[0];
- Blob blob = new Blob();
- int count = 100;
- int numSamples = 0;
- int grab = -1;
- float time =0.0;
- void setup() {
- size(900, 600);
- smooth();
- float x = 30;
- while (x < width) {
- float y = 30;
- while (y < height) {
- makeNewsonicBlock(x, y, 25);
- y = y + 60;
- }
- x = x + 60;
- }
- }
- void draw() {
- background(74, 147, 177);
- if (mousePressed == true) {
- selectsonicBlock();
- if (grab>=0) {
- sonicBlocks[grab].mouseMove();
- //sonicBlocks[grab].ring();
- }
- }
- for (int i = 0; i < count; i = i+1) {
- sonicBlocks[i].display();
- sonicBlocks[i].drag(.90);
- //sonicBlocks[i].changeColor();
- }
- time+=.02;
- blob.display();
- if (isTouching = true){
- col = color(31,52,75);
- }
- else{
- col = color(44,149,171);
- }
- }
- void mousePressed() {
- }
- void mouseReleased() {
- grab = -1;
- }
- void selectsonicBlock() {
- for (int i = 0; i < sonicBlocks.length; i ++) {
- if (dist(sonicBlocks[i].posX, sonicBlocks[i].posY, mouseX, mouseY) < sonicBlocks[i].rad/2 ) {
- grab = sonicBlocks[i].ID;
- }
- }
- }
- void touching(){
- for (int i = 0; i < sonicBlocks.length; i ++){
- if (dist(sonicBlocks[i].posX, sonicBlocks[i].posY, mouseX, mouseY) < blobRad + sonicBlocks[i].rad){
- isTouching = true;
- }
- }
- }
- void makeNewsonicBlock(float x, float y, float rad) {
- sonicBlock newsonicBlock = new sonicBlock(sonicBlocks.length, x, y, rad);
- sonicBlocks = (sonicBlock[]) append(sonicBlocks, newsonicBlock);
- }
- void keyPressed() {
- if (key == CODED) {
- if (keyCode == UP) {
- blobRad += 10;
- }
- else if (keyCode == DOWN) {
- blobRad -=10;
- }
- if (blobRad >= 400) {
- blobRad = 20;
- }
- }
- }
- class sonicBlock {
- float posX;
- float posY;
- float speedX;
- float speedY;
- float rad;
- int ID;
- float dis;
- sonicBlock(int objID, float tempposX, float tempposY, float tempRad) {
- ID = objID;
- posX = tempposX;
- posY = tempposY;
- rad = tempRad;
- //dingdong = minim.loadSnippet(fileName);
- }
- void display() {
- noStroke();
- fill(col);
- rectMode(CENTER);
- rect(posX, posY, rad, rad);
- }
- /*void changeColor(){
- if (isTouching = true){
- col = color(31,52,75);
- }
- else{
- col = color(44,149,171);
- }
- }*/
- }
- class Blob {
- //ellipseMode(CENTER);
- Blob() {
- }
- void display() {
- fill(31, 52, 75, 60);
- ellipse(mouseX, mouseY, blobRad, blobRad);
- }
- }
1