Skip to content

Instantly share code, notes, and snippets.

@EllaY44
Created February 14, 2023 21:10
Show Gist options
  • Save EllaY44/565fc5a4a86524e586e109251ccbfe49 to your computer and use it in GitHub Desktop.
Save EllaY44/565fc5a4a86524e586e109251ccbfe49 to your computer and use it in GitHub Desktop.
Week 3 homework question
def setup():
size(800, 700);
stroke(100, 100, 255, 80)
background(255)
frameRate(30)
def draw():
fill(245, 242, 195)
rect(0, 0, 800, 700)
fill(40, 49, 48)
rect(0, 0, 800, 70)
fill(40, 49, 48)
rect(0,130,800,2)
rect(0,180,800,2)
rect(0,230,800,2)
rect(0,280,800,2)
rect(0,330,800,2)
rect(0,380,800,2)
rect(0,430,800,2)
rect(0,480,800,2)
rect(0,530,800,2)
rect(0,580,800,2)
rect(0,630,800,2)
rect(0,680,800,2)
rect(0,730,800,2)
stroke(150, 150, 250, 90)
distance = dist(pmouseX, pmouseY, mouseX, mouseY)
mappedDistance = map(distance, 0,200, 40,1)
d = dist(pmouseX, pmouseY, mouseX, mouseY)
line(pmouseX, pmouseY, mouseX, mouseY)
@EllaY44
Copy link
Author

EllaY44 commented Feb 14, 2023

@rors Hello, I was wondering how to fix the following problem:

When I run the code and use the mouse to "draw", the 'pen' appears, meaning that the mouse has a trail, but it does not stay on the screen. How can I fix it so that the mouse works more like a pen like it did in class, so that the movements of the mouse stay on the window?

@rors
Copy link

rors commented Feb 16, 2023

Hi @EllaY44. So the reason that my code left the mouse movements on the screen as if it was a pen is because I was not wiping (redrawing) the screen every frame, for example with background(), or in your case here, with lined 8-27 which draw your lined paper effect. Effectively what's happening here is that you are drawing a line where the mouse is on lines 30-34, but then when draw() repeats, you are immediately "overwriting" that mouse line with the lined paper effect.

One solution here would be to move all your code that draws the lined paper effect into setup(), so that it only happens once. Then in draw() you'll only draw the line where the mouse is, so you never draw anything to overwrite it.

Have a look at what I did here. (This view shows you just the changes.)

One other issue: you are using 4 spaces of indentation in draw() (which is good) but for some reason you're using 5 spaces of indentation in setup() which is fine but non-standard. This raises an error issue because in my code where I cut/pasted code from draw() into setup(), now the indentation is different. And you cannot have different sized indentation within the same block. So if you want to run the code I created, you'll have to fix that or get an error. I would recommend using 4 spaces for all the indentation in setup() and everywhere.

Let me know if that works. Nice work 👍

@EllaY44
Copy link
Author

EllaY44 commented Feb 16, 2023

Hello @rors ,
Thank you for your response! I've just fixed it and it's working how I wanted it to now.

@rors
Copy link

rors commented Feb 21, 2023

Great 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment