(Java)Example OpenCV Create Manipulasi Canvas dengan Mouse XY

Kita akan membuat Canvas yang kita inginkan dari ukuran panjang dan lebar dengan memasukkan warna HSB dimana kita menggunakan warna yang berurutan sehingga seperti pelangi..

 	public void setup() 
	{
	  size(640, 360);
	  colorMode(HSB, height, height, height);  
	  noStroke();
	  background(0);
	}

Mendeteksi Mouse Curcors

 public void draw() 
	{
	  int whichBar = mouseX / barWidth;
	  if (whichBar != lastBar) {
	    int barX = whichBar * barWidth;
	    fill(mouseY, height, height);
	    rect(barX, 0, barWidth, height);
	    lastBar = whichBar;
	  }
	}

Full Code

import processing.*;
import processing.core.PApplet;
public class A extends PApplet{
	int barWidth = 20;
	int lastBar = -1;

	public void setup() 
	{
	  size(640, 360);
	  colorMode(HSB, height, height, height);  
	  noStroke();
	  background(0);
	}

	public void draw() 
	{
	  int whichBar = mouseX / barWidth;
	  if (whichBar != lastBar) {
	    int barX = whichBar * barWidth;
	    fill(mouseY, height, height);
	    rect(barX, 0, barWidth, height);
	    lastBar = whichBar;
	  }
	}
}
 

Run
5-12-2014 5-22-31 AM

Advertisements

Published by

jarcode

hello I am jarcode

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s