Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Snowflakes: http://solemone.de/demos/snow-effect-processing/
- // Hue slider: http://cs1335-documentation.readthedocs.io/en/latest/hsbSlider.html
- void setup() {
- size(1000, 600, P3D);
- smooth();
- surface.setResizable(true);
- colorMode(HSB);
- stroke(0,0,0);
- // Snowflakes setup
- for(int i = 0; i < quantity; i++) {
- flakeSize1[i] = round(random(minFlakeSize, maxFlakeSize));
- xPosition[i] = random(0, width);
- yPosition[i] = random(0, height);
- direction[i] = round(random(0, 1));
- }
- }
- int z = 0;
- // Snowflake variables
- int quantity = 300;
- float [] xPosition = new float[quantity];
- float [] yPosition = new float[quantity];
- int [] flakeSize1 = new int[quantity];
- int [] direction = new int[quantity];
- int minFlakeSize = 1;
- int maxFlakeSize = 5;
- // Snowflake variables
- float flakeSize = 30;
- float difference = 50;
- float layerTwo = 50;
- float layerThree = layerTwo + difference;
- float layerFour = layerTwo + (difference * 2);
- // Slider variables
- float marginLeft = 20;
- float handle1 = marginLeft;
- float handle2 = marginLeft;
- float handle3 = marginLeft;
- float barWidth = 255;
- float barHeight = 6;
- float handleSize = 20;
- // Hue bar variables
- float _barWidth = 255.0; //slider-bar width;
- float _hueVal = _barWidth/2; //initial hueValue global value
- void draw() {
- z++;
- background(0);
- for(int i = 0; i < xPosition.length; i++) {
- fill(random(0, 255), random(0, 255), random(0, 255));
- ellipse(xPosition[i], yPosition[i], flakeSize1[i], flakeSize1[i]);
- if(direction[i] == 0) {
- xPosition[i] += map(flakeSize1[i], minFlakeSize, maxFlakeSize, .1, .5);
- } else {
- xPosition[i] -= map(flakeSize1[i], minFlakeSize, maxFlakeSize, .1, .5);
- }
- yPosition[i] += flakeSize1[i] + direction[i];
- if(xPosition[i] > width + flakeSize1[i] || xPosition[i] < -flakeSize1[i] || yPosition[i] > height + flakeSize1[i]) {
- xPosition[i] = random(0, width);
- yPosition[i] = -flakeSize1[i];
- }
- }
- fill(255);
- stroke(4);
- rectMode(CORNER);
- // Scrollbars
- rect(marginLeft, 20, barWidth, barHeight);
- translate(0, 0, 2);
- ellipse(handle1, 25, handleSize, handleSize);
- rect(marginLeft, 60, barWidth, barHeight);
- translate(0, 0, 2);
- ellipse(handle2, 65, handleSize, handleSize);
- // Hue bar
- _hueVal= drawSlider(marginLeft, 100.0,_barWidth,barHeight,_hueVal);
- // Snowflake
- translate(width / 2, height / 2, -1);
- rotate(radians(width - mouseX) * 0.5);
- // Middle
- rectMode(CENTER);
- stroke(0, 100);
- fill(_hueVal,255,255); //use the new _hueValue to set fill for drawing canvas object
- ellipse(0, 0, flakeSize, flakeSize);
- // Spokes
- for (int i = 0; i < 8; i++) {
- rotate(radians(45));
- ellipse(layerTwo, layerTwo, flakeSize, flakeSize);
- rect(layerThree, layerThree, flakeSize, flakeSize);
- ellipse(layerFour, layerFour, flakeSize, flakeSize);
- }
- }
- void mouseDragged() {
- if (mouseY > 10 && mouseY < 40 && mouseX > marginLeft && mouseX < (marginLeft + barWidth)) {
- handle1 = mouseX;
- flakeSize = mouseX;
- }
- if (mouseY > 50 && mouseY < 70 && mouseX > marginLeft && mouseX < (marginLeft + barWidth)) {
- handle2 = mouseX;
- layerTwo = mouseX / 2;
- layerThree = layerTwo + difference;
- layerFour = layerTwo + (difference * 2);
- }
- if (mouseY > 50 && mouseY < 130 && mouseX > marginLeft && mouseX < (marginLeft + barWidth)) {
- handle3 = mouseX - 20;
- handle3 = mouseX;
- }
- }
- float drawSlider(float xPos, float yPos, float sWidth, float sHeight,float hueVal){
- fill(255);
- noStroke();
- float sliderPos = map(hueVal, 0.0,255.0, 0.0, sWidth); //find the current sliderPosition from hueVal
- for(int i = 0; i < sWidth; i++){ //draw 1 line for each hueValue from 0-255
- float hueValue = map(i,0.0,sWidth,0.0,255.0); //get hueVal for each i position //local variable
- stroke(hueValue,255,255);
- line(xPos+i,yPos,xPos+i,yPos+sHeight);
- }
- if(mousePressed && mouseX>xPos && mouseX<(xPos+sWidth) && mouseY>yPos-10 && mouseY <yPos+sHeight+10){
- sliderPos=mouseX-xPos;
- hueVal=map(sliderPos,0.0,sWidth,0.0,255.0); // get new hueVal based on moved slider
- }
- stroke(100);
- fill(hueVal,255,255); //either new or old hueVal
- translate(0, 0, 2);
- ellipse(sliderPos + xPos-3, yPos + 3, handleSize, handleSize); //this is our slider indicator that moves
- return hueVal;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement