mirror of
https://github.com/dyne/FreeJ.git
synced 2026-02-05 20:49:15 +01:00
processing-js 0.4 has been merged in some relevant parts basic and topic scripts added for test color handling fixed, more scripts show up now
35 lines
626 B
Plaintext
35 lines
626 B
Plaintext
PImage teddy;
|
|
|
|
float xpos;
|
|
float ypos;
|
|
float drag = 30.0;
|
|
|
|
void setup()
|
|
{
|
|
size(200,200);
|
|
teddy = loadImage("data/teddy.gif");
|
|
xpos = width/2;
|
|
ypos = height/2;
|
|
frameRate(60);
|
|
}
|
|
|
|
void draw()
|
|
{
|
|
background(102);
|
|
|
|
float difx = mouseX - xpos-teddy.width/2;
|
|
if(abs(difx) > 1.0) {
|
|
xpos = xpos + difx/drag;
|
|
xpos = constrain(xpos, 0, width-teddy.width);
|
|
}
|
|
|
|
float dify = mouseY - ypos-teddy.height/2;
|
|
if(abs(dify) > 1.0) {
|
|
ypos = ypos + dify/drag;
|
|
ypos = constrain(ypos, 0, height-teddy.height);
|
|
}
|
|
|
|
// Display the sprite at the position xpos, ypos
|
|
image( teddy, xpos, ypos );
|
|
}
|