Created
February 14, 2023 21:10
-
-
Save EllaY44/565fc5a4a86524e586e109251ccbfe49 to your computer and use it in GitHub Desktop.
Week 3 homework question
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Hello @rors ,
Thank you for your response! I've just fixed it and it's working how I wanted it to now.
Great 👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 whendraw()
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 indraw()
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 insetup()
which is fine but non-standard. This raises an error issue because in my code where I cut/pasted code fromdraw()
intosetup()
, 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 insetup()
and everywhere.Let me know if that works. Nice work 👍