xxxxxxxxxx
//How to let the circle run on the left and right side of the triangle?
//How to set color as var?
var headsize=20;
var bodyrotate=0;
var legoffset=-50;
var legincr=0.3;
var thesize =1
var c="white"
var colorList=["Orange","Blue","Green"]
var osc;
function preload() {
sound=loadSound('sound.m4a')
}
function setup() {
createCanvas(windowWidth, windowHeight);
rectMode(CENTER);
osc = new p5.Oscillator(); // make an oscillator
osc.setType('sine'); // options are 'sine', 'sawtooth', 'triangle', 'square'
osc.start(); // start it
}
function draw() {
background(c);
translate(mouseX, mouseY);
osc.freq(mouseX); // frequency to the X axis (in Hz)
osc.amp(3.0 - mouseY/height); // amplitude to the Y axis
if(mouseX-pmouseX+mouseY-pmouseY>0)sound.play()
//HEAD
fill(220,189,245);
push();
translate(0,-40);
ellipse(0,0,headsize,headsize);
pop();
headsize+=0.2;
if(headsize>45) headsize=25;
//BODY
fill(250,218,249)
push();
rotate(bodyrotate);
triangle(0,0,-50,+60,50,+60);
bodyrotate-=0.03
//LEG
fill(184,184,245);
ellipse(-50,60,10,10);
ellipse(50,60,10,10);
pop();
//Eyes
strokeWeight(6);
translate(0, -7);
point(8, -35);
point(-8,-35);
strokeWeight(3);
//Mouse
fill(220,189,245);
ellipse(0,0,9,16);
point(0,-22);
pop();
}
function keyTyped() {
c=random(colorList);
}