Skip to content

Commit a5f5db9

Browse files
authored
Merge pull request #543 from zoyron/step
Added stepping feet to 09_Simulate
2 parents 2397d15 + 213ca4c commit a5f5db9

File tree

3 files changed

+240
-0
lines changed

3 files changed

+240
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* @name Stepping Feet Illusion
3+
* @description Stepping feet illusion is a very famous psychological experiment
4+
* Both the bricks will appear to move at different speed
5+
* even though they are moving at the same speed.
6+
* Click the mouse inside Canvas to confirm that
7+
* they are moving at the same speed.
8+
* Contributed by Sagar Arora.
9+
*/
10+
11+
// this class describes the structure
12+
// and movents of the brick
13+
class Brick{
14+
constructor(bc, y){
15+
this.brickColor = bc;
16+
this.yPos = y;
17+
this.xPos = 0;
18+
}
19+
20+
// this function creates the brick
21+
createBrick(){
22+
fill(this.brickColor);
23+
rect(this.xPos, this.yPos, 100, 50);
24+
}
25+
26+
// this function sets the speed
27+
// of movement of the brick to 1
28+
setSpeed(){
29+
this.xSpeed = 1;
30+
}
31+
32+
// this function set the bricks in motion
33+
moveBrick(){
34+
this.xPos+=this.xSpeed;
35+
if(this.xPos+100 >= width || this.xPos <= 0){
36+
this.xSpeed*=-1;
37+
}
38+
}
39+
}
40+
41+
function setup() {
42+
createCanvas(720, 400);
43+
createP("Keep the mouse clicked").style('color','#ffffff');
44+
createP("to check whether the bricks").style('color','#ffffff');
45+
createP("are moving at same speed or not").style('color','#ffffff');
46+
}
47+
48+
// creating two bricks of
49+
// colors white and black
50+
let brick1 = new Brick("white",100);
51+
let brick2 = new Brick("black",250);
52+
53+
//
54+
brick1.setSpeed();
55+
brick2.setSpeed();
56+
57+
function draw () {
58+
background(0);
59+
if(mouseIsPressed){
60+
background(50);
61+
}
62+
brick1.createBrick();
63+
brick1.moveBrick();
64+
if(!mouseIsPressed){
65+
createBars();
66+
}
67+
brick2.createBrick();
68+
brick2.moveBrick();
69+
}
70+
71+
// this function creates the black and
72+
// white bars across the screen
73+
function createBars() {
74+
let len = 12;
75+
for(let i = 0;i<width/len;i++){
76+
fill("white");
77+
if(i%2 == 0)
78+
rect(i*len,height,len,-height);
79+
}
80+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* @name Stepping Feet Illusion
3+
* @description Stepping feet illusion is a very famous psychological experiment
4+
* Both the bricks will appear to move at different speed
5+
* even though they are moving at the same speed.
6+
* Click the mouse inside Canvas to confirm that
7+
* they are moving at the same speed.
8+
* Contributed by Sagar Arora.
9+
*/
10+
11+
// this class describes the structure
12+
// and movents of the brick
13+
class Brick{
14+
constructor(bc, y){
15+
this.brickColor = bc;
16+
this.yPos = y;
17+
this.xPos = 0;
18+
}
19+
20+
// this function creates the brick
21+
createBrick(){
22+
fill(this.brickColor);
23+
rect(this.xPos, this.yPos, 100, 50);
24+
}
25+
26+
// this function sets the speed
27+
// of movement of the brick to 1
28+
setSpeed(){
29+
this.xSpeed = 1;
30+
}
31+
32+
// this function set the bricks in motion
33+
moveBrick(){
34+
this.xPos+=this.xSpeed;
35+
if(this.xPos+100 >= width || this.xPos <= 0){
36+
this.xSpeed*=-1;
37+
}
38+
}
39+
}
40+
41+
function setup() {
42+
createCanvas(720, 400);
43+
createP("Keep the mouse clicked").style('color','#ffffff');
44+
createP("to check whether the bricks").style('color','#ffffff');
45+
createP("are moving at same speed or not").style('color','#ffffff');
46+
}
47+
48+
// creating two bricks of
49+
// colors white and black
50+
let brick1 = new Brick("white",100);
51+
let brick2 = new Brick("black",250);
52+
53+
//
54+
brick1.setSpeed();
55+
brick2.setSpeed();
56+
57+
function draw () {
58+
background(0);
59+
if(mouseIsPressed){
60+
background(50);
61+
}
62+
brick1.createBrick();
63+
brick1.moveBrick();
64+
if(!mouseIsPressed){
65+
createBars();
66+
}
67+
brick2.createBrick();
68+
brick2.moveBrick();
69+
}
70+
71+
// this function creates the black and
72+
// white bars across the screen
73+
function createBars() {
74+
let len = 12;
75+
for(let i = 0;i<width/len;i++){
76+
fill("white");
77+
if(i%2 == 0)
78+
rect(i*len,height,len,-height);
79+
}
80+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* @name Stepping Feet Illusion
3+
* @description Stepping feet illusion is a very famous psychological experiment
4+
* Both the bricks will appear to move at different speed
5+
* even though they are moving at the same speed.
6+
* Click the mouse inside Canvas to confirm that
7+
* they are moving at the same speed.
8+
* Contributed by Sagar Arora.
9+
*/
10+
11+
// this class describes the structure
12+
// and movents of the brick
13+
class Brick{
14+
constructor(bc, y){
15+
this.brickColor = bc;
16+
this.yPos = y;
17+
this.xPos = 0;
18+
}
19+
20+
// this function creates the brick
21+
createBrick(){
22+
fill(this.brickColor);
23+
rect(this.xPos, this.yPos, 100, 50);
24+
}
25+
26+
// this function sets the speed
27+
// of movement of the brick to 1
28+
setSpeed(){
29+
this.xSpeed = 1;
30+
}
31+
32+
// this function set the bricks in motion
33+
moveBrick(){
34+
this.xPos+=this.xSpeed;
35+
if(this.xPos+100 >= width || this.xPos <= 0){
36+
this.xSpeed*=-1;
37+
}
38+
}
39+
}
40+
41+
function setup() {
42+
createCanvas(720, 400);
43+
createP("Keep the mouse clicked").style('color','#ffffff');
44+
createP("to check whether the bricks").style('color','#ffffff');
45+
createP("are moving at same speed or not").style('color','#ffffff');
46+
}
47+
48+
// creating two bricks of
49+
// colors white and black
50+
let brick1 = new Brick("white",100);
51+
let brick2 = new Brick("black",250);
52+
53+
//
54+
brick1.setSpeed();
55+
brick2.setSpeed();
56+
57+
function draw () {
58+
background(0);
59+
if(mouseIsPressed){
60+
background(50);
61+
}
62+
brick1.createBrick();
63+
brick1.moveBrick();
64+
if(!mouseIsPressed){
65+
createBars();
66+
}
67+
brick2.createBrick();
68+
brick2.moveBrick();
69+
}
70+
71+
// this function creates the black and
72+
// white bars across the screen
73+
function createBars() {
74+
let len = 12;
75+
for(let i = 0;i<width/len;i++){
76+
fill("white");
77+
if(i%2 == 0)
78+
rect(i*len,height,len,-height);
79+
}
80+
}

0 commit comments

Comments
 (0)