Beginner I need help with my code
in
Programming Questions
•
2 years ago
Excuse my English is very bad.
My image "Guygde.jpg"is much larger than the working window.
If I put my picture in the setup, the drawing plot is perfect, but I do not move in the window.
If I put my picture in draw () I can move in the window but I do not drawing plot.
Another question: how to save the trace to a file?
Thank you .. A beginner discouraged! THANKSSSSSS
My image "Guygde.jpg"is much larger than the working window.
If I put my picture in the setup, the drawing plot is perfect, but I do not move in the window.
If I put my picture in draw () I can move in the window but I do not drawing plot.
Another question: how to save the trace to a file?
Thank you .. A beginner discouraged! THANKSSSSSS
-
ArrayList history = new ArrayList();
float distthresh = 60;
PImage b;
float scaleValue = 1;
float imgX, imgY; -
void setup(){
size(900,600);
b = loadImage("Guygde.jpg"); // 1328 by 1372 pixel
background(0);
image(b, 0, 0);
stroke(0,50);
smooth();
}
void draw(){
translate( imgX, imgY );
// image(b, 0, 0);
if (keyPressed) // si une touche est pressée
{ - if (key == CODED)
{
if (keyCode == DOWN)
{
imgY = imgY-10;
}
if (keyCode == UP)
{
imgY = imgY+10;
}
if (keyCode == LEFT)
{
imgX = imgX-10;
}
if (keyCode == RIGHT)
{
imgX = imgX+10;
}
}
- }
}
void mouseDragged(){
PVector d = new PVector(mouseX,mouseY,0);
history.add(0,d);
for (int p=0; p<history.size(); p++){
PVector v = (PVector) history.get(p);
float joinchance = p/history.size() + d.dist(v)/distthresh;
if (joinchance < random(0.4)) line(d.x,d.y,v.x,v.y);
}
}
void keyPressed(){
if (key == ' ') {
background(0);
history.clear();
}
}
1