28 June 2011, 09:23 | #1 |
Gets there in the end...
Join Date: Sep 2005
Location: Wales
Posts: 862
|
twister effect
Hi all,
One of my favourite demo effects is a vertical twisting and rotating oblong. I'm trying to recreate this (admittedly firstly on the PC using Blitz Basic but then maybe on the amiga later as I've re set up that under WinUAE). I've created what looks like the oblong out of a stack of 1-pixel-high horizonal lines which seems to rotate nicely when solid but when I tried warping it with sine curves and it just looks warped and not twisted. Is there a pseudocode (or readable code) which does this anywhere that I can look at? I'm not great at these demo effects (I've only nailed starfields and sine scrollers so far!) but my mate challenged me to write a demo in Blitz for the PC and later the Amiga. I shouldn't agree to things when drunk! Rob |
28 June 2011, 09:45 | #2 |
move.l #$c0ff33,throat
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
|
A twister is a rather simple effect. Create 4 points:
x1 = sin(a) x2 = sin(a+90) x3 = sin(a+90*2) x4 = sin(a+90*3) Then you just connect these points, i.e. you draw a simple horizontal line from x1-x2;x2-x3;x3-x4;x4-x1. When you draw the lines, you have to check that xstart<xend, if that check fails you don't draw the line. That's basically all you need to do for a simple twister. Now it's your turn to code it. Last edited by StingRay; 28 June 2011 at 09:50. Reason: typo |
28 June 2011, 09:58 | #3 |
Registered User
Join Date: Sep 2009
Location: Norway
Posts: 1,710
|
You also need a routine to fill the "fake sides" of the twister, so it looks like it is twisting and not just shrinking.
Like this (for extra coolness, use the copperlist for gradient). http://cpcrulez.fr/im3/twist.png |
28 June 2011, 10:00 | #4 |
move.l #$c0ff33,throat
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
|
|
28 June 2011, 10:04 | #5 |
Registered User
Join Date: Sep 2009
Location: Norway
Posts: 1,710
|
1. By "sides" I mean the two different regions, e.g. red being side 1, and dark red being side 2. Lousy way of putting it, but I'm sure you catch my drift?
2. It ... draws a filled line. My mistake. But at least you should have some routines to make it look gradient and fake 3D-ish, that's how real men do it Now I assume I get an answer like "You have no idea how to code a twister", which of course is more than correct, but it doesn't mean I don't know how cool twisters should look like in my opinion. |
28 June 2011, 10:06 | #6 | |
move.l #$c0ff33,throat
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
|
Quote:
Edit since Mr. Bubsy edited his post: You assume a lot of things. Also, you might want to think what is more helpful here, your post which mentions "fake sides" and other "interesting" things or a simple and easy to understand explanation of the basic twister algorithm. Last edited by StingRay; 28 June 2011 at 10:50. |
|
28 June 2011, 10:18 | #7 |
Gets there in the end...
Join Date: Sep 2005
Location: Wales
Posts: 862
|
my god, I was overcomplicating things immensely! My code was over the top, caused a nice warp, but didn't twist! Thanks.
EDIT - It works, can't believe how simple it was. I've got to try and not find the complicated solutions! Last edited by Coagulus; 28 June 2011 at 10:37. Reason: tested |
28 June 2011, 12:02 | #8 | |
Registered User
Join Date: Aug 2006
Location: Scunthorpe/United Kingdom
Posts: 1,978
|
Quote:
D. |
|
28 June 2011, 12:32 | #9 | |
gone
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
|
I made an asm twister a while ago now - it's held in my unreleased effects stockpile.
It's a bit more like the one from Hardwired in style rather than the type (I think) you mean but, well... it's still a twister Quote:
Now time for your Amiga assembler version! |
|
28 June 2011, 14:03 | #10 |
Gets there in the end...
Join Date: Sep 2005
Location: Wales
Posts: 862
|
well, the test was done in blitzplus for pc. It's not optimized and very wasteful, but a great basis for me to work on!
Code:
; twister test Global a# Global x1# Global x2# Global x3# Global x4# Global ang#=0 Global amp#=9 Graphics 800,600 Repeat Cls twister() Flip Until KeyDown(1) End Function twister() For a=1 To 500 Step 2 x1=((Sin((a/amp)+ang))*100)+300 x2=((Sin((a/amp)+ang+90))*100)+300 x3=((Sin((a/amp)+ang+90*2))*100)+300 x4=((Sin((a/amp)+ang+90*3))*100)+300 Color 255,0,0 If x1<x2 Line x1,a,x2,a End If Color 128,0,0 If x2<x3 Line x2,a,x3,a End If Color 0,0,255 If x3<x4 Line x3,a,x4,a End If Color 0,0,128 If x4<x1 Line x4,a,x1,a End If Next ang=ang+1 If ang=360 Then ang=0 End Function |
28 June 2011, 14:26 | #11 |
gone
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
|
Any chance of a .exe of that so the non-Blitz guys like me can see it in action...?
|
28 June 2011, 14:40 | #12 |
move.l #$c0ff33,throat
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
|
|
28 June 2011, 14:44 | #13 | ||
Gets there in the end...
Join Date: Sep 2005
Location: Wales
Posts: 862
|
Quote:
As a test I tried to copy the code into Amiga Blitz Basic 2, odd thing is, I only changed the multipliers because of the resolution and now get an almost triangular one. I do suspect that a lot of optimizing will be needed for a miggy version in Blitz. It's been a while since I used blitz on the Amiga though, I had to dig out my old yellow Blitz Basic 2 manual! Code:
VWait 200 BLITZ Slice 0,44,320,256,$fff8,2,8,4,320,320 BitMap 0,320,256,2 BitMap 1,320,256,2 bm=0 a.f=0 x1.f=0 x2.f=0 x3.f=0 x4.f=0 ang.f=0 amp.f=100 While Joyb(0)=0 VWait Use BitMap bm Cls 0 For a.f=1 To 200 Step 2 x1.f=((Sin((a.f/amp.f)+ang.f))*50)+140 x2.f=((Sin((a.f/amp.f)+ang.f+90))*50)+140 x3.f=((Sin((a.f/amp.f)+ang.f+90*2))*50)+140 x4.f=((Sin((a.f/amp.f)+ang.f+90*3))*50)+140 If x1<x2 Line x1,a,x2,a,1 End If If x2<x3 Line x2,a,x3,a,2 End If If x3<x4 Line x3,a,x4,a,3 End If If x4<x1 Line x4,a,x1,a,1 End If Next ang=ang+0.1 If ang=360 Then ang=0 VWait Show bm bm=1-bm Wend End Quote:
(esc quits) http://coagulus.newport.net/t/twist.exe Last edited by TCD; 28 June 2011 at 15:02. Reason: Back to back merged. Use the edit function. |
||
28 June 2011, 14:54 | #14 |
gone
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
|
Thanks Coagulus - looks nice I'd say
I might have to knock up an Amiga asm version to complement the twister I already made before |
28 June 2011, 15:02 | #15 | |
Registered User
Join Date: Aug 2006
Location: Scunthorpe/United Kingdom
Posts: 1,978
|
Quote:
Code:
10 REM Twister demo effect 20 LET ang=0: LET xoff=(SCRw/2)-20: LET aa=1 30 SCREEN LOCK 40 LET amp=SIN(aa)*16 50 FOR y=0 TO SCRh-1 60 LET x1=((SIN((y/amp)+ang))*100)+xoff 70 LET x2=((SIN((y/amp)+ang+90))*100)+xoff 80 LET x3=((SIN((y/amp)+ang+180))*100)+xoff 90 LET x4=((SIN((y/amp)+ang+270))*100)+xoff 100 IF x1<x2 THEN MOVE TO x1,y: DRAW INK 4; TO x2,y 110 IF x2<x3 THEN MOVE TO x2,y: DRAW INK 12; TO x3,y 120 IF x3<x4 THEN MOVE TO x3,y: DRAW INK 6; TO x4,y 130 IF x4<x1 THEN MOVE TO x4,y: DRAW INK 14; TO x1,y 140 NEXT y 150 INC ang,1,0 TO 359 160 INC aa 170 WAIT SCREEN 180 CLS 190 GO TO 40 |
|
28 June 2011, 15:14 | #16 |
Gets there in the end...
Join Date: Sep 2005
Location: Wales
Posts: 862
|
|
28 June 2011, 15:22 | #17 |
Posts: n/a
|
Bring it up next time you're round, I'll be setting more challenges when
we're drunk ! |
28 June 2011, 15:35 | #18 | |
Gets there in the end...
Join Date: Sep 2005
Location: Wales
Posts: 862
|
Quote:
EDIT : and I challenge you to do the ASM version since your using it at the mo! Last edited by Coagulus; 28 June 2011 at 15:39. Reason: return challenge |
|
28 June 2011, 16:05 | #19 |
Posts: n/a
|
Challenge accepted ! (amount of time needed deliberatley not specified )
|
28 June 2011, 16:10 | #20 | |
Registered User
Join Date: Sep 2009
Location: Norway
Posts: 1,710
|
Quote:
I assume a lot of things indeed, but I frankly don't know what answer I can expect from you, it's mostly picking on my errors in a rather annoying way. As the thread is evolving and starting to be open for other ideas, my suggestions might as well be appopriate to this thread after all. And "fake sides" was not a very bad explaination, given there exists twisters with the feeling of 3D sides w/ fake light sources. Or should I say light sources? Real light sources, better? The reason I say "fake" is because it's pure cheating, coding wise. It's like calling a dragonball a ball, code wise (like I did in #flashtro some years ago ). This is what I mean, and with some more maths you can create the feeling of different sides on the twister, like walls. |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Help with a sine effect | bobster | Coders. Tutorials | 16 | 17 October 2012 12:11 |
2x Filter effect: How to? | Cherno | request.UAE Wishlist | 3 | 13 February 2012 06:26 |
Global Effect | mai | support.Games | 3 | 04 February 2010 12:58 |
Cracktro effect | absence | Coders. General | 13 | 02 April 2009 16:41 |
Chessboard effect | Six | Coders. General | 11 | 09 January 2007 15:45 |
|
|