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).

sclass AnimatedLine > Animation {
  int maxSpeed = 1;
  int y, speed;
  
  void start {
    y = random(h);
    newSpeed();
  }
  
  void newSpeed {
    speed = random_incl(-maxSpeed, maxSpeed);
  }
  
  void paint {
    fillRect(g, 0, 0, w, h, Color.white);
    drawLine(g, 0, y, w, y, Color.black);
  }
  
  void nextFrame {
    if (oneIn(20)) newSpeed();
    y = clamp(y+speed, 0, h-1);
  }
}

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: 78 / 152
Version history: 4 change(s)
Referenced in: [show references]