Skip to content

Commit 49dbb5b

Browse files
authored
Create ramp-function.js
1 parent bdb54c2 commit 49dbb5b

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

sketches/ramp-function.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
function setup() {
2+
createCanvas(600, 600);
3+
frameRate(30);
4+
}
5+
function draw() {
6+
background(50);
7+
graph();
8+
unitStep(frameCount);
9+
fill(255);
10+
noStroke();
11+
textSize(28);
12+
textAlign(CENTER, CENTER);
13+
text("r(t)",width/2+30,0.1*height);
14+
text("t",0.9*width,0.5*height+30);
15+
}
16+
function graph(){
17+
stroke(255);
18+
strokeWeight(1.5); line(0.1*width,height/2,0.9*width,height/2); triangle(0.09*width,height/2,0.1*width,height/2 - 3,0.1*width,height/2 + 3);
19+
triangle(0.91*width,height/2,0.9*width,height/2 - 3,0.9*width,height/2 + 3);
20+
line(width/2,0.1*height,width/2,0.9*height);
21+
triangle(0.5*width,0.09*height,0.5*width- 3,0.1*height ,0.5*width+ 3,0.1*height );
22+
triangle(0.5*width,0.91*height,0.5*width- 3,0.9*height ,0.5*width+ 3,0.9*height );
23+
}
24+
function unitStep(t){
25+
stroke(255,0,0);
26+
if(t >0.1*width){
27+
if(t<=width/2 )
28+
{
29+
line(0.11*width,height/2,t,height/2);
30+
}
31+
if(t>=0.9*width)
32+
{
33+
line(0.1*width,height/2,width/2,height/2);
34+
line(width/2,height/2,0.9*width,0.1*height);
35+
}
36+
if(t>width/2 && t<=0.9*width)
37+
{
38+
line(0.1*width,height/2,width/2,height/2);
39+
line(width/2,height/2,t,-t+height);
40+
41+
}
42+
43+
}
44+
}

0 commit comments

Comments
 (0)