Error on parameter or method declaration near 'float'?

void setup(){
size(200,200);
  background(255);

}

void draw(){
  stroke(0);
  strokeWeight(float)
  float mouseSpeed = abs(mouseX - pmouseX);
 
  line(pmouseX,pmouseY,mouseX,mouseY);

}
1 Like

StrokeWeight() is documented here: https://processing.org/reference/strokeWeight_.html . It should be some number, not the word ‘float’. Also mouseSpeed is never used so it can be removed unless you have some use for it that you are not showing.

1 Like

You’ve forgotten the ending semi-colon ;.
Also, float is a reserved keyword!
Pass a number or a variable argument for strokeWeight().

2 Likes

yes,i was about to make the width of line changing according to the mousespeed,but i don’t know how to deploy it

hi,this is actually a test about write a sentence makes the width of line changing according to the speed of mouse,i can’t figure it out how to write,could you please help me,thanks

You need to declare a global variable that stores the current boldness.
Then change that global variable according to your local variable mouseSpeed.

2 Likes

Point 1

please note that float is the Type of the variable.
The Name of the variable is mouseSpeed.

Therefore you have to use mouseSpeed (its name) when you want to use its value. (probably a typo from your side)
So don’t say strokeWeight(float), better say strokeWeight(mouseSpeed);.

You can also write:

  float mouseSpeed;       // declare var mouseSpeed of type float 
  mouseSpeed = abs(mouseX - pmouseX);      // set var mouseSpeed 
  strokeWeight(mouseSpeed);         // use var mouseSpeed 

Point 2

You need to use strokeWeight() AFTER you declare mouseSpeed.
Because mouseSpeed must be known when you use it in strokeWeight(....);.
It must be:

float mouseSpeed = .........;
strokeWeight(mouseSpeed);

Full Code

Here is my version:

[full code solution removed]

The results look nice!

Improvements

  • You can try to make an if-clause to catch when the mouse cursor is
    in the upperleft corner at the beginning.
  • You can set a minimum and maximum for strokeWeight to have more control.
  • Bigger canvas.
  • A key to clear the canvas.

Chrisir

2 Likes