Francis89074 commited on
Commit
c67b039
·
verified ·
1 Parent(s): 14a3228

Create stim2.js

Browse files

Induce gamma brain waves

Files changed (1) hide show
  1. stim2.js +53 -0
stim2.js ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ let flickerRate = 40; // 40 Hz flicker rate
2
+ let angle = 0; // For rotation
3
+ let isBright = true; // Toggle between bright and dark states
4
+
5
+ function setup() {
6
+ createCanvas(windowWidth, windowHeight);
7
+ frameRate(flickerRate); // Set to 40 Hz
8
+ rectMode(CENTER); // Center shapes for rotation
9
+ background(0);
10
+ }
11
+
12
+ function draw() {
13
+ // Flicker between two states
14
+ if (isBright) {
15
+ background(255); // Bright background
16
+ } else {
17
+ background(0); // Dark background
18
+ }
19
+ isBright = !isBright; // Toggle
20
+
21
+ // Add rotating grid of shapes
22
+ let gridSize = 80; // Size of grid cells
23
+ translate(width / 2, height / 2); // Move to center
24
+ rotate(angle); // Apply rotation
25
+ angle += 0.02; // Slow rotation speed
26
+
27
+ for (let x = -width; x < width; x += gridSize) {
28
+ for (let y = -height; y < height; y += gridSize) {
29
+ // Alternate colors based on flicker state and position
30
+ if ((floor(x / gridSize) + floor(y / gridSize)) % 2 === 0) {
31
+ fill(isBright ? 0 : 255); // Inverse of background
32
+ } else {
33
+ fill(isBright ? 255 : 0);
34
+ }
35
+ noStroke();
36
+
37
+ // Draw rotating rectangles and circles
38
+ push();
39
+ translate(x, y);
40
+ rotate(angle * 0.5); // Additional rotation for each shape
41
+ rect(0, 0, gridSize * 0.6, gridSize * 0.6); // Square
42
+ pop();
43
+
44
+ // Overlay smaller flickering circles
45
+ fill(isBright ? 255 : 0); // Opposite color for contrast
46
+ ellipse(x, y, gridSize * 0.3); // Circle
47
+ }
48
+ }
49
+ }
50
+
51
+ function windowResized() {
52
+ resizeCanvas(windowWidth, windowHeight);
53
+ }