some (hopefully basic) questions

hi! i'm new to p5 and coding in general and i'm having some trouble completing a project because i still lack the knowledge to fill in the gaps. what i want to do seems kind of simple but i don't really know if it is, i've tried looking for tutorials/examples but they either don't work in the online p5 processor (i have sublime, too, but it's not running a lot of the files i'm trying to work on for some reason?) or i don't know exactly how to look it up.

ok, so.

1) i have some text that follows the mouse around on the canvas, but i'd like it to leave a trail (preferably a fixed one but doesn't matter if it fades tbh, just whatever is simplest to do). i figured the code would be something along the lines of "if mouseX and mouseY increase, the quantity of the text increases". i tried it by doing the following:

if (mouseX++,mouseY++){i++}
for(i=1;i<10;i++)
  textFont("courier new")
text("text",mouseX,mouseY)

but the mouseX and mouseY variables start moving on their own rather than increase the number of lines when i move the cursor. (i kinda realize some mistakes here but it's the best i could come up with. i only started w js like a week ago so pls be patient w me)

2) how can i make an object rotate on its axis as an animtion rather than a fixed transform of its position?

and finally (and probably the most complicated. or maybe not and im just really inexperienced lol)

3) the project i'm working on is a sort of interactive story. i've made a bunch of separate files with different code each. is there a way to link them, whether it is to put them all on the same file or through the use of html? i have a little experience with hypertext narratives so thats sorta what i'm going for, but it could be just pushing the spacebar or something to get to the next part if turning an actual object into a link is too difficult.

i'm super confused about everything and i'd really really really appreciate some help even if it's with just one of these things. thanks a lot in advance!!

Answers

  • To create a trail, you generally store the previous positions in an array and then draw something at all of the previous positions. Or you could not clear out old frames if you want the trail to stay on the screen.

    You can animate a rotation by rotating it a little bit each frame.

    How you transition between sketches depends on how they're organized and how you want it to work. You could combine them into one sketch that uses if statements to decide what to draw each frame, or you could navigate to a different .html page that loads a completely different sketch.

    The best advice I can give you is to break your problems down into smaller pieces and take those pieces on one at a time. Create small examples that test out just one of your questions, and post a MCVE if you get stuck. Good luck.

Sign In or Register to comment.