Created
March 13, 2020 03:16
-
-
Save volfegan/9357c72ba9f52f140ff7c47c765cde20 to your computer and use it in GitHub Desktop.
Some static screen on radar display
This file contains hidden or 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
Slider slider; | |
long time; | |
boolean glitch = false; | |
float t=0; | |
float x, y, angle, r, n; | |
float sliderSize, startValue, endValue; | |
void setup() { | |
size(730, 730, FX2D); | |
sliderSize = 400; | |
PVector sliderPos = new PVector((width-sliderSize)/2, height-50); //to put in the middle-bottom | |
startValue = 0; | |
endValue = 360; | |
slider = new Slider(sliderPos, sliderSize, startValue, endValue); | |
time = millis(); | |
} | |
//make a radar dish sweep | |
void draw() { | |
background(0); | |
float normalizedSlider = norm(slider.getSliderValue(), startValue, endValue); | |
//enable total static or partial static with blank spaces glitch | |
if (!glitch && random(1) > .5 && time < millis()-400) { | |
glitch = true; | |
} | |
if (glitch && time < millis()-500) { | |
time = millis(); | |
if (random(1) > .75) | |
glitch = false; | |
} | |
//making static radar screen | |
loadPixels(); | |
int yoff = 0; | |
for (int y=0; y < height; y+=1+round(random(1))) { | |
int xoff = 0; | |
//making some random blank spaces glitch | |
if ((glitch||random(1) > 0.995) && random(1) > 0.5 + 0.2*normalizedSlider) continue; | |
for (int x=0; x < width; x++) { | |
float noise = noise(xoff, yoff)*255; | |
float r = random(1); | |
if (r > 0.6 && dist(width/2, height/2, x, y) < width/2) { | |
if (noise > 50+200*normalizedSlider) | |
pixels[y*width+x] = color(0, noise, 0); //horizontal static | |
else | |
if (noise > 10) | |
pixels[y+height*x] = color(0, noise, 0); //vertical static | |
} | |
yoff += t; | |
} | |
xoff += t; | |
} | |
updatePixels(); | |
t++; | |
//static screen end | |
//Spiral Dragon author @Eddie_Le_Garden | |
////https://twitter.com/Eddie_Le_Garden/status/1235238788009324545 | |
x=slider.getSliderValue(); | |
y=slider.getSliderValue(); | |
angle=atan2(y-height, x-width); | |
stroke(0, 255, 0, 100+100*normalizedSlider); | |
for (r=20; r<dist(width, height, x, y); r+=.1+normalizedSlider/10) { | |
if (random(1) < 0.5 + 0.2*normalizedSlider) continue; | |
n=noise(r*.005, frameCount*.005)*50+angle; | |
point(width/2+cos(n*2)*r/2, height/2+sin(n*2)*r/2); | |
} | |
//end Spiral Dragon | |
//distance marker circles and heading | |
stroke(0, 255, 0, 100); | |
noFill(); | |
for (int i=1; i<=4; i++) | |
circle(width/2, height/2, i*width/4); | |
line(width/2, height/2, width/2, 0); | |
//scanning line | |
strokeWeight(4); | |
translate(width/2, height/2); | |
rotate(t*.1); | |
line(0, 0, width/2, 0); | |
rotate(-t*.1); | |
translate(-width/2, -height/2); | |
slider.trackSlider(); | |
text("Slider Value = " +String.format("%.1f", slider.getSliderValue()), 10, 18); //to get 1 decimal point | |
println(floor(slider.getSliderValue()*10)/10.0); //to get 1 decimal point | |
} | |
//https://www.reddit.com/r/processing/comments/fbwsbd/circle_draws_sin_waves_interesting_program_i_made/ | |
//author: u/liberal_destroyer3 -- https://www.reddit.com/user/liberal_destroyer3 | |
//helper functions on slider variable——————————————————————————————————————————————— | |
void mouseMoved() { | |
slider.checkHighlight(); | |
} | |
void mousePressed() { | |
slider.checkPressed(); | |
} | |
void mouseReleased() { | |
slider.held=false; | |
slider.checkHighlight(); | |
} | |
//end——————————————————————————————————————————————————————————————————————————————— | |
class Slider { | |
color Color=color(220); | |
color sliderColor=color(200); | |
color highlightColor=color(190); | |
color heldColor=color(170); | |
float r=9; | |
//————————————————————————————————————————————————————————————————— | |
PVector pos; | |
float len; | |
float startValue; | |
float endValue; | |
float sliderPos; | |
boolean highlight=false; | |
boolean held=false; | |
Slider(PVector pos, float len, float startValue, float endValue) { | |
this.pos = pos; | |
this.len = len; | |
this.startValue = startValue; | |
this.endValue = endValue; | |
sliderPos=(pos.x+len+pos.x)/2; | |
//println(sliderPos); | |
} | |
Slider(PVector pos, float len, float startValue, float endValue, float startPos) { | |
this.pos = pos; | |
this.len = len; | |
this.startValue = startValue; | |
this.endValue = endValue; | |
float x = map(startPos, startValue, endValue, pos.x, pos.x+len); | |
sliderPos=x; | |
} | |
float getSliderValue() { | |
float x = map(sliderPos, pos.x, pos.x+len, startValue, endValue); | |
return x; | |
} | |
void trackSlider() { | |
this.update(); | |
this.display(); | |
this.getSliderValue(); | |
} | |
void update() { | |
if(held) { | |
cursor(HAND); | |
sliderPos=mouseX; | |
sliderPos=constrain(sliderPos,pos.x,pos.x+len); | |
} else if(highlight) { | |
cursor(HAND); | |
} else { | |
cursor(ARROW); | |
} | |
} | |
void display() { | |
strokeWeight(1); | |
int b=5; | |
float rt; | |
fill(Color); | |
rect(pos.x-b, pos.y-b,len+b*2, b*2,6); | |
if(held) { | |
fill(heldColor); | |
rt=r+2; | |
} else if(highlight) { | |
fill(highlightColor); | |
rt=r+2; | |
} else { | |
fill(sliderColor); | |
rt=r; | |
} | |
//println(sliderPos); | |
circle(sliderPos, pos.y, rt*2); | |
} | |
boolean mouseOver() { | |
return dist(mouseX,mouseY,sliderPos,pos.y)<r; | |
} | |
void checkHighlight() { | |
if(mouseOver()) { | |
highlight=true; | |
} else { | |
highlight=false; | |
} | |
} | |
void checkPressed() { | |
if(mouseOver()) { | |
held=true; | |
} else { | |
held=false; | |
} | |
} | |
//end | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment