English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 28 June 2011, 09:23   #1
Coagulus
Gets there in the end...

Coagulus's Avatar
 
Join Date: Sep 2005
Location: Wales
Posts: 630
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
Coagulus is offline  
Old 28 June 2011, 09:45   #2
StingRay
move.l #$c0ff33,throat

StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,214
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
StingRay is offline  
Old 28 June 2011, 09:58   #3
8bitbubsy
Registered User

8bitbubsy's Avatar
 
Join Date: Sep 2009
Location: Norway
Posts: 1,290
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
8bitbubsy is offline  
Old 28 June 2011, 10:00   #4
StingRay
move.l #$c0ff33,throat

StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,214
Quote:
Originally Posted by 8bitbubsy View Post
You also need a routine to fill the "fake sides" of the twister, so it looks like it is twisting and not just shrinking.
First question: what are "fake sides"?
Second question: What does a horizontal line drawer do?
StingRay is offline  
Old 28 June 2011, 10:04   #5
8bitbubsy
Registered User

8bitbubsy's Avatar
 
Join Date: Sep 2009
Location: Norway
Posts: 1,290
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.
8bitbubsy is offline  
Old 28 June 2011, 10:06   #6
StingRay
move.l #$c0ff33,throat

StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,214
Quote:
Originally Posted by 8bitbubsy View Post
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
He asked for a simple twister algorithm. That you can easily improve that very basic algorithm should be clear (draw textured lines, add light sources etc. pp.) but that is not exactly the topic here.

Edit since Mr. Bubsy edited his post:

Quote:
Originally Posted by 8bitbubsy View Post
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.
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.
StingRay is offline  
Old 28 June 2011, 10:18   #7
Coagulus
Gets there in the end...

Coagulus's Avatar
 
Join Date: Sep 2005
Location: Wales
Posts: 630
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
Coagulus is offline  
Old 28 June 2011, 12:02   #8
Dunny
Registered User

Dunny's Avatar
 
Join Date: Aug 2006
Location: Scunthorpe/United Kingdom
Posts: 1,178
Quote:
Originally Posted by Coagulus View Post
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!
Can you post a code snippet? I'm curious as to how you did this

D.
Dunny is offline  
Old 28 June 2011, 12:32   #9
pmc
gone
pmc's Avatar
 
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:
Originally Posted by Coagulus
It works, can't believe how simple it was. I've got to try and not find the complicated solutions!
Nice one Coagulus.

Now time for your Amiga assembler version!
pmc is offline  
Old 28 June 2011, 14:03   #10
Coagulus
Gets there in the end...

Coagulus's Avatar
 
Join Date: Sep 2005
Location: Wales
Posts: 630
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
Coagulus is offline  
Old 28 June 2011, 14:26   #11
pmc
gone
pmc's Avatar
 
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...?
pmc is offline  
Old 28 June 2011, 14:40   #12
StingRay
move.l #$c0ff33,throat

StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,214
Quote:
Originally Posted by Coagulus View Post
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!
Looks fine to me, have fun playing around with the code and improving twisty twister.
StingRay is offline  
Old 28 June 2011, 14:44   #13
Coagulus
Gets there in the end...

Coagulus's Avatar
 
Join Date: Sep 2005
Location: Wales
Posts: 630
Quote:
Originally Posted by StingRay View Post
Looks fine to me, have fun playing around with the code and improving twisty twister.
I shall, cheers!

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:
Originally Posted by pmc View Post
Any chance of a .exe of that so the non-Blitz guys like me can see it in action...?
ok

(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.
Coagulus is offline  
Old 28 June 2011, 14:54   #14
pmc
gone
pmc's Avatar
 
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
pmc is offline  
Old 28 June 2011, 15:02   #15
Dunny
Registered User

Dunny's Avatar
 
Join Date: Aug 2006
Location: Scunthorpe/United Kingdom
Posts: 1,178
Quote:
Originally Posted by Coagulus View Post
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!
Very nice! Equivalent in SpecBAS (note that I've modified your use of "amp" to make it twist as it draws):

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
Dunny is offline  
Old 28 June 2011, 15:14   #16
Coagulus
Gets there in the end...

Coagulus's Avatar
 
Join Date: Sep 2005
Location: Wales
Posts: 630
Quote:
Originally Posted by Dunny View Post
Very nice! Equivalent in SpecBAS (note that I've modified your use of "amp" to make it twist as it draws):
that's cool! I've tried it in my code too.

ps nice looking language, reminds me of my first coding on the speccy!
Coagulus is offline  
Old 28 June 2011, 15:22   #17
dobbar
 
Posts: n/a
Bring it up next time you're round, I'll be setting more challenges when
we're drunk !
 
Old 28 June 2011, 15:35   #18
Coagulus
Gets there in the end...

Coagulus's Avatar
 
Join Date: Sep 2005
Location: Wales
Posts: 630
Quote:
Originally Posted by dobbar View Post
Bring it up next time you're round, I'll be setting more challenges when
we're drunk !
ah, the reason (culprit) for all this appears!

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
Coagulus is offline  
Old 28 June 2011, 16:05   #19
dobbar
 
Posts: n/a
Challenge accepted ! (amount of time needed deliberatley not specified )
 
Old 28 June 2011, 16:10   #20
8bitbubsy
Registered User

8bitbubsy's Avatar
 
Join Date: Sep 2009
Location: Norway
Posts: 1,290
Quote:
Originally Posted by StingRay View Post
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.
Dear Mr. StingRay:
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.

8bitbubsy is offline  
 


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 06:13.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Page generated in 0.17480 seconds with 13 queries