d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Mouseclicked Function
Add Reply New Topic New Poll
Member
Posts: 16,404
Joined: Mar 28 2009
Gold: 7.69
Sep 27 2016 12:36pm
Hello. I've been trying to make it so when you click your mouse on the canvas a new fish is drawn. Im having trouble figuring out 1. Where to put the mouseClicked(); function and 2. What to put inside the body of the function.

Code
background(89, 216, 255);

var centerX = 200;
var centerY = 100;
var bodyLength = 118;
var bodyHeight = 74;
var bodyColor = color(162, 0, 255);
var tailWidth = bodyLength/4;
var tailHeight = bodyHeight/2;
var bot = 400;


var drawFish = function(centerX, centerY, bodyLength, bodyHeight, bodyColor, tailWidth, tailHeight) {

noStroke();
fill(bodyColor);
// body
ellipse(centerX, centerY, bodyLength, bodyHeight);
// tail

triangle(centerX-bodyLength/2, centerY,
centerX-bodyLength/2-tailWidth, centerY-tailHeight,
centerX-bodyLength/2-tailWidth, centerY+tailHeight);
// eye
fill(33, 33, 33);
ellipse(centerX+bodyLength/4, centerY, bodyHeight/5, bodyHeight/5);

};


drawFish(191,200, 50, 23, color(242, 190, 67), 21, 11);
drawFish(100,329, 118, 70, color(31, 207, 54), 15, 50);
drawFish(307,98, 183, 70, color(179, 56, 207), 30, 21);
drawFish(100,109, 49, 85, color(240, 67, 139), 29, 91);

//pebbles
for (var i = 0; i < width; i++){
fill(i+random(0, 255),random(0, 255),random(0, 255));
ellipse(i+random(-196, 10), random(bot, height), random(71,40), random(-56, -31));
}


This post was edited by Shakti on Sep 27 2016 12:52pm
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll