Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let grid = [];
  2. let gridSize = 10;
  3. let spacing = 50;
  4. let isDrawing = false;
  5. let lines = [];
  6.  
  7. function setup(){
  8.   createCanvas(600, 600);
  9.   ellipseMode(CENTER);
  10.   background(0);
  11.  
  12.   for(let i = 0; i < gridSize; i++){
  13.     for(let j = 0; j < gridSize*2; j++){
  14.       if(j % 2 == 0){
  15.         grid.push(new Dot(i * spacing, j * spacing/2));
  16.       } else {
  17.         grid.push(new Dot(i * spacing + spacing/2, j * spacing/2));
  18.       }
  19.     }
  20.   }
  21. } // End of setup
  22.  
  23. function draw(){
  24.   background(0);
  25.  
  26.   for(let i = 0; i < grid.length; i++){
  27.     grid[i].display();
  28.   }
  29. } // End of draw
  30.  
  31. function mousePressed(){
  32.   for(let i = 0; i < grid.length; i++){
  33.     if(grid[i].mouseOver){
  34.       isDrawing = true;
  35.       lines.push({x: grid[i].x, y: grid[i].y});
  36.     }
  37.   }
  38.  
  39.   console.log(lines);
  40. }
  41.  
  42. class Dot{
  43.   constructor(x, y){
  44.     this.x = x;
  45.     this.y = y;
  46.   }
  47.  
  48.   mouseOver(){
  49.     let tolerance = 8;
  50.    
  51.     let distX = this.x - mouseX;
  52.     let distY = this.y - mouseY;
  53.     let dist = Math.sqrt((distX * distX) + (distY * distY));
  54.    
  55.     return dist <= tolerance;
  56.   }
  57.  
  58.   display(){
  59.     fill(150);
  60.     noStroke();
  61.     ellipse(this.x, this.y, 4, 4);
  62.    
  63.     if(this.mouseOver()){
  64.       noFill();
  65.       stroke(255);
  66.       ellipse(this.x, this.y, 16, 16);
  67.     }
  68.   }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement