Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

23
LINES

< > BotCompany Repo | #1033723 // AnimatedLine

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (4964L/28K).

1  
sclass AnimatedLine > Animation {
2  
  int maxSpeed = 1;
3  
  int y, speed;
4  
  
5  
  void start {
6  
    y = random(h);
7  
    newSpeed();
8  
  }
9  
  
10  
  void newSpeed {
11  
    speed = random_incl(-maxSpeed, maxSpeed);
12  
  }
13  
  
14  
  void paint {
15  
    fillRect(g, 0, 0, w, h, Color.white);
16  
    drawLine(g, 0, y, w, y, Color.black);
17  
  }
18  
  
19  
  void nextFrame {
20  
    if (oneIn(20)) newSpeed();
21  
    y = clamp(y+speed, 0, h-1);
22  
  }
23  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, ekrmjmnbrukm, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1033723
Snippet name: AnimatedLine
Eternal ID of this version: #1033723/5
Text MD5: 4ad2d26c33786670fe7bdae072e91408
Transpilation MD5: 74adabaa7fa8d634bad8d6719db7ad10
Author: stefan
Category: javax / gazelle v
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-12-30 20:59:13
Source code size: 416 bytes / 23 lines
Pitched / IR pitched: No / No
Views / Downloads: 173 / 294
Version history: 4 change(s)
Referenced in: [show references]