stroke weight controlled by mouseWheel

Hi guys! I'm very new to processing, and what i'm trying to do with this code, is to simply change stroke weight using mouse wheel. I tried to look for the answers, but couldn't find anything that would help me, and I'm pretty sure, at the end of the day it is going to be a very simple command.

Could any of you help me out?

void setup() {
    size(1000, 500);
    background(168, 100, 168);
}

void draw() {
    noCursor();
    println (mouseX +"," + mouseY);
    noStroke();
    fill(168, 100, 168);
    rect(0, 0, 50, displayHeight);
    rect(0, 0, displayWidth, 20);
    rect(950, 0, 200, displayHeight);
    rect(0, 480, displayWidth, 20);
    triangle(70, 0, 70, 200, 110, 0);
    triangle(130, 20, 90, 220, 130, 480);
    triangle(70, 260, 70, 480, 110, 480);
    triangle(130, 480, 170, 20, 130, 20);
    triangle(190, 20, 230, 480, 230, 20);
    quad(150, 480, 155, 460, 205, 460, 210, 480);
    triangle(160, 440, 200, 440, 180, 220);
    triangle(250, 20, 270, 220, 290, 20);
    rect(310, 20, 20, displayHeight);
    triangle(250, 480, 250, 440, 270, 480);
    triangle(270, 480, 290, 440, 290, 480);
    rect(350, 20, 20, displayHeight);
    rect(390, 20, 100, 440);
    rect(490, 20, 460, displayHeight);

    strokeWeight(20);
    stroke(249, 173, 129);
    line(pmouseX, pmouseY, mouseX, mouseY);
}

Answers

  • (don't use the html option, just paste the code, select it, hit ctrl-o)

  • edited January 2016

    ok thanks man, but how to resolve my question?

  • _vk_vk
    Answer ✓

    Something like this?

    float strokeW = 20;
    
    
    void setup() {
      size(1000, 500);
      background(168, 100, 168);
    }
    
    void draw() {
      noCursor();
    
      strokeWeight(strokeW);
      stroke(249, 173, 129);
      line(pmouseX, pmouseY, mouseX, mouseY);
    }
    
    void mouseWheel(MouseEvent e) {
      float amt = e.getCount();
      float newWid = strokeW+=amt;
    
      // keep it in valid range (>0);
      strokeW = max(newWid, 0);
    }
    
  • Something exactly like this @_vk thanks! i'll try to put it all together now :)

  • _vk_vk
    edited January 2016

    :)

Sign In or Register to comment.